From 2f48f3c88c11c802a1dfc9d803b1d9715cb95b33 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 7 Sep 2021 19:37:38 +0200 Subject: reimplement _syscall_mount --- src/init/main.c | 4 +++- src/kernel/syscalls.c | 10 ++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/init/main.c b/src/init/main.c index deacb15..41f51d3 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -28,8 +28,10 @@ int main(void) { } void fs_test(void) { - handle_t front, back; + handle_t front, back, file; front = _syscall_fs_create((void*)&back); // TODO change user_ptr to void* + _syscall_mount(front, argify("/mnt")); + file = _syscall_open(argify("/mnt/test")); } void misc_tests(void) { diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 5d792ce..d2217eb 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -104,10 +104,11 @@ handle_t _syscall_open(const user_ptr path, int len) { int _syscall_mount(handle_t handle, const user_ptr path, int len) { struct vfs_mount *mount = NULL; char *path_buf; - int res; if (len > PATH_MAX) return -1; if (handle < 0 || handle >= HANDLE_MAX) return -1; + if (process_current->handles[handle].type != HANDLE_FS_FRONT) + return -1; // copy the path to the kernel path_buf = kmalloc(len); @@ -125,11 +126,8 @@ int _syscall_mount(handle_t handle, const user_ptr path, int len) { mount->prev = process_current->mount; mount->prefix = path_buf; mount->prefix_len = len; - - res = -1; // TODO pass to filesystem - if (res < 0) goto fail; + mount->backend = process_current->handles[handle].fs.backend; process_current->mount = mount; - return 0; fail: kfree(path_buf); kfree(mount); @@ -179,7 +177,7 @@ handle_t _syscall_fs_create(user_ptr back_user) { NULL, (uintptr_t)&back, sizeof(handle_t))) goto fail; - backend = kmalloc(sizeof(struct vfs_backend)); + backend = kmalloc(sizeof(struct vfs_backend)); // TODO never freed backend->type = VFS_BACK_USER; process_current->handles[front].fs.backend = backend; process_current->handles[back ].fs.backend = backend; -- cgit v1.2.3