diff options
author | dzwdz | 2021-11-14 18:13:36 +0100 |
---|---|---|
committer | dzwdz | 2021-11-14 18:13:36 +0100 |
commit | 25e7ee0a22e5e28dce8bd88aef61fc7894bfbe7b (patch) | |
tree | 8a61244f4fd72a85bd99493c9c882574f6f9f33b /src/kernel/vfs | |
parent | d2df6a9c064965b62c8b966bb93a81b663b35395 (diff) |
kernel/vfs: slightly tidy up the root driver
Diffstat (limited to 'src/kernel/vfs')
-rw-r--r-- | src/kernel/vfs/root.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index adf1bfe..f4bdcc2 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -1,6 +1,7 @@ #include <kernel/mem/virt.h> #include <kernel/panic.h> #include <kernel/proc.h> +#include <kernel/util.h> #include <kernel/vfs/root.h> #include <shared/mem.h> @@ -9,26 +10,25 @@ enum { HANDLE_TTY, }; +static bool exacteq(struct vfs_request *req, const char *str) { + int len = strlen(str); + assert(req->input.kern); + return req->input.len == len && !memcmp(req->input.buf_kern, str, len); +} + 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 HANDLE_TTY; - } + if (exacteq(req, "/")) return HANDLE_ROOT; + if (exacteq(req, "/tty")) return HANDLE_TTY; return -1; case VFSOP_READ: switch (req->id) { 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; + if (req->output.len < 0) return 0; // is this needed? TODO make that a size_t or something + int len = min((size_t) req->output.len, strlen(src) + 1); virt_cpy_to(req->caller->pages, req->output.buf, src, len); return len; } |