From: Tulio A M Mendes Date: Mon, 25 May 2026 21:01:29 +0000 (-0300) Subject: vfs: add kill_sb callback to vfs_fs_type_t for filesystem cleanup (P2.3) X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=de8c3c6a02b4e4dd2986c26092cab52ab6d54c45;p=AdrOS.git vfs: add kill_sb callback to vfs_fs_type_t for filesystem cleanup (P2.3) - 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 --- diff --git a/include/fs.h b/include/fs.h index f299339c..c1ea44a1 100644 --- a/include/fs.h +++ b/include/fs.h @@ -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 */ diff --git a/src/kernel/fs.c b/src/kernel/fs.c index b16b9876..a803b4bd 100644 --- a/src/kernel/fs.c +++ b/src/kernel/fs.c @@ -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++) diff --git a/src/kernel/init.c b/src/kernel/init.c index e2953d25..47c29c47 100644 --- a/src/kernel/init.c +++ b/src/kernel/init.c @@ -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);