Skip to content

Commit

Permalink
Fix compilation error for Linux 6.3 (#24)
Browse files Browse the repository at this point in the history
Prior to Linux v6.3, function prototype was declared below:
void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
	        const struct inode *dir, umode_t mode);

Since Linux v6.3, it becomes as following:
void inode_init_owner(struct mnt_idmap *idmap, struct inode *inode,
                const struct inode *dir, umode_t mode);

This patch takes the change of inode_init_owner prototype into consideration.

Close #23
  • Loading branch information
fewletter committed Jun 3, 2023
1 parent f719a46 commit a2ba8bd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
42 changes: 36 additions & 6 deletions inode.c
Expand Up @@ -195,7 +195,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
}

if (S_ISLNK(mode)) {
#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
inode_init_owner(&nop_mnt_idmap, inode, dir, inode->mode);
#elif USER_NS_REQUIRED()
inode_init_owner(&init_user_ns, inode, dir, mode);
#else
inode_init_owner(inode, dir, mode);
Expand All @@ -216,7 +218,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
}

/* Initialize inode */
#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
inode_init_owner(&nop_mnt_idmap, inode, dir, inode->mode);
#elif USER_NS_REQUIRED()
inode_init_owner(&init_user_ns, inode, dir, mode);
#else
inode_init_owner(inode, dir, mode);
Expand Down Expand Up @@ -254,7 +258,13 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
* - cleanup index block of the new inode
* - add new file/directory in parent index
*/
#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
static int simplefs_create(struct mnt_idmap *id,
struct inode *dir,
struct dentry *dentry,
umode_t mode,
bool excl)
#elif USER_NS_REQUIRED()
static int simplefs_create(struct user_namespace *ns,
struct inode *dir,
struct dentry *dentry,
Expand Down Expand Up @@ -555,7 +565,14 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
return ret;
}

#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
static int simplefs_rename(struct mnt_idmap *id,
struct inode *old_dir,
struct dentry *old_dentry,
struct inode *new_dir,
struct dentry *new_dentry,
unsigned int flags)
#elif USER_NS_REQUIRED()
static int simplefs_rename(struct user_namespace *ns,
struct inode *old_dir,
struct dentry *old_dentry,
Expand Down Expand Up @@ -699,7 +716,15 @@ static int simplefs_rename(struct inode *old_dir,
return ret;
}

#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
static int simplefs_mkdir(struct mnt_idmap *id,
struct inode *dir,
struct dentry *dentry,
umode_t mode)
{
return simplefs_create(id, dir, dentry, mode | S_IFDIR, 0);
}
#elif USER_NS_REQUIRED()
static int simplefs_mkdir(struct user_namespace *ns,
struct inode *dir,
struct dentry *dentry,
Expand Down Expand Up @@ -815,7 +840,12 @@ static int simplefs_link(struct dentry *old_dentry,
return ret;
}

#if USER_NS_REQUIRED()
#if MNT_IDMAP_REQUIRED()
static int simplefs_symlink(struct mnt_idmap *id,
struct inode *dir,
struct dentry *dentry,
const char *symname)
#elif USER_NS_REQUIRED()
static int simplefs_symlink(struct user_namespace *ns,
struct inode *dir,
struct dentry *dentry,
Expand Down
1 change: 1 addition & 0 deletions simplefs.h
Expand Up @@ -27,6 +27,7 @@
#include <linux/version.h>

#define USER_NS_REQUIRED() LINUX_VERSION_CODE >= KERNEL_VERSION(5,12,0)
#define MNT_IDMAP_REQUIRED() LINUX_VERSION_CODE >= KERNEL_VERSION(6,3,0)

/*
* simplefs partition layout
Expand Down
5 changes: 4 additions & 1 deletion super.c
Expand Up @@ -282,7 +282,10 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent)
ret = PTR_ERR(root_inode);
goto free_bfree;
}
#if USER_NS_REQUIRED()

#if MNT_IDMAP_REQUIRED()
inode_init_owner(&nop_mnt_idmap, root_inode, NULL, root_inode->i_mode);
#elif USER_NS_REQUIRED()
inode_init_owner(&init_user_ns, root_inode, NULL, root_inode->i_mode);
#else
inode_init_owner(root_inode, NULL, root_inode->i_mode);
Expand Down

0 comments on commit a2ba8bd

Please sign in to comment.