diff options
-rw-r--r-- | src/init/driver/ansiterm.c | 2 | ||||
-rw-r--r-- | src/init/driver/ps2.c | 2 | ||||
-rw-r--r-- | src/init/fs/misc.c | 28 | ||||
-rw-r--r-- | src/init/fs/misc.h | 1 | ||||
-rw-r--r-- | src/init/main.c | 14 |
5 files changed, 42 insertions, 5 deletions
diff --git a/src/init/driver/ansiterm.c b/src/init/driver/ansiterm.c index 60aad72..2d8ef1f 100644 --- a/src/init/driver/ansiterm.c +++ b/src/init/driver/ansiterm.c @@ -56,7 +56,7 @@ static void in_char(char c) { } void ansiterm_drv(void) { - vga_fd = _syscall_open("/vga", 4, 0); + vga_fd = _syscall_open("/kdev/vga", 9, 0); _syscall_read(vga_fd, vga, sizeof vga, 0); // find first empty line diff --git a/src/init/driver/ps2.c b/src/init/driver/ps2.c index 0c6d548..a05ae61 100644 --- a/src/init/driver/ps2.c +++ b/src/init/driver/ps2.c @@ -78,7 +78,7 @@ static void main_loop(void) { } void ps2_drv(void) { - fd = _syscall_open("/ps2", 4, 0); + fd = _syscall_open("/kdev/ps2", 9, 0); if (fd < 0) _syscall_exit(1); main_loop(); diff --git a/src/init/fs/misc.c b/src/init/fs/misc.c index 257ed32..f406ee2 100644 --- a/src/init/fs/misc.c +++ b/src/init/fs/misc.c @@ -122,6 +122,34 @@ void fs_passthru(const char *prefix) { _syscall_exit(0); } +void fs_whitelist(const char **list) { + struct fs_wait_response res; + static char buf[1024]; + bool allow; + + while (!_syscall_fs_wait(buf, sizeof(buf), &res)) { + switch (res.op) { + case VFSOP_OPEN: + allow = false; + // TODO reverse dir_inject + for (const char **iter = list; *iter; iter++) { + size_t len = strlen(*iter); // inefficient, whatever + if (len <= res.len && !memcmp(buf, *iter, len)) { + allow = true; + break; + } + } + _syscall_fs_respond(NULL, allow ? _syscall_open(buf, res.len, res.flags) : -1); + break; + + default: + fs_respond_delegate(&res, res.id, buf); + break; + } + } + _syscall_exit(0); +} + void fs_dir_inject(const char *path) { struct fs_dir_handle { diff --git a/src/init/fs/misc.h b/src/init/fs/misc.h index 879be32..d64ab1e 100644 --- a/src/init/fs/misc.h +++ b/src/init/fs/misc.h @@ -5,6 +5,7 @@ bool fork2_n_mount(const char *path); void fs_passthru(const char *prefix); +void fs_whitelist(const char **list); void fs_dir_inject(const char *path); diff --git a/src/init/main.c b/src/init/main.c index 9afb2a7..705da8f 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -22,6 +22,14 @@ int main(void) { file_open(&__stdout, "/com1", 0); printf("preinit\n"); + /* move everything provided by the kernel to /kdev */ + MOUNT("/kdev/", fs_passthru(NULL)); + if (!fork2_n_mount("/")) { + const char *l[] = {"/kdev/", NULL}; + fs_whitelist(l); + } + if (!fork2_n_mount("/")) fs_dir_inject("/kdev/"); // TODO should be part of fs_whitelist + MOUNT("/init/", tar_driver(&_initrd)); MOUNT("/tmp/", tmpfs_drv()); MOUNT("/keyboard", ps2_drv()); @@ -49,7 +57,7 @@ int main(void) { } if (!_syscall_fork(0, NULL)) { - if (file_open(&__stdout, "/com1", 0) < 0 || file_open(&__stdin, "/com1", 0) < 0) + if (file_open(&__stdout, "/kdev/com1", 0) < 0 || file_open(&__stdin, "/kdev/com1", 0) < 0) _syscall_exit(1); shell_loop(); @@ -72,8 +80,8 @@ int main(void) { // try to find any working output - if (file_open(&__stdout, "/com1", 0) < 0) - file_open(&__stdout, "/vga_tty", 0); + if (file_open(&__stdout, "/kdev/com1", 0) < 0) + file_open(&__stdout, "/kdev/vga_tty", 0); _syscall_await(); printf("init: quitting\n"); |