Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions fs.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include "simplefs.h"

#if SIMPLEFS_AT_LEAST(6, 18, 0)
#include <linux/fs_context.h>
#endif
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>

#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,
Expand All @@ -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)
{
Expand All @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mkfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions simplefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
18 changes: 14 additions & 4 deletions super.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <linux/parser.h>

#include "simplefs.h"

#if SIMPLEFS_AT_LEAST(6, 18, 0)
#include <linux/fs_context.h>
#endif
struct dentry *simplefs_mount(struct file_system_type *fs_type,
int flags,
const char *dev_name,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -635,22 +643,24 @@ 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);
if (!sb->s_root) {
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:
Expand Down
Loading