feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / kernel / fs / fsm.c
index 10e766ac229b098d87070cb64f7bd58f43473192..950583857b981857d2a5d2ce35e2f1c990f60b6a 100644 (file)
 #include <klibc/string.h>
 #include <lunaix/ds/hashtable.h>
 #include <lunaix/fs.h>
+#include <lunaix/mm/valloc.h>
+
+#include <lunaix/fs/twimap.h>
+#include <lunaix/fs/twifs.h>
 
 #define HASH_BUCKET_BITS 4
 #define HASH_BUCKET_NUM (1 << HASH_BUCKET_BITS)
 
+DEFINE_LLIST(fs_flatlist);
 DECLARE_HASHTABLE(fs_registry, HASH_BUCKET_NUM);
 
 void
 fsm_init()
 {
     hashtable_init(fs_registry);
+
+    ldga_invoke_fn0(fs);
 }
 
 void
@@ -28,6 +35,7 @@ fsm_register(struct filesystem* fs)
 {
     hstr_rehash(&fs->fs_name, HSTR_FULL_HASH);
     hashtable_hash_in(fs_registry, &fs->fs_list, fs->fs_name.hash);
+    llist_append(&fs_flatlist, &fs->fs_flat);
 }
 
 struct filesystem*
@@ -45,4 +53,33 @@ fsm_get(const char* fs_name)
     }
 
     return NULL;
-}
\ No newline at end of file
+}
+
+struct filesystem*
+fsm_new_fs(char* name, size_t name_len)
+{
+    struct filesystem* fs = vzalloc(sizeof(*fs));
+    if (name_len == (size_t)-1) {
+        name_len = strlen(name);
+    }
+    fs->fs_name = HHSTR(name, name_len, 0);
+    return fs;
+}
+
+static void
+read_fslist(struct twimap *mapping)
+{
+    struct filesystem *pos, *n;
+    llist_for_each(pos, n, &fs_flatlist, fs_flat)
+    {
+        twimap_printf(mapping, "%s %d\n", pos->fs_name.value, pos->types);
+    }
+}
+
+static void
+fstab_twifs_plugin()
+{
+    struct twimap* map = twifs_mapping(NULL, NULL, "fstab");
+    map->read = read_fslist;
+}
+EXPORT_TWIFS_PLUGIN(fstab, fstab_twifs_plugin);
\ No newline at end of file