diff options
-rw-r--r-- | src/init/main.c | 44 | ||||
-rw-r--r-- | src/init/stdlib.c | 2 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 10 |
3 files changed, 30 insertions, 26 deletions
diff --git a/src/init/main.c b/src/init/main.c index a46cb18..661ee64 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -16,43 +16,43 @@ extern char _bss_end; extern char _initrd; void read_file(const char *path, size_t len); -void fs_prep(void); __attribute__((section(".text.startup"))) int main(void) { // allocate bss _syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT); - // TODO if (!fork2_n_mount("/tty")) ansiterm_drv(); - - __tty_fd = _syscall_open(argify("/com1")); - if (__tty_fd < 0) - _syscall_exit(1); + MOUNT("/init", tar_driver(&_initrd)); MOUNT("/keyboard", ps2_drv()); + MOUNT("/vga_tty", ansiterm_drv()); - fs_prep(); - shell_loop(); + MOUNT("/bind", fs_passthru(NULL)); - _syscall_exit(0); -} + if (!_syscall_fork()) { + __tty_fd = _syscall_open(argify("/com1")); + if (__tty_fd < 0) _syscall_exit(1); -void fs_prep(void) { - handle_t front = _syscall_fs_fork2(); - if (!front) { - tar_driver(&_initrd); + shell_loop(); _syscall_exit(1); } - /* the trailing slash should be ignored by mount() - * TODO actually write tests */ - _syscall_mount(front, argify("/init/")); + if (!_syscall_fork()) { + __tty_fd = _syscall_open(argify("/vga_tty")); + if (__tty_fd < 0) _syscall_exit(1); - if (!fork2_n_mount("/")) fs_dir_inject("/init/"); + shell_loop(); + _syscall_exit(1); + } - /* from here on i'll just use the helper MOUNT macro */ + // try to find any working output + __tty_fd = _syscall_open(argify("/com1")); + if (__tty_fd < 0) __tty_fd = _syscall_open(argify("/vga_tty")); - /* passthrough fs */ - MOUNT("/2nd/", fs_passthru(NULL)); /* copies / under /2nd */ - MOUNT("/3rd/", fs_passthru("/init/")); /* copies /init under /3rd */ + for (;;) { + _syscall_await(); + printf("init: something quit\n"); + } + + _syscall_exit(0); } diff --git a/src/init/stdlib.c b/src/init/stdlib.c index e8b3f97..839b8f5 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -10,6 +10,8 @@ int printf(const char *fmt, ...) { int total = 0; va_list argp; va_start(argp, fmt); + if (__tty_fd < 0) return 0; + for (;;) { char c = *fmt++; switch (c) { diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 0214ca7..761b619 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -25,15 +25,17 @@ int vfs_request_create(struct vfs_request req_) { ret = vfs_request_finish(req, ret); return ret; case VFS_BACK_USER: - if (req->backend->handler == NULL) { + if (req->backend->handler + && req->backend->handler->state == PS_WAITS4REQUEST) + { + vfs_request_pass2handler(req); + } else { // backend isn't ready yet, join the queue struct process **iter = &req->backend->queue; while (*iter != NULL) iter = &(*iter)->waits4fs.queue_next; *iter = process_current; process_switch_any(); - } else { - vfs_request_pass2handler(req); } default: panic_invalid_state(); @@ -45,7 +47,7 @@ _Noreturn void vfs_request_pass2handler(struct vfs_request *req) { struct fs_wait_response res = {0}; int len; assert(handler); - assert(handler->state == PS_WAITS4REQUEST); + assert(handler->state == PS_WAITS4REQUEST); // TODO currently callers have to ensure that the handler is in the correct state. should they? assert(!handler->handled_req); handler->state = PS_RUNNING; handler->handled_req = req; |