summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2021-09-18 12:23:08 +0200
committerdzwdz2021-09-18 12:23:08 +0200
commita26876079cb155b013461aa525276b9cc8598ccf (patch)
tree57ebfce84d0a390d106ae733335d8e11b7f9c8e4
parent27cf4b1923629cbf71609311d004914c2508c03a (diff)
implement NULL mounts
-rw-r--r--src/init/main.c11
-rw-r--r--src/kernel/syscalls.c16
-rw-r--r--src/kernel/vfs/request.c3
3 files changed, 25 insertions, 5 deletions
diff --git a/src/init/main.c b/src/init/main.c
index c81f789..233b92d 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -58,10 +58,19 @@ void fs_test(void) {
}
// parent: accesses the fs
- log("\n");
+ log("\n\n");
_syscall_mount(front, argify("/init"));
read_file(argify("/init/fake.txt"));
read_file(argify("/init/1.txt"));
read_file(argify("/init/2.txt"));
read_file(argify("/init/dir/3.txt"));
+
+ log("\nshadowing /init/dir...\n");
+ _syscall_mount(-1, argify("/init/dir"));
+ read_file(argify("/init/fake.txt"));
+ read_file(argify("/init/1.txt"));
+ read_file(argify("/init/2.txt"));
+ read_file(argify("/init/dir/3.txt"));
+
+ log("\n");
}
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);