]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
vfs: unify virtual filesystems in registry and add /dev/vda to devfs
authorTulio A M Mendes <[email protected]>
Tue, 26 May 2026 01:54:53 +0000 (22:54 -0300)
committerTulio A M Mendes <[email protected]>
Wed, 3 Jun 2026 04:02:35 +0000 (01:02 -0300)
- Added tmpfs_mount/tmpfs_kill_sb to tmpfs.c with proper cleanup
- Added devfs_mount/devfs_kill_sb to devfs.c (static globals, no cleanup needed)
- Added procfs_mount/procfs_kill_sb to procfs.c (static globals, no cleanup needed)
- Registered tmpfs, devfs, and procfs in filesystem type registry in init.c
- Added /dev/vda block device node to devfs for consistency with virtio-blk
- Updated headers (tmpfs.h, devfs.h, procfs.h) with VFS mount interface declarations
- Added necessary includes (fs.h, blockdev.h) to virtual filesystem implementations

Test results:
- Smoke test: 119/119 PASS
- Zero regressions

include/devfs.h
include/procfs.h
include/tmpfs.h
src/kernel/devfs.c
src/kernel/init.c
src/kernel/procfs.c
src/kernel/tmpfs.c

index 7796ae86fdbcad0c993185c7c9e2c265ff57d586..9e91dc21e3bf35ead6b4c17a6cd3c63aaa7e49e7 100644 (file)
 #define DEVFS_H
 
 #include "fs.h"
+#include "blockdev.h"
 
 #define DEVFS_MAX_DEVICES 32
 
+struct block_device;
+
 fs_node_t* devfs_create_root(void);
 
+/* VFS mount interface */
+vfs_mount_result_t devfs_mount(struct block_device* bdev, uint32_t lba);
+void devfs_kill_sb(vfs_superblock_t* sb);
+
 /*
  * Register a device node with devfs.
  * The caller owns the fs_node_t storage (must remain valid for the
index 3dc6699e986ffd70117c7b29560fa16a4702f44e..d8d73afcf20d15f3f61faf97d8170435542a0ce3 100644 (file)
 #define PROCFS_H
 
 #include "fs.h"
+#include "blockdev.h"
+
+struct block_device;
 
 fs_node_t* procfs_create_root(void);
 
+/* VFS mount interface */
+vfs_mount_result_t procfs_mount(struct block_device* bdev, uint32_t lba);
+void procfs_kill_sb(vfs_superblock_t* sb);
+
 #endif
index ae14274c6b28d349bb031461d862ae31621a12d4..ffaea215f91432457d0c748d2ad59f1bf0be6d03 100644 (file)
 #define TMPFS_H
 
 #include "fs.h"
+#include "blockdev.h"
 #include <stdint.h>
 
+struct block_device;
+
 fs_node_t* tmpfs_create_root(void);
 int tmpfs_add_file(fs_node_t* root_dir, const char* name, const uint8_t* data, uint32_t len);
 
+/* VFS mount interface */
+vfs_mount_result_t tmpfs_mount(struct block_device* bdev, uint32_t lba);
+void tmpfs_kill_sb(vfs_superblock_t* sb);
+
 int tmpfs_mkdir_p(fs_node_t* root_dir, const char* path);
 fs_node_t* tmpfs_create_file(fs_node_t* root_dir, const char* path, const uint8_t* data, uint32_t len);
 int tmpfs_create_symlink(fs_node_t* root_dir, const char* link_path, const char* target);
index ce76c531857038c354fd58110143174dbddb4a80..f26f9cea99cfacf92792156e30ef9ec3b7063a90 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "devfs.h"
+#include "fs.h"
+#include "blockdev.h"
 
 #include "errno.h"
 #include "utils.h"
@@ -23,6 +25,7 @@ static fs_node_t g_dev_null;
 static fs_node_t g_dev_zero;
 static fs_node_t g_dev_random;
 static fs_node_t g_dev_urandom;
+static fs_node_t g_dev_vda;
 static uint32_t g_devfs_inited = 0;
 
 static struct fs_node* devfs_finddir_impl(struct fs_node* node, const char* name);
@@ -262,9 +265,31 @@ static void devfs_init_once(void) {
     g_dev_urandom.flags = FS_CHARDEVICE;
     g_dev_urandom.inode = 9;
     g_dev_urandom.f_ops = &dev_random_ops;
+
+    /* Initialize /dev/vda block device node (placeholder, will be registered by virtio-blk) */
+    memset(&g_dev_vda, 0, sizeof(g_dev_vda));
+    strcpy(g_dev_vda.name, "vda");
+    g_dev_vda.flags = FS_BLOCKDEVICE;
+    g_dev_vda.inode = 10;
+    /* f_ops will be set by virtio-blk driver when it registers */
+    devfs_register_device(&g_dev_vda);
 }
 
 fs_node_t* devfs_create_root(void) {
     devfs_init_once();
     return &g_dev_root.vfs;
 }
