From 07ea385f961f4ad1ff7fd2f83c731b03c498fad9 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Sun, 12 Jul 2026 11:00:39 -0400 Subject: [PATCH] fs_init: change to_mount to block_device Signed-off-by: Michael Shaw --- fs/fat32/fat32.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fat32/inode.c | 2 ++ fs/fat32/inode.h | 7 +++++++ fs/vfs/initcpio.c | 1 + fs/vfs/inode.c | 7 +++++++ fs/vfs/ramfs.c | 2 +- fs/vfs/vfs.c | 1 + include/fs/vfs.h | 3 ++- 8 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 fs/fat32/fat32.c create mode 100644 fs/fat32/inode.c create mode 100644 fs/fat32/inode.h diff --git a/fs/fat32/fat32.c b/fs/fat32/fat32.c new file mode 100644 index 0000000..c86d235 --- /dev/null +++ b/fs/fat32/fat32.c @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#include + +#include + +#include + +#include "inode.h" + +static struct fs_driver fat32_driver = {0}; + +static int alloc_inode(fs_t *fs, u64 mode, inode_t **out) +{ + return -ENOSYS; +} + +static int free_inode(fs_t *fs, inode_t *inode) +{ + return -ENOSYS; +} + +static int open_inode(fs_t *fs, u64 id, dirent_t *dirent, inode_t **out) +{ + return -ENOSYS; +} + +static int fs_init(int flags, struct block_device *bdev, fs_t **out) +{ + fs_t *fs = kalloc(sizeof(fs_t), ALLOC_KERN); + if (!fs) + return -ENOMEM; + *out = fs; + + fs->fs_ops.alloc_inode = alloc_inode; + fs->fs_ops.free_inode = free_inode; + fs->fs_ops.open_inode = open_inode; + + return 0; +} + +static int fs_deinit(fs_t *fs) +{ + return -EINVAL; +} + +void fat32_init() +{ + strcpy(fat32_driver.name, "fat32"); + fat32_driver.init = fs_init; + fat32_driver.deinit = fs_deinit; +} +DRIVER_ENTRY(fat32_init); diff --git a/fs/fat32/inode.c b/fs/fat32/inode.c new file mode 100644 index 0000000..1a19d3a --- /dev/null +++ b/fs/fat32/inode.c @@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + diff --git a/fs/fat32/inode.h b/fs/fat32/inode.h new file mode 100644 index 0000000..9ebbeab --- /dev/null +++ b/fs/fat32/inode.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _INODE_H_ +#define _INODE_H_ + + + +#endif /* _INODE_H_ */ diff --git a/fs/vfs/initcpio.c b/fs/vfs/initcpio.c index 538f876..11409fd 100644 --- a/fs/vfs/initcpio.c +++ b/fs/vfs/initcpio.c @@ -104,6 +104,7 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t ** if (res == 0) { new_dent->fs = parent->fs; new_dent->parent = parent; + dirent_inc_ref(parent); *out = new_dent; } else { inode_dec_ref(existing_ino); diff --git a/fs/vfs/inode.c b/fs/vfs/inode.c index b9458f2..051bd75 100644 --- a/fs/vfs/inode.c +++ b/fs/vfs/inode.c @@ -37,6 +37,7 @@ int dirent_populate_children(dirent_t *dir) goto cleanup; insert->parent = dir; + dirent_inc_ref(dir); if (!list_insert(&inode->dirents, insert)) { dirent_free(insert); @@ -211,6 +212,9 @@ dirent_t *dirent_dup(dirent_t *src) ret->fs = src->fs; ret->parent = src->parent; + if (ret->parent) + dirent_inc_ref(ret->parent); + if (src->inode) { inode_inc_ref(src->inode); ret->inode = src->inode; @@ -221,6 +225,9 @@ dirent_t *dirent_dup(dirent_t *src) void dirent_free(dirent_t *dirent) { + if (dirent->parent) + dirent_dec_ref(dirent->parent); + kfree(dirent->name); slab_free(dirent_slab, dirent); } diff --git a/fs/vfs/ramfs.c b/fs/vfs/ramfs.c index b96ebf3..b7276c9 100644 --- a/fs/vfs/ramfs.c +++ b/fs/vfs/ramfs.c @@ -210,7 +210,7 @@ static ssize_t get_dents(inode_t *parent, dirent_t **dents) return n; } -static int init(int flags, dirent_t *to_mount, fs_t **out) +static int init(int flags, struct block_device *to_mount, fs_t **out) { return ramfs_create(flags, out); } diff --git a/fs/vfs/vfs.c b/fs/vfs/vfs.c index d01a853..e58c024 100644 --- a/fs/vfs/vfs.c +++ b/fs/vfs/vfs.c @@ -274,6 +274,7 @@ int vfs_creat(dirent_t *parent, const char *name, u64 mode, int flags, dirent_t new_dirent->fs = fs; new_dirent->parent = parent; + dirent_inc_ref(parent); *out = new_dirent; write_unlock(&ino->rwlock); return 0; diff --git a/include/fs/vfs.h b/include/fs/vfs.h index 60e9b24..3dd06ae 100644 --- a/include/fs/vfs.h +++ b/include/fs/vfs.h @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -55,7 +56,7 @@ struct fs_driver { char name[FILE_NAME_MAX_LEN + 1]; - int (*init)(int flags, dirent_t *to_mount, fs_t **out); + int (*init)(int flags, struct block_device *to_mount, fs_t **out); int (*deinit)(fs_t *fs); };