From a26876079cb155b013461aa525276b9cc8598ccf Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 18 Sep 2021 12:23:08 +0200 Subject: implement NULL mounts --- src/kernel/syscalls.c | 16 ++++++++++++---- src/kernel/vfs/request.c | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 1bc9694..57774c2 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -104,12 +104,10 @@ fail: int _syscall_mount(handle_t handle, const char __user *path, int len) { struct vfs_mount *mount = NULL; - char *path_buf; + struct vfs_backend *backend = NULL; + char *path_buf = NULL; 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); @@ -121,6 +119,14 @@ int _syscall_mount(handle_t handle, const char __user *path, int len) { if (len < 0) goto fail; // TODO remove trailing slash + if (handle >= 0) { // mounting a real backend + if (handle >= HANDLE_MAX) + goto fail; + if (process_current->handles[handle].type != HANDLE_FS_FRONT) + goto fail; + backend = process_current->handles[handle].fs.backend; + } // otherwise backend == NULL + // append to mount list mount = kmalloc(sizeof *mount); mount->prev = process_current->mount; @@ -128,6 +134,8 @@ int _syscall_mount(handle_t handle, const char __user *path, int len) { mount->prefix_len = len; mount->backend = process_current->handles[handle].fs.backend; process_current->mount = mount; + return 0; + fail: kfree(path_buf); kfree(mount); diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 6159bbf..46c52b8 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -15,6 +15,9 @@ int vfs_request_create(struct vfs_request req_) { process_current->pending_req = req_; req = &process_current->pending_req; + if (!req->backend) + return vfs_request_finish(req, -1); + switch (req->backend->type) { case VFS_BACK_ROOT: ret = vfs_root_handler(req); -- cgit v1.2.3