From a66ce8238c08703bd1066a8094d6ab537e82b20e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 12 Sep 2021 13:26:29 +0200 Subject: implement most of fs_wait awaited_req is a garbage name but i couldn't come up with a better one. i also have no idea how to handle all the failure states --- src/kernel/vfs/request.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/kernel/vfs/request.c') diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index a275fd6..2ff5d72 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -29,12 +30,37 @@ _Noreturn void vfs_request_create(struct vfs_request req) { } _Noreturn void vfs_request_pass2handler(struct vfs_request *req) { - assert(req->backend->handler); - assert(req->backend->handler->state == PS_WAITS4REQUEST); + struct process *handler = req->backend->handler; + int len; + assert(handler); + assert(handler->state == PS_WAITS4REQUEST); + handler->state = PS_RUNNING; - req->backend->handler->state = PS_RUNNING; - // TODO pass the request to the process - process_switch(req->backend->handler); + if (!virt_cpy_from(handler->pages, + &len, handler->awaited_req.len, sizeof len)) + goto fail; // can't read buffer length + if (len > req->input.len) { + // input bigger than buffer + // TODO what should be done during e.g. open() calls? truncating doesn't seem right + len = req->input.len; + } + + if (req->input.kern) { + if (!virt_cpy_to(handler->pages, + handler->awaited_req.buf, req->input.buf_kern, len)) + goto fail; // can't copy buffer + } else { + panic(); // TODO + } + + if (!virt_cpy_to(handler->pages, + handler->awaited_req.len, &len, sizeof len)) + goto fail; // can't copy new length + + regs_savereturn(&handler->regs, req->type); + process_switch(handler); +fail: + panic(); // TODO } // returns from a VFS operation to the calling process -- cgit v1.2.3