Skip to content

Commit 2ee1fc1

Browse files
committed
Enforce SIMPLEFS_{AT_LEAST,LESS_EQUAL} macro
It would look a bit more elegant with the introduction of Linux kernel version check macros.
1 parent 5929c20 commit 2ee1fc1

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int simplefs_file_get_block(struct inode *inode,
8080
/* Called by the page cache to read a page from the physical disk and map it
8181
* into memory.
8282
*/
83-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
83+
#if SIMPLEFS_AT_LEAST(5, 19, 0)
8484
static void simplefs_readahead(struct readahead_control *rac)
8585
{
8686
mpage_readahead(rac, simplefs_file_get_block);
@@ -95,7 +95,7 @@ static int simplefs_readpage(struct file *file, struct page *page)
9595
/* Called by the page cache to write a dirty page to the physical disk (when
9696
* sync is called or when memory is needed).
9797
*/
98-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0)
98+
#if SIMPLEFS_AT_LEAST(6, 8, 0)
9999
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
100100
{
101101
struct folio *folio = page_folio(page);
@@ -113,7 +113,7 @@ static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
113113
* the data into the page cache. This function checks if the write operation
114114
* can complete and allocates the necessary blocks through block_write_begin().
115115
*/
116-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
116+
#if SIMPLEFS_AT_LEAST(5, 19, 0)
117117
static int simplefs_write_begin(struct file *file,
118118
struct address_space *mapping,
119119
loff_t pos,
@@ -147,7 +147,7 @@ static int simplefs_write_begin(struct file *file,
147147
return -ENOSPC;
148148

149149
/* prepare the write */
150-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
150+
#if SIMPLEFS_AT_LEAST(5, 19, 0)
151151
err = block_write_begin(mapping, pos, len, pagep, simplefs_file_get_block);
152152
#else
153153
err = block_write_begin(mapping, pos, len, flags, pagep,
@@ -174,7 +174,7 @@ static int simplefs_write_end(struct file *file,
174174
struct inode *inode = file->f_inode;
175175
struct simplefs_inode_info *ci = SIMPLEFS_INODE(inode);
176176
struct super_block *sb = inode->i_sb;
177-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
177+
#if SIMPLEFS_AT_LEAST(6, 6, 0)
178178
struct timespec64 cur_time;
179179
#endif
180180
uint32_t nr_blocks_old;
@@ -191,11 +191,11 @@ static int simplefs_write_end(struct file *file,
191191
/* Update inode metadata */
192192
inode->i_blocks = DIV_ROUND_UP(inode->i_size, SIMPLEFS_BLOCK_SIZE) + 1;
193193

194-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
194+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
195195
cur_time = current_time(inode);
196196
inode_set_mtime_to_ts(inode, cur_time);
197197
inode_set_ctime_to_ts(inode, cur_time);
198-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
198+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
199199
cur_time = current_time(inode);
200200
inode->i_mtime = cur_time;
201201
inode_set_ctime_to_ts(inode, cur_time);
@@ -246,7 +246,7 @@ static int simplefs_write_end(struct file *file,
246246
}
247247

248248
const struct address_space_operations simplefs_aops = {
249-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)
249+
#if SIMPLEFS_AT_LEAST(5, 19, 0)
250250
.readahead = simplefs_readahead,
251251
#else
252252
.readpage = simplefs_readpage,

inode.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
6464
i_gid_write(inode, le32_to_cpu(cinode->i_gid));
6565
inode->i_size = le32_to_cpu(cinode->i_size);
6666

67-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
67+
#if SIMPLEFS_AT_LEAST(6, 6, 0)
6868
inode_set_ctime(inode, (time64_t) le32_to_cpu(cinode->i_ctime), 0);
6969
#else
7070
inode->i_ctime.tv_sec = (time64_t) le32_to_cpu(cinode->i_ctime);
7171
inode->i_ctime.tv_nsec = 0;
7272
#endif
7373

74-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
74+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
7575
inode_set_atime(inode, (time64_t) le32_to_cpu(cinode->i_atime), 0);
7676
inode_set_mtime(inode, (time64_t) le32_to_cpu(cinode->i_mtime), 0);
7777
#else
@@ -175,7 +175,7 @@ static struct dentry *simplefs_lookup(struct inode *dir,
175175
brelse(bh);
176176

177177
/* Update directory access time */
178-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
178+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
179179
inode_set_atime_to_ts(dir, current_time(dir));
180180
#else
181181
dir->i_atime = current_time(dir);
@@ -209,10 +209,8 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
209209
uint32_t ino, bno;
210210
int ret;
211211

212-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
213-
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 7, 0)
212+
#if SIMPLEFS_AT_LEAST(6, 6, 0) && SIMPLEFS_LESS_EQUAL(6, 7, 0)
214213
struct timespec64 cur_time;
215-
#endif
216214
#endif
217215

218216
/* Check mode before doing anything to avoid undoing everything */
@@ -250,9 +248,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
250248
#endif
251249
set_nlink(inode, 1);
252250

253-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
251+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
254252
simple_inode_init_ts(inode);
255-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
253+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
256254
cur_time = current_time(inode);
257255
inode->i_atime = inode->i_mtime = cur_time;
258256
inode_set_ctime_to_ts(inode, cur_time);
@@ -294,9 +292,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
294292
set_nlink(inode, 1);
295293
}
296294

297-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
295+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
298296
simple_inode_init_ts(inode);
299-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
297+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
300298
cur_time = current_time(inode);
301299
inode->i_atime = inode->i_mtime = cur_time;
302300
inode_set_ctime_to_ts(inode, cur_time);
@@ -347,10 +345,8 @@ static int simplefs_create(struct inode *dir,
347345
char *fblock;
348346
struct buffer_head *bh, *bh2;
349347

350-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
351-
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 7, 0)
348+
#if SIMPLEFS_AT_LEAST(6, 6, 0) && SIMPLEFS_LESS_EQUAL(6, 7, 0)
352349
struct timespec64 cur_time;
353-
#endif
354350
#endif
355351
int ret = 0, alloc = false, bno = 0;
356352
int ei = 0, bi = 0, fi = 0;
@@ -431,9 +427,9 @@ static int simplefs_create(struct inode *dir,
431427
/* Update stats and mark dir and new inode dirty */
432428
mark_inode_dirty(inode);
433429

434-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
430+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
435431
simple_inode_init_ts(dir);
436-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
432+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
437433
cur_time = current_time(dir);
438434
dir->i_mtime = dir->i_atime = cur_time;
439435
inode_set_ctime_to_ts(dir, cur_time);
@@ -558,10 +554,8 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
558554
struct inode *inode = d_inode(dentry);
559555
struct buffer_head *bh = NULL, *bh2 = NULL;
560556
struct simplefs_file_ei_block *file_block = NULL;
561-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
562-
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 7, 0)
557+
#if SIMPLEFS_AT_LEAST(6, 6, 0) && SIMPLEFS_LESS_EQUAL(6, 7, 0)
563558
struct timespec64 cur_time;
564-
#endif
565559
#endif
566560
int ei = 0, bi = 0;
567561
int ret = 0;
@@ -577,9 +571,9 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
577571
goto clean_inode;
578572

579573
/* Update inode stats */
580-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
574+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
581575
simple_inode_init_ts(dir);
582-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
576+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
583577
cur_time = current_time(dir);
584578
dir->i_mtime = dir->i_atime = cur_time;
585579
inode_set_ctime_to_ts(dir, cur_time);
@@ -648,11 +642,11 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
648642
i_gid_write(inode, 0);
649643
inode->i_mode = 0;
650644

651-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
645+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
652646
inode_set_mtime(inode, 0, 0);
653647
inode_set_atime(inode, 0, 0);
654648
inode_set_ctime(inode, 0, 0);
655-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
649+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
656650
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = 0;
657651
inode_set_ctime(inode, 0, 0);
658652
#else
@@ -699,10 +693,8 @@ static int simplefs_rename(struct inode *old_dir,
699693
struct simplefs_file_ei_block *eblock_new = NULL;
700694
struct simplefs_dir_block *dblock = NULL;
701695

702-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
703-
#if LINUX_VERSION_CODE <= KERNEL_VERSION(6, 7, 0)
696+
#if SIMPLEFS_AT_LEAST(6, 6, 0) && SIMPLEFS_LESS_EQUAL(6, 7, 0)
704697
struct timespec64 cur_time;
705-
#endif
706698
#endif
707699

708700
int new_pos = -1, ret = 0;
@@ -798,9 +790,9 @@ static int simplefs_rename(struct inode *old_dir,
798790
brelse(bh2);
799791

800792
/* Update new parent inode metadata */
801-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
793+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
802794
simple_inode_init_ts(new_dir);
803-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
795+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
804796
cur_time = current_time(new_dir);
805797
new_dir->i_atime = new_dir->i_mtime = cur_time;
806798
inode_set_ctime_to_ts(new_dir, cur_time);
@@ -819,9 +811,9 @@ static int simplefs_rename(struct inode *old_dir,
819811
goto release_new;
820812

821813
/* Update old parent inode metadata */
822-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
814+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
823815
simple_inode_init_ts(old_dir);
824-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
816+
#elif SIMPLEFS_AT_LEAST(6, 6, 0)
825817
cur_time = current_time(old_dir);
826818
old_dir->i_atime = old_dir->i_mtime = cur_time;
827819
inode_set_ctime_to_ts(old_dir, cur_time);

simplefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct simplefs_sb_info {
7979
/* compatibility macros */
8080
#define SIMPLEFS_AT_LEAST(major, minor, rev) \
8181
LINUX_VERSION_CODE >= KERNEL_VERSION(major, minor, rev)
82+
#define SIMPLEFS_LESS_EQUAL(major, minor, rev) \
83+
LINUX_VERSION_CODE <= KERNEL_VERSION(major, minor, rev)
8284

8385
/* A 'container' structure that keeps the VFS inode and additional on-disk
8486
* data.

super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ static int simplefs_write_inode(struct inode *inode,
8080
disk_inode->i_gid = i_gid_read(inode);
8181
disk_inode->i_size = inode->i_size;
8282

83-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
83+
#if SIMPLEFS_AT_LEAST(6, 6, 0)
8484
struct timespec64 ctime = inode_get_ctime(inode);
8585
disk_inode->i_ctime = ctime.tv_sec;
8686
#else
8787
disk_inode->i_ctime = inode->i_ctime.tv_sec;
8888
#endif
8989

90-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
90+
#if SIMPLEFS_AT_LEAST(6, 7, 0)
9191
disk_inode->i_atime = inode_get_atime_sec(inode);
9292
disk_inode->i_atime = inode_get_mtime_sec(inode);
9393
#else

0 commit comments

Comments
 (0)