fix: memory leakage in file descriptor allocation
[lunaix-os.git] / lunaix-os / kernel / fs / fsm.c
index 95e12e3e003ec7ecbe2828df9d8bb6262e04bfff..bce983a1c2b51d3c3743cf9edcdca9e2ef43780d 100644 (file)
@@ -11,6 +11,7 @@
 #include <klibc/string.h>
 #include <lunaix/ds/hashtable.h>
 #include <lunaix/fs.h>
+#include <lunaix/mm/valloc.h>
 
 #define HASH_BUCKET_BITS 4
 #define HASH_BUCKET_NUM (1 << HASH_BUCKET_BITS)
@@ -21,12 +22,14 @@ void
 fsm_init()
 {
     hashtable_init(fs_registry);
+
+    fsm_register_all();
 }
 
 void
 fsm_register(struct filesystem* fs)
 {
-    hstr_rehash(&fs->fs_name, HASH_BUCKET_BITS);
+    hstr_rehash(&fs->fs_name, HSTR_FULL_HASH);
     hashtable_hash_in(fs_registry, &fs->fs_list, fs->fs_name.hash);
 }
 
@@ -35,7 +38,7 @@ fsm_get(const char* fs_name)
 {
     struct filesystem *pos, *next;
     struct hstr str = HSTR(fs_name, 0);
-    hstr_rehash(&str, HASH_BUCKET_BITS);
+    hstr_rehash(&str, HSTR_FULL_HASH);
 
     hashtable_hash_foreach(fs_registry, str.hash, pos, next, fs_list)
     {
@@ -45,4 +48,12 @@ fsm_get(const char* fs_name)
     }
 
     return NULL;
+}
+
+struct filesystem*
+fsm_new_fs(char* name, size_t name_len)
+{
+    struct filesystem* fs = vzalloc(sizeof(*fs));
+    fs->fs_name = HHSTR(name, name_len, 0);
+    return fs;
 }
\ No newline at end of file