diff options
author | dzwdz | 2021-09-12 13:00:20 +0200 |
---|---|---|
committer | dzwdz | 2021-09-12 13:00:20 +0200 |
commit | 625ae265cbabe76bd272e9e8f0f637635af64b23 (patch) | |
tree | 6edecc8fa0053fc4fda0d079fbc1f3bdaac6fe7e /src/kernel | |
parent | e65d58357aaff7c1d05c06753538383478c1b0e9 (diff) |
vfs_request refactor pt2
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/syscalls.c | 14 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 4 | ||||
-rw-r--r-- | src/kernel/vfs/request.h | 27 | ||||
-rw-r--r-- | src/kernel/vfs/root.c | 9 |
4 files changed, 31 insertions, 23 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index fdf4b84..eb8da09 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -88,11 +88,11 @@ handle_t _syscall_open(const char __user *path, int len) { vfs_request_create((struct vfs_request) { .type = VFSOP_OPEN, - .open = { - .path = &path_buf[mount->prefix_len], - .path_len = len - mount->prefix_len, + .input = { + .kern = true, + .buf_kern = &path_buf[mount->prefix_len], // TODO this is unfreeable + .len = len - mount->prefix_len, }, - .caller = process_current, .backend = mount->backend, }); @@ -146,11 +146,11 @@ int _syscall_write(handle_t handle_num, const char __user *buf, int len) { if (handle->type != HANDLE_FILE) return -1; vfs_request_create((struct vfs_request) { .type = VFSOP_WRITE, - .rw = { + .input = { .buf = (userptr_t) buf, - .buf_len = len, - .id = handle->file.id, + .len = len, }, + .id = handle->file.id, .caller = process_current, .backend = handle->file.backend, }); diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 1212aa4..a275fd6 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -57,8 +57,8 @@ _Noreturn void vfs_request_finish(struct vfs_request *req, int ret) { ret = handle; } - if (req->type == VFSOP_OPEN) - kfree(req->open.path); + if (req->input.kern) kfree(req->input.buf_kern); + if (req->output.kern) kfree(req->output.buf_kern); req->caller->state = PS_RUNNING; regs_savereturn(&req->caller->regs, ret); diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h index 3021c6f..52af544 100644 --- a/src/kernel/vfs/request.h +++ b/src/kernel/vfs/request.h @@ -22,17 +22,24 @@ enum vfs_operation { // describes an in-process vfs call struct vfs_request { enum vfs_operation type; - union { - struct { - char *path; - int path_len; - } open; - struct { + struct { // TODO maybe this should be a separate type + bool kern; // if false: use .buf ; if true: use .buf_kern + union { char __user *buf; - int buf_len; - int id; // filled in by the kernel - } rw; - }; + char *buf_kern; + }; + int len; + } input; + struct { + bool kern; // if false: use .buf ; if true: use .buf_kern + union { + char __user *buf; + char *buf_kern; + }; + int len; + } output; + + int id; // handle.file.id struct process *caller; struct vfs_backend *backend; diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index 29caf14..feb718d 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -8,18 +8,19 @@ int vfs_root_handler(struct vfs_request *req) { switch (req->type) { case VFSOP_OPEN: - if (req->open.path_len == 4 - && !memcmp(req->open.path, "/tty", 4)) { + assert(req->input.kern); + if (req->input.len == 4 + && !memcmp(req->input.buf_kern, "/tty", 4)) { return 0; } return -1; case VFSOP_WRITE: - switch (req->rw.id) { + switch (req->id) { // every id corresponds to a special file type // this is a shit way to do this but :shrug: case 0: { // tty struct virt_iter iter; - virt_iter_new(&iter, req->rw.buf, req->rw.buf_len, + virt_iter_new(&iter, req->input.buf, req->input.len, req->caller->pages, true, false); while (virt_iter_next(&iter)) tty_write(iter.frag, iter.frag_len); |