diff options
author | dzwdz | 2021-08-22 13:40:22 +0200 |
---|---|---|
committer | dzwdz | 2021-08-22 13:40:22 +0200 |
commit | ac74cec51fa9c31e4c8cea2dd9f01b7b895d61b4 (patch) | |
tree | 9bd017bf5e1f17b621dfc034b230a45159fb7e30 /src/kernel/syscalls.c | |
parent | 6d8f2d0e93228a1aaecace14eb345fe1224b211f (diff) |
fs_open() stub
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r-- | src/kernel/syscalls.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 2b3dafc..13e0535 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -3,6 +3,7 @@ #include <kernel/panic.h> #include <kernel/proc.h> #include <kernel/syscalls.h> +#include <kernel/vfs/path.h> #include <stdint.h> _Noreturn static void await_finish(struct process *dead, struct process *listener) { @@ -64,6 +65,28 @@ int _syscall_fork() { return 1; } +fd_t _syscall_fs_open(const char *path, size_t len) { + struct virt_iter iter; + static char buffer[PATH_MAX]; // holds the simplified path + size_t pos = 0; + + if (len > PATH_MAX) return -1; + + // copy the path to buffer + virt_iter_new(&iter, (void*)path, len, process_current->pages, true, false); + while (virt_iter_next(&iter)) { + memcpy(buffer + pos, iter.frag, iter.frag_len); + pos += iter.frag_len; + } + if (iter.error) return -1; + + len = path_simplify(buffer, buffer, len); + if (len < 0) return -1; + + tty_write(buffer, len); + return -1; +} + int _syscall_debuglog(const char *msg, size_t len) { struct virt_iter iter; size_t written = 0; @@ -84,6 +107,8 @@ int syscall_handler(int num, int a, int b, int c) { return _syscall_await((void*)a, b); case _SYSCALL_FORK: return _syscall_fork(); + case _SYSCALL_FS_OPEN: + return _syscall_fs_open((void*)a, b); case _SYSCALL_DEBUGLOG: return _syscall_debuglog((void*)a, b); default: |