summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2022-07-30 20:45:36 +0200
committerdzwdz2022-07-31 00:13:08 +0200
commit40674fa5469c7af09095d5dd5cca8eccc728561c (patch)
treeb1d49dedf9eb2718d34c13272e0f00e99aa31732
parentfdeac40f867ca0c43ade53cce4b77bb146b10aae (diff)
user: replace the MOUNT macro with MOUNT_AT
The old style could be confused with a regular function, where the driver would be executed unconditionally. This should make it more obvious that the driver doesn't get executed in the parent process.
-rw-r--r--src/user/app/init/init.c8
-rw-r--r--src/user/bootstrap/main.c10
-rw-r--r--src/user/lib/fs/misc.h23
3 files changed, 29 insertions, 12 deletions
diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c
index bb92cce..519329c 100644
--- a/src/user/app/init/init.c
+++ b/src/user/app/init/init.c
@@ -28,10 +28,10 @@ int main(void) {
freopen("/kdev/com1", "a+", stdout);
printf("in init (stage 2), main at 0x%x\n", &main);
- MOUNT("/tmp/", tmpfs_drv());
- MOUNT("/keyboard", ps2_drv());
- MOUNT("/vga_tty", ansiterm_drv());
- MOUNT("/bin/", fs_passthru("/init/bin"));
+ MOUNT_AT("/tmp/") { tmpfs_drv(); }
+ MOUNT_AT("/keyboard") { ps2_drv(); }
+ MOUNT_AT("/vga_tty") { ansiterm_drv(); }
+ MOUNT_AT("/bin/") { fs_passthru("/init/bin"); }
if (fork()) {
/* used to trigger a kernel bug
diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c
index e877b64..fc239cf 100644
--- a/src/user/bootstrap/main.c
+++ b/src/user/bootstrap/main.c
@@ -15,14 +15,16 @@ void _start(void) {
_syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT);
/* move everything provided by the kernel to /kdev */
- MOUNT("/kdev/", fs_passthru(NULL));
- if (!fork2_n_mount("/")) {
+ MOUNT_AT("/kdev/") { fs_passthru(NULL); }
+ MOUNT_AT("/") {
const char *l[] = {"/kdev/", NULL};
fs_whitelist(l);
}
- if (!fork2_n_mount("/")) fs_dir_inject("/kdev/"); // TODO should be part of fs_whitelist
+ MOUNT_AT("/") {
+ fs_dir_inject("/kdev/"); // TODO should be part of fs_whitelist
+ }
- MOUNT("/init/", tar_driver(&_initrd));
+ MOUNT_AT("/init/") { tar_driver(&_initrd); }
void *init = tar_find("bin/init", 8, &_initrd, ~0) + 512;
if (init) {
diff --git a/src/user/lib/fs/misc.h b/src/user/lib/fs/misc.h
index 0d9eb20..00f3c04 100644
--- a/src/user/lib/fs/misc.h
+++ b/src/user/lib/fs/misc.h
@@ -1,6 +1,8 @@
#pragma once
#include <stdbool.h>
#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
bool fork2_n_mount(const char *path);
@@ -9,8 +11,21 @@ void fs_whitelist(const char **list);
void fs_dir_inject(const char *path);
+static bool mount_at_pred(const char *path) {
+ // TODO preprocess path - simplify & ensure trailing slash
+ if (!fork2_n_mount(path)) {
+ /* child -> go into the for body */
+ _klogf("%s: impl", path);
+ return true;
+ }
+
+ if (strcmp("/", path) && !fork2_n_mount("/")) {
+ _klogf("%s: dir", path);
+ fs_dir_inject(path);
+ exit(1);
+ }
+ return false; /* continue after the for loop */
+}
+
/** Mounts something and injects its path into the fs */
-// TODO path needs to have a trailing slash
-#define MOUNT(path, impl) \
- if (!fork2_n_mount(path)) {_klogf("impl %s", path); impl;} \
- if (!fork2_n_mount("/")) {_klogf("dir for %s", path); fs_dir_inject(path);}
+#define MOUNT_AT(path) for (; mount_at_pred(path); exit(1))