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 */
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++)
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);