summaryrefslogtreecommitdiff
path: root/src/kernel/handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/handle.c')
-rw-r--r--src/kernel/handle.c29
1 files changed, 20 insertions, 9 deletions
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 <kernel/mem/alloc.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+#include <kernel/vfs/request.h>
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);
}