diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/vfs/root.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index 8e2c8a2..834bed7 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -4,21 +4,35 @@ #include <kernel/util.h> #include <kernel/vfs/root.h> +enum { + HANDLE_ROOT, + HANDLE_TTY, +}; + int vfs_root_handler(struct vfs_request *req) { switch (req->type) { case VFSOP_OPEN: assert(req->input.kern); + if (req->input.len == 1 && *req->input.buf_kern == '/') + return HANDLE_ROOT; if (req->input.len == 4 && !memcmp(req->input.buf_kern, "/tty", 4)) { - return 0; + return HANDLE_TTY; } return -1; case VFSOP_READ: switch (req->id) { - // every id corresponds to a special file type - // this is a shit way to do this but :shrug: - case 0: { // tty + case HANDLE_ROOT: { + const char *src = "tty"; // TODO document directory read format + int srclen = 4; // TODO port strlen to the kernel + int len = req->output.len; + if (len < 0) return 0; // is this needed? + if (len > srclen) len = srclen; + virt_cpy_to(req->caller->pages, req->output.buf, src, len); + return len; + } + case HANDLE_TTY: { struct virt_iter iter; virt_iter_new(&iter, req->output.buf, req->output.len, req->caller->pages, true, false); @@ -31,7 +45,8 @@ int vfs_root_handler(struct vfs_request *req) { case VFSOP_WRITE: switch (req->id) { - case 0: { // tty + case HANDLE_ROOT: return -1; + case HANDLE_TTY: { struct virt_iter iter; virt_iter_new(&iter, req->input.buf, req->input.len, req->caller->pages, true, false); @@ -41,6 +56,7 @@ int vfs_root_handler(struct vfs_request *req) { } default: panic_invalid_state(); } + default: panic_invalid_state(); } } |