From 40674fa5469c7af09095d5dd5cca8eccc728561c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 30 Jul 2022 20:45:36 +0200 Subject: 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. --- src/user/lib/fs/misc.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/user/lib/fs') 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 #include +#include +#include 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)) -- cgit v1.2.3