Skip to content

Commit 71ffd70

Browse files
committed
Introduce SIMPLEFS_AT_LEAST to detect versions
As the Linux kernel development continuously changes its kernel APIs, it is necessary to detect the kernel versions and decide on the corresponding conditional build paths during the build process. The SIMPLEFS_AT_LEAST macro is introduced for this purpose.
1 parent 855c339 commit 71ffd70

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

inode.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
223223
}
224224

225225
if (S_ISLNK(mode)) {
226-
#if MNT_IDMAP_REQUIRED()
226+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
227227
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
228-
#elif USER_NS_REQUIRED()
228+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
229229
inode_init_owner(&init_user_ns, inode, dir, mode);
230230
#else
231231
inode_init_owner(inode, dir, mode);
@@ -255,9 +255,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
255255
}
256256

257257
/* Initialize inode */
258-
#if MNT_IDMAP_REQUIRED()
258+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
259259
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
260-
#elif USER_NS_REQUIRED()
260+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
261261
inode_init_owner(&init_user_ns, inode, dir, mode);
262262
#else
263263
inode_init_owner(inode, dir, mode);
@@ -302,13 +302,13 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
302302
* - cleanup index block of the new inode
303303
* - add new file/directory in parent index
304304
*/
305-
#if MNT_IDMAP_REQUIRED()
305+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
306306
static int simplefs_create(struct mnt_idmap *id,
307307
struct inode *dir,
308308
struct dentry *dentry,
309309
umode_t mode,
310310
bool excl)
311-
#elif USER_NS_REQUIRED()
311+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
312312
static int simplefs_create(struct user_namespace *ns,
313313
struct inode *dir,
314314
struct dentry *dentry,
@@ -652,14 +652,14 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
652652
return ret;
653653
}
654654

655-
#if MNT_IDMAP_REQUIRED()
655+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
656656
static int simplefs_rename(struct mnt_idmap *id,
657657
struct inode *old_dir,
658658
struct dentry *old_dentry,
659659
struct inode *new_dir,
660660
struct dentry *new_dentry,
661661
unsigned int flags)
662-
#elif USER_NS_REQUIRED()
662+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
663663
static int simplefs_rename(struct user_namespace *ns,
664664
struct inode *old_dir,
665665
struct dentry *old_dentry,
@@ -829,15 +829,15 @@ static int simplefs_rename(struct inode *old_dir,
829829
return ret;
830830
}
831831

832-
#if MNT_IDMAP_REQUIRED()
832+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
833833
static int simplefs_mkdir(struct mnt_idmap *id,
834834
struct inode *dir,
835835
struct dentry *dentry,
836836
umode_t mode)
837837
{
838838
return simplefs_create(id, dir, dentry, mode | S_IFDIR, 0);
839839
}
840-
#elif USER_NS_REQUIRED()
840+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
841841
static int simplefs_mkdir(struct user_namespace *ns,
842842
struct inode *dir,
843843
struct dentry *dentry,
@@ -954,12 +954,12 @@ static int simplefs_link(struct dentry *old_dentry,
954954
return ret;
955955
}
956956

957-
#if MNT_IDMAP_REQUIRED()
957+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
958958
static int simplefs_symlink(struct mnt_idmap *id,
959959
struct inode *dir,
960960
struct dentry *dentry,
961961
const char *symname)
962-
#elif USER_NS_REQUIRED()
962+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
963963
static int simplefs_symlink(struct user_namespace *ns,
964964
struct inode *dir,
965965
struct dentry *dentry,

simplefs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323

2424
#define SIMPLEFS_MAX_SUBFILES (SIMPLEFS_FILES_PER_EXT * SIMPLEFS_MAX_EXTENTS)
2525

26-
#include <linux/version.h>
27-
28-
#define USER_NS_REQUIRED() LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
29-
#define MNT_IDMAP_REQUIRED() LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
30-
3126
/* simplefs partition layout
3227
* +---------------+
3328
* | superblock | 1 block
@@ -80,6 +75,11 @@ struct simplefs_sb_info {
8075
};
8176

8277
#ifdef __KERNEL__
78+
#include <linux/version.h>
79+
/* compatibility macros */
80+
#define SIMPLEFS_AT_LEAST(major, minor, rev) \
81+
LINUX_VERSION_CODE >= KERNEL_VERSION(major, minor, rev)
82+
8383
struct simplefs_inode_info {
8484
uint32_t ei_block; /* Block with list of extents for this file */
8585
char i_data[32];

super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ int simplefs_fill_super(struct super_block *sb, void *data, int silent)
301301
goto free_bfree;
302302
}
303303

304-
#if MNT_IDMAP_REQUIRED()
304+
#if SIMPLEFS_AT_LEAST(6, 3, 0)
305305
inode_init_owner(&nop_mnt_idmap, root_inode, NULL, root_inode->i_mode);
306-
#elif USER_NS_REQUIRED()
306+
#elif SIMPLEFS_AT_LEAST(5, 12, 0)
307307
inode_init_owner(&init_user_ns, root_inode, NULL, root_inode->i_mode);
308308
#else
309309
inode_init_owner(root_inode, NULL, root_inode->i_mode);

0 commit comments

Comments
 (0)