From 8513ae3c3e83ec8835bc0d1355284a9ddd928693 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 2 May 2022 18:43:49 +0200 Subject: kernel/vfs: pass `close()` calls to fs handlers --- src/kernel/handle.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/kernel/handle.c') diff --git a/src/kernel/handle.c b/src/kernel/handle.c index d7f19b3..91832a0 100644 --- a/src/kernel/handle.c +++ b/src/kernel/handle.c @@ -2,6 +2,7 @@ #include #include #include +#include struct handle *handle_init(enum handle_type type) { struct handle *h = kmalloc(sizeof *h); @@ -13,15 +14,25 @@ struct handle *handle_init(enum handle_type type) { void handle_close(struct handle *h) { if (!h) return; assert(h->refcount > 0); - if (--(h->refcount) == 0) { - // TODO call close() in handler - // TODO count allocations and frees + if (--(h->refcount) > 0) return; - // TODO sanity check to check if refcount is true. handle_sanity? - - // TODO tests which would catch premature frees - // by that i mean duplicating a handle and killing the original process - h->type = HANDLE_INVALID; - kfree(h); + if (h->type == HANDLE_FILE) { + vfs_request_create((struct vfs_request) { + .type = VFSOP_CLOSE, + .id = h->file.id, + .caller = NULL, + .backend = h->file.backend, + }); } + + // TODO handle close(HANDLE_FS_FRONT) + + // TODO count allocations and frees + + // TODO sanity check to check if refcount is true. handle_sanity? + + // TODO tests which would catch premature frees + // by that i mean duplicating a handle and killing the original process + h->type = HANDLE_INVALID; + kfree(h); } -- cgit v1.2.3