From 710e9b2b5c16f74f66420c66d12455ad518d42c7 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 2 Oct 2022 19:25:17 +0200 Subject: syscall/open: add the full suite of READ/WRITE flags --- src/kernel/vfs/request.c | 11 ++++++++--- src/kernel/vfs/request.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/kernel/vfs') diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 24d5dac..0a377d3 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -23,8 +23,12 @@ void vfsreq_create(struct vfs_request req_) { memcpy(req, &req_, sizeof *req); if (req->backend) req->backend->refcount++; - if (req->type == VFSOP_OPEN && (req->flags & OPEN_RO)) - req->flags &= ~OPEN_CREATE; + if (req->type == VFSOP_OPEN && !(req->flags & OPEN_WRITE) && (req->flags & OPEN_CREATE)) { + vfsreq_finish_short(req, -EINVAL); + return; + } + + // TODO if i add a handle field to vfs_request, check ->readable ->writeable here if (req->backend && req->backend->potential_handlers) { struct vfs_request **iter = &req->backend->queue; @@ -47,7 +51,8 @@ void vfsreq_finish(struct vfs_request *req, char __user *stored, long ret, h = handle_init(HANDLE_FILE); h->backend = req->backend; req->backend->refcount++; h->file_id = stored; - h->ro = req->flags & OPEN_RO; + h->readable = OPEN_READABLE(req->flags); + h->writeable = OPEN_WRITEABLE(req->flags); } else { /* delegating - moving a handle to the caller */ assert(handler); diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h index 4e309b0..db707d0 100644 --- a/src/kernel/vfs/request.h +++ b/src/kernel/vfs/request.h @@ -42,6 +42,8 @@ struct vfs_request { size_t len; } output; + // TODO why doesn't this just have a reference to the handle? + void __user *id; // handle.file.id long offset; int flags; -- cgit v1.2.3