1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
void create_vfs(void) {
mkdir("/proc", 0755);
mkdir("/sys", 0755);
mkdir("/dev", 0755);
mkdir("/run", 0755);
}
void mount_vfs(void) {
if (mount("proc", "/proc", "proc",
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) {
perror("mount /proc");
}
if (mount("sys", "/sys", "sysfs",
MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) {
perror("mount /sys");
}
if (mount("dev", "/dev", "devtmpfs", MS_NOSUID | MS_RELATIME, "mode=755") !=
0) {
perror("mount /dev");
}
if (mount("run", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME,
"mode=755") != 0) {
perror("mount /run");
}
mkdir("/dev/pts", 0755);
mkdir("/dev/shm", 1777);
if (mount("devpts", "/dev/pts", "devpts",
MS_NOSUID | MS_NOEXEC | MS_RELATIME, "gid=5,mode=620") != 0) {
perror("mount /dev/pts");
}
if (mount("shm", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME,
"mode=1777") != 0) {
perror("mount /dev/shm");
}
}
int main(void) {
create_vfs();
mount_vfs();
return 0;
}
|