diff --git a/fs.c b/fs.c index 0dc4aa1..a442005 100644 --- a/fs.c +++ b/fs.c @@ -1,11 +1,28 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include "simplefs.h" +#if SIMPLEFS_AT_LEAST(6, 18, 0) +#include +#endif #include #include #include -#include "simplefs.h" +#if SIMPLEFS_AT_LEAST(6, 18, 0) +static int simplefs_get_tree(struct fs_context *fc) +{ + return get_tree_bdev(fc, simplefs_fill_super); +} +static const struct fs_context_operations simplefs_context_ops = { + .get_tree = simplefs_get_tree, +}; +static int init_simplefs_context(struct fs_context *fc) +{ + fc->ops = &simplefs_context_ops; + return 0; +} +#else /* Mount a simplefs partition */ struct dentry *simplefs_mount(struct file_system_type *fs_type, int flags, @@ -21,7 +38,7 @@ struct dentry *simplefs_mount(struct file_system_type *fs_type, return dentry; } - +#endif /* Unmount a simplefs partition */ void simplefs_kill_sb(struct super_block *sb) { @@ -41,7 +58,11 @@ void simplefs_kill_sb(struct super_block *sb) static struct file_system_type simplefs_file_system_type = { .owner = THIS_MODULE, .name = "simplefs", +#if SIMPLEFS_AT_LEAST(6, 18, 0) + .init_fs_context = init_simplefs_context, +#else .mount = simplefs_mount, +#endif .kill_sb = simplefs_kill_sb, .fs_flags = FS_REQUIRES_DEV, .next = NULL, diff --git a/inode.c b/inode.c index 3f8dad2..62dcdcc 100644 --- a/inode.c +++ b/inode.c @@ -41,7 +41,15 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino) return ERR_PTR(-ENOMEM); /* If inode is in cache, return it */ +#if SIMPLEFS_AT_LEAST(6, 19, 0) + if (!(inode_state_read_once(inode) & I_NEW)) +/* inode->i_state is struct inode_state_flags in kernels v6.19 +, + * and inode_state_read_once returns __state from the state flag + * structure which is enum + */ +#else if (!(inode->i_state & I_NEW)) +#endif return inode; ci = SIMPLEFS_INODE(inode); @@ -663,7 +671,7 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry) if (S_ISLNK(inode->i_mode)) goto clean_inode; - /* Update inode stats */ + /* Update inode stats */ #if SIMPLEFS_AT_LEAST(6, 7, 0) simple_inode_init_ts(dir); #elif SIMPLEFS_AT_LEAST(6, 6, 0) @@ -907,7 +915,7 @@ static int simplefs_rename(struct inode *old_dir, if (ret != 0) goto release_new; - /* Update old parent inode metadata */ + /* Update old parent inode metadata */ #if SIMPLEFS_AT_LEAST(6, 7, 0) simple_inode_init_ts(old_dir); #elif SIMPLEFS_AT_LEAST(6, 6, 0) diff --git a/mkfs.c b/mkfs.c index b50a009..8ae753d 100644 --- a/mkfs.c +++ b/mkfs.c @@ -61,7 +61,7 @@ static struct superblock *write_superblock(int fd, struct stat *fstats) nr_blocks - nr_istore_blocks - nr_ifree_blocks - nr_bfree_blocks; memset(sb, 0, sizeof(struct superblock)); - sb->info = (struct simplefs_sb_info){ + sb->info = (struct simplefs_sb_info) { .magic = htole32(SIMPLEFS_MAGIC), .nr_blocks = htole32(nr_blocks), .nr_inodes = htole32(nr_inodes), diff --git a/simplefs.h b/simplefs.h index f99353f..4a9c767 100644 --- a/simplefs.h +++ b/simplefs.h @@ -101,7 +101,11 @@ struct simplefs_dir_block { }; /* superblock functions */ +#if SIMPLEFS_AT_LEAST(6, 18, 0) +int simplefs_fill_super(struct super_block *sb, struct fs_context *fc); +#else int simplefs_fill_super(struct super_block *sb, void *data, int silent); +#endif void simplefs_kill_sb(struct super_block *sb); /* inode functions */ diff --git a/super.c b/super.c index 019944e..c453603 100644 --- a/super.c +++ b/super.c @@ -13,7 +13,9 @@ #include #include "simplefs.h" - +#if SIMPLEFS_AT_LEAST(6, 18, 0) +#include +#endif struct dentry *simplefs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, @@ -529,12 +531,18 @@ static struct super_operations simplefs_super_ops = { }; /* Fill the struct superblock from partition superblock */ +#if SIMPLEFS_AT_LEAST(6, 18, 0) +int simplefs_fill_super(struct super_block *sb, struct fs_context *fc) +{ +#else int simplefs_fill_super(struct super_block *sb, void *data, int silent) { +#endif struct buffer_head *bh = NULL; struct simplefs_sb_info *csb = NULL; struct simplefs_sb_info *sbi = NULL; struct inode *root_inode = NULL; + int ret = 0, i; /* Initialize the superblock */ @@ -635,7 +643,7 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent) #elif SIMPLEFS_AT_LEAST(5, 12, 0) inode_init_owner(&init_user_ns, root_inode, NULL, root_inode->i_mode); #else - inode_init_owner(root_inode, NULL, root_inode->i_mode); +inode_init_owner(root_inode, NULL, root_inode->i_mode); #endif sb->s_root = d_make_root(root_inode); @@ -643,14 +651,16 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent) ret = -ENOMEM; goto iput; } - + /* Since parse_options is not available at fill_super stage at kernels + * v6.18+, it is disabled for now. */ +#if SIMPLEFS_LESS_EQUAL(6, 17, 0) ret = simplefs_parse_options(sb, data); if (ret) { pr_err("simplefs_fill_super: Failed to parse options, error code: %d\n", ret); return ret; } - +#endif return 0; iput: