summaryrefslogtreecommitdiff
path: root/4rc/4rc.c
diff options
context:
space:
mode:
Diffstat (limited to '4rc/4rc.c')
-rw-r--r--4rc/4rc.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/4rc/4rc.c b/4rc/4rc.c
new file mode 100644
index 0000000..68a5d9f
--- /dev/null
+++ b/4rc/4rc.c
@@ -0,0 +1,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;
+}