Manage int IDs via id_alloc
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m31s

This commit is contained in:
2026-02-22 20:40:12 +01:00
parent 8fc5418915
commit 084809ac99
13 changed files with 203 additions and 70 deletions

View File

@@ -1,6 +1,7 @@
#include <device/device.h>
#include <fs/tarfs.h>
#include <fs/vfs.h>
#include <id/id_alloc.h>
#include <libk/fieldsizeof.h>
#include <libk/hash.h>
#include <libk/lengthof.h>
@@ -97,7 +98,7 @@ int vfs_open (struct procgroup* procgroup, const char* mountpoint, const char* p
spin_lock (&procgroup->lock);
int id = handle->id = procgroup->sys_vfs_handles++;
int id = handle->id = id_alloc (&procgroup->vfs_handle_id_alloc);
rbtree_insert (struct vfs_handle, &procgroup->vfs_handle_tree, &handle->handle_tree_link,
handle_tree_link, id);
@@ -119,8 +120,13 @@ int vfs_close (struct procgroup* procgroup, int id) {
return -ST_NOT_FOUND;
}
spin_lock (&handle->lock);
rbtree_delete (&procgroup->vfs_handle_tree, &handle->handle_tree_link);
id_free (&procgroup->vfs_handle_id_alloc, handle->id);
spin_unlock (&handle->lock);
spin_unlock (&procgroup->lock);
free (handle);
@@ -191,7 +197,6 @@ int vfs_kernel_describe (const char* mountpoint, const char* path, struct desc*
}
void vfs_procgroup_cleanup (struct procgroup* procgroup) {
struct list_node_link* handle_cleanup_list = NULL;
struct vfs_handle* handle;
struct rb_node_link* node;
@@ -202,14 +207,8 @@ void vfs_procgroup_cleanup (struct procgroup* procgroup) {
rbtree_next (node, next);
handle = rbtree_entry (node, struct vfs_handle, handle_tree_link);
node = next;
list_append (handle_cleanup_list, &handle->handle_cleanup_link);
}
struct list_node_link *cleanup_link, *cleanup_tmp_link;
list_foreach (handle_cleanup_list, cleanup_link, cleanup_tmp_link) {
handle = list_entry (cleanup_link, struct vfs_handle, handle_cleanup_link);
list_remove (handle_cleanup_list, &handle->handle_cleanup_link);
free (handle);
vfs_close (procgroup, handle->id);
}
}