+
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t devfs_mount(block_device_t* bdev, uint32_t lba) {
+    (void)bdev;
+    (void)lba;
+    vfs_mount_result_t result = {NULL, NULL};
+    result.root = devfs_create_root();
+    return result;
+}
+
+void devfs_kill_sb(vfs_superblock_t* sb) {
+    (void)sb;
+    /* devfs uses static globals, no cleanup needed */
+}
index 57448bbf01a806115285d489642c65a1aac83834..b004ab8bf8fccc095abc53b2d8a39e6acab8eb76 100644 (file)
@@ -158,6 +158,31 @@ int init_start(const struct boot_info* bi) {
     };
     vfs_fs_type_register(&ext2_fs_type);
 
+    /* Register virtual filesystems (no block device needed) */
+    static vfs_fs_type_t tmpfs_fs_type = {
+        .name = "tmpfs",
+        .flags = 0,
+        .mount = tmpfs_mount,
+        .kill_sb = tmpfs_kill_sb
+    };
+    vfs_fs_type_register(&tmpfs_fs_type);
+
+    static vfs_fs_type_t devfs_fs_type = {
+        .name = "devfs",
+        .flags = 0,
+        .mount = devfs_mount,
+        .kill_sb = devfs_kill_sb
+    };
+    vfs_fs_type_register(&devfs_fs_type);
+
+    static vfs_fs_type_t procfs_fs_type = {
+        .name = "procfs",
+        .flags = 0,
+        .mount = procfs_mount,
+        .kill_sb = procfs_kill_sb
+    };
+    vfs_fs_type_register(&procfs_fs_type);
+
     /* Parse kernel command line (Linux-like triaging) */
     cmdline_parse(bi ? bi->cmdline : NULL);
 
index c46b894ca116637f323883526a1db1d034b9bb8a..c205084f37eaf952bdea787338a076c39b1352bb 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "procfs.h"
+#include "fs.h"
+#include "blockdev.h"
 
 #include "process.h"
 #include "spinlock.h"
@@ -16,7 +18,6 @@
 #include "pmm.h"
 #include "timer.h"
 #include "kernel/cmdline.h"
-#include "fs.h"
 
 #include <stddef.h>
 
@@ -581,3 +582,17 @@ fs_node_t* procfs_create_root(void) {
 
     return &g_proc_root;
 }
+
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t procfs_mount(block_device_t* bdev, uint32_t lba) {
+    (void)bdev;
+    (void)lba;
+    vfs_mount_result_t result = {NULL, NULL};
+    result.root = procfs_create_root();
+    return result;
+}
+
+void procfs_kill_sb(vfs_superblock_t* sb) {
+    (void)sb;
+    /* procfs uses static globals, no cleanup needed */
+}
index dda880d6fe69abeff234963379d9c0895e8298a3..ff1e96d88902d145ed8e8f3d37253b8f51bd6f9c 100644 (file)
@@ -8,6 +8,8 @@
  */
 
 #include "tmpfs.h"
+#include "fs.h"
+#include "blockdev.h"
 
 #include "errno.h"
 #include "heap.h"
@@ -298,6 +300,30 @@ fs_node_t* tmpfs_create_root(void) {
     return &root->vfs;
 }
 
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t tmpfs_mount(block_device_t* bdev, uint32_t lba) {
+    (void)bdev;
+    (void)lba;
+    vfs_mount_result_t result = {NULL, NULL};
+    result.root = tmpfs_create_root();
+    return result;
+}
+
+void tmpfs_kill_sb(vfs_superblock_t* sb) {
+    if (sb && sb->root) {
+        struct tmpfs_node* root = (struct tmpfs_node*)sb->root;
+        /* Free all children recursively */
+        struct tmpfs_node* child = root->first_child;
+        while (child) {
+            struct tmpfs_node* next = child->next_sibling;
+            if (child->data) kfree(child->data);
+            kfree(child);
+            child = next;
+        }
+        kfree(root);
+    }
+}
+
 int tmpfs_add_file(fs_node_t* root_dir, const char* name, const uint8_t* data, uint32_t len) {
     if (!root_dir || root_dir->flags != FS_DIRECTORY) return -ENOTDIR;
     if (!name || name[0] == 0) return -EINVAL;