summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
authordzwdz2021-08-25 14:49:58 +0200
committerdzwdz2021-08-25 14:49:58 +0200
commit0da663e05c93f2791d7166ece8d69a1be06a7924 (patch)
tree05dd2c16b04a3fd2e6ecf491da217b2686d8ec35 /src/kernel/syscalls.c
parentab5150478dd14c1c5b28ca50b36b35e8224df54b (diff)
implement open() for FD_SPECIAL_TTY (`/tty`)
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c26
1 files changed, 24 insertions, 2 deletions
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) {