diff options
-rw-r--r-- | src/kernel/syscalls.c | 18 | ||||
-rw-r--r-- | src/kernel/vfs/mount.c | 13 | ||||
-rw-r--r-- | src/kernel/vfs/mount.h | 3 |
3 files changed, 18 insertions, 16 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 1c0a687..19499d1 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -68,7 +68,7 @@ int _syscall_fork(void) { fd_t _syscall_fs_open(const user_ptr path, int len) { struct virt_iter iter; - struct vfs_mount *mount = process_current->mount; + struct vfs_mount *mount; static char buffer[PATH_MAX]; // holds the path int fd, res; @@ -90,21 +90,7 @@ fd_t _syscall_fs_open(const user_ptr path, int len) { len = path_simplify(buffer, buffer, len); if (len < 0) return -1; - // find mount - for (mount = process_current->mount; mount; mount = mount->prev) { - if (mount->prefix_len > len) - continue; - if (memcmp(mount->prefix, buffer, mount->prefix_len) == 0) - break; - } - - 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]"); - + mount = vfs_mount_resolve(process_current->mount, buffer, len); if (!mount) return -1; res = fdop_dispatch((struct fdop_args){ diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c index be33b6b..bf98957 100644 --- a/src/kernel/vfs/mount.c +++ b/src/kernel/vfs/mount.c @@ -1,4 +1,5 @@ #include <kernel/mem.h> +#include <kernel/util.h> #include <kernel/vfs/mount.h> struct vfs_mount *vfs_mount_seed(void) { @@ -13,3 +14,15 @@ struct vfs_mount *vfs_mount_seed(void) { }; return mount; } + +struct vfs_mount *vfs_mount_resolve( + struct vfs_mount *top, const char *path, size_t path_len) +{ + for (; top; top = top->prev) { + if (top->prefix_len > path_len) + continue; + if (memcmp(top->prefix, path, top->prefix_len) == 0) + break; + } + return top; +} diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h index 982f951..51990a1 100644 --- a/src/kernel/vfs/mount.h +++ b/src/kernel/vfs/mount.h @@ -10,3 +10,6 @@ struct vfs_mount { // prepares init's filesystem view struct vfs_mount *vfs_mount_seed(void); +struct vfs_mount *vfs_mount_resolve( + struct vfs_mount *top, const char *path, size_t path_len); + |