From 0da663e05c93f2791d7166ece8d69a1be06a7924 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 25 Aug 2021 14:49:58 +0200 Subject: implement open() for FD_SPECIAL_TTY (`/tty`) --- src/kernel/syscalls.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/kernel/syscalls.c') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 737484d..1c0a687 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -70,9 +70,17 @@ fd_t _syscall_fs_open(const user_ptr path, int len) { struct virt_iter iter; struct vfs_mount *mount = process_current->mount; static char buffer[PATH_MAX]; // holds the path + int fd, res; if (len > PATH_MAX) return -1; + // find the first free fd + for (fd = 0; fd < FD_MAX; fd++) { + if (process_current->fds[fd].type == FD_EMPTY) + break; + } + if (fd == FD_MAX) return -1; + // copy the path to the kernel virt_iter_new(&iter, path, len, process_current->pages, true, false); while (virt_iter_next(&iter)) @@ -90,14 +98,28 @@ fd_t _syscall_fs_open(const user_ptr path, int len) { break; } - tty_write(buffer, len); + tty_write(buffer + mount->prefix_len, len - mount->prefix_len); tty_const(" from mount "); if (mount) tty_write(mount->prefix, mount->prefix_len); else tty_const("[none]"); - return -1; + if (!mount) return -1; + + res = fdop_dispatch((struct fdop_args){ + .type = FDOP_OPEN, + .fd = &mount->fd, + .open = { + .target = &process_current->fds[fd], + .path = &buffer[mount->prefix_len], + .len = len - mount->prefix_len, + } + }); + if (res < 0) + return res; + else + return fd; } int _syscall_fd_mount(fd_t fd, const user_ptr path, int len) { -- cgit v1.2.3