]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
vfs: add kill_sb callback to vfs_fs_type_t for filesystem cleanup (P2.3)
authorTulio A M Mendes <[email protected]>
Mon, 25 May 2026 21:01:29 +0000 (18:01 -0300)
committerTulio A M Mendes <[email protected]>
Wed, 3 Jun 2026 04:02:35 +0000 (01:02 -0300)
- Add kill_sb function pointer to vfs_fs_type_t
- Update vfs_umount_nolock to call fstype->kill_sb instead of direct fat_umount/ext2_umount
- Implement fat_kill_sb and ext2_kill_sb callbacks in init.c
- Callbacks call filesystem-specific umount and free superblock

include/fs.h
src/kernel/fs.c
src/kernel/init.c

index f299339c9473c63ae8f819d53b119b4e66367a75..c1ea44a1b36dfb761cefbb82f5dc309447cebb7c 100644 (file)
@@ -55,6 +55,7 @@ typedef struct vfs_fs_type {
     const char* name;                     /* e.g. "fat", "ext2" */
     uint32_t flags;                       /* FS_NEEDS_BDEV, etc. */
     vfs_mount_result_t (*mount)(const block_device_t* bdev, uint32_t lba);  /* Mount function */
+    void (*kill_sb)(vfs_superblock_t* sb); /* Unmount/cleanup function */
 } vfs_fs_type_t;
 
 /* poll() event flags — shared between kernel VFS and syscall layer */
index b16b9876cf50c439adbf7029c2d0963e516b7187..a803b4bd9bbe0802450432d20501379b8f83da4c 100644 (file)
@@ -202,14 +202,9 @@ int vfs_umount_nolock(const char* mountpoint) {
         blockdev_release(g_mounts[idx].bdev);
     }
 
-    /* Call filesystem-specific umount to free mount structure */
-    if (g_mounts[idx].sb && g_mounts[idx].sb->private_data) {
-        if (strcmp(g_mounts[idx].fstype, "fat") == 0) {
-            fat_umount((struct fat_mount*)g_mounts[idx].sb->private_data);
-        } else if (strcmp(g_mounts[idx].fstype, "ext2") == 0) {
-            ext2_umount((struct ext2_mount*)g_mounts[idx].sb->private_data);
-        }
-        g_mounts[idx].sb->private_data = NULL;
+    /* Call filesystem-specific umount callback to free mount structure */
+    if (g_mounts[idx].sb && g_mounts[idx].sb->fstype && g_mounts[idx].sb->fstype->kill_sb) {
+        g_mounts[idx].sb->fstype->kill_sb(g_mounts[idx].sb);
     }
 
     for (int j = idx; j < g_mount_count - 1; j++)
index e2953d25eb85e81ff66fb49c52f4686dc99681bc..47c29c47daed7bcc606faebc796c3e902ec85857 100644 (file)
@@ -96,19 +96,35 @@ int init_mount_fs(const char* fstype, const block_device_t* bdev, uint32_t lba,
     return 0;
 }
 
+static void fat_kill_sb(vfs_superblock_t* sb) {
+    if (sb && sb->private_data) {
+        fat_umount((struct fat_mount*)sb->private_data);
+        kfree(sb);
+    }
+}
+
+static void ext2_kill_sb(vfs_superblock_t* sb) {
+    if (sb && sb->private_data) {
+        ext2_umount((struct ext2_mount*)sb->private_data);
+        kfree(sb);
+    }
+}
+
 int init_start(const struct boot_info* bi) {
     /* Register filesystem types */
     static vfs_fs_type_t fat_fs_type = {
         .name = "fat",
         .flags = FS_NEEDS_BDEV,
-        .mount = fat_mount
+        .mount = fat_mount,
+        .kill_sb = fat_kill_sb
     };
     vfs_fs_type_register(&fat_fs_type);
 
     static vfs_fs_type_t ext2_fs_type = {
         .name = "ext2",
         .flags = FS_NEEDS_BDEV,
-        .mount = ext2_mount
+        .mount = ext2_mount,
+        .kill_sb = ext2_kill_sb
     };
     vfs_fs_type_register(&ext2_fs_type);