build initrd
[cascardo/b2hw.git] / init.c
1 /*
2  * Copyright (C) 2016  Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, visit the http://fsf.org website.
16  */
17
18 #include "init.h"
19 #include <sys/mount.h>
20 #include <sys/stat.h>
21 #include <stdlib.h>
22
23 int devmount_setup(void)
24 {
25         int r;
26         mkdir("/dev", 0755);
27         r = mount(NULL, "/dev", "devtmpfs", MS_NOEXEC | MS_NOSUID | MS_NOATIME, NULL);
28         if (r < 0)
29                 r = mount(NULL, "/dev", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NOATIME, NULL);
30         return r;
31 }
32
33 int devpts_setup(void)
34 {
35         mkdir("/dev/pts", 0755);
36         return mount(NULL, "/dev/pts", "devpts", MS_NOEXEC | MS_NOSUID | MS_NOATIME, NULL);
37 }
38
39 int sysfsmount_setup(void)
40 {
41         mkdir("/sys", 0755);
42         return mount(NULL, "/sys", "sysfs", MS_NOEXEC | MS_NOSUID | MS_NOATIME, NULL);
43 }