Skip to content

Commit 19acb71

Browse files
authored
Merge pull request #32 from groverb/master
access inode's ctime access using proper accessors
2 parents 22a947d + ddc8450 commit 19acb71

File tree

3 files changed

+93
-4
lines changed

3 files changed

+93
-4
lines changed

file.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ static int simplefs_write_end(struct file *file,
168168
struct inode *inode = file->f_inode;
169169
struct simplefs_inode_info *ci = SIMPLEFS_INODE(inode);
170170
struct super_block *sb = inode->i_sb;
171+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
172+
struct timespec64 cur_time;
173+
#endif
171174
uint32_t nr_blocks_old;
172175

173176
/* Complete the write() */
@@ -181,7 +184,15 @@ static int simplefs_write_end(struct file *file,
181184

182185
/* Update inode metadata */
183186
inode->i_blocks = inode->i_size / SIMPLEFS_BLOCK_SIZE + 2;
187+
188+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
189+
cur_time = current_time(inode);
190+
inode->i_mtime = cur_time;
191+
inode_set_ctime_to_ts(inode, cur_time);
192+
#else
184193
inode->i_mtime = inode->i_ctime = current_time(inode);
194+
#endif
195+
185196
mark_inode_dirty(inode);
186197

187198
/* If file is smaller than before, free unused blocks */

inode.c

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
5454
i_uid_write(inode, le32_to_cpu(cinode->i_uid));
5555
i_gid_write(inode, le32_to_cpu(cinode->i_gid));
5656
inode->i_size = le32_to_cpu(cinode->i_size);
57+
58+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
59+
inode_set_ctime(inode, (time64_t) le32_to_cpu(cinode->i_ctime), 0);
60+
#else
5761
inode->i_ctime.tv_sec = (time64_t) le32_to_cpu(cinode->i_ctime);
5862
inode->i_ctime.tv_nsec = 0;
63+
#endif
64+
5965
inode->i_atime.tv_sec = (time64_t) le32_to_cpu(cinode->i_atime);
6066
inode->i_atime.tv_nsec = 0;
6167
inode->i_mtime.tv_sec = (time64_t) le32_to_cpu(cinode->i_mtime);
@@ -169,6 +175,10 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
169175
uint32_t ino, bno;
170176
int ret;
171177

178+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
179+
struct timespec64 cur_time;
180+
#endif
181+
172182
/* Check mode before doing anything to avoid undoing everything */
173183
if (!S_ISDIR(mode) && !S_ISREG(mode) && !S_ISLNK(mode)) {
174184
pr_err(
@@ -203,7 +213,14 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
203213
inode_init_owner(inode, dir, mode);
204214
#endif
205215
set_nlink(inode, 1);
216+
217+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
218+
cur_time = current_time(inode);
219+
inode->i_atime = inode->i_mtime = cur_time;
220+
inode_set_ctime_to_ts(inode, cur_time);
221+
#else
206222
inode->i_ctime = inode->i_atime = inode->i_mtime = current_time(inode);
223+
#endif
207224
inode->i_op = &symlink_inode_ops;
208225
return inode;
209226
}
@@ -239,7 +256,13 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
239256
set_nlink(inode, 1);
240257
}
241258

259+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
260+
cur_time = current_time(inode);
261+
inode->i_atime = inode->i_mtime = cur_time;
262+
inode_set_ctime_to_ts(inode, cur_time);
263+
#else
242264
inode->i_ctime = inode->i_atime = inode->i_mtime = current_time(inode);
265+
#endif
243266

244267
return inode;
245268

@@ -284,6 +307,11 @@ static int simplefs_create(struct inode *dir,
284307
struct simplefs_dir_block *dblock;
285308
char *fblock;
286309
struct buffer_head *bh, *bh2;
310+
311+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
312+
struct timespec64 cur_time;
313+
#endif
314+
287315
int ret = 0, alloc = false, bno = 0;
288316
int ei = 0, bi = 0, fi = 0;
289317

@@ -365,7 +393,15 @@ static int simplefs_create(struct inode *dir,
365393

366394
/* Update stats and mark dir and new inode dirty */
367395
mark_inode_dirty(inode);
396+
397+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
398+
cur_time = current_time(dir);
399+
dir->i_mtime = dir->i_atime = cur_time;
400+
inode_set_ctime_to_ts(dir, cur_time);
401+
#else
368402
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
403+
#endif
404+
369405
if (S_ISDIR(mode))
370406
inc_nlink(dir);
371407
mark_inode_dirty(dir);
@@ -480,6 +516,9 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
480516
struct inode *inode = d_inode(dentry);
481517
struct buffer_head *bh = NULL, *bh2 = NULL;
482518
struct simplefs_file_ei_block *file_block = NULL;
519+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
520+
struct timespec64 cur_time;
521+
#endif
483522
int ei = 0, bi = 0;
484523
int ret = 0;
485524

@@ -494,7 +533,14 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
494533
goto clean_inode;
495534

496535
/* Update inode stats */
536+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
537+
cur_time = current_time(dir);
538+
dir->i_mtime = dir->i_atime = cur_time;
539+
inode_set_ctime_to_ts(dir, cur_time);
540+
#else
497541
dir->i_mtime = dir->i_atime = dir->i_ctime = current_time(dir);
542+
#endif
543+
498544
if (S_ISDIR(inode->i_mode)) {
499545
drop_nlink(dir);
500546
drop_nlink(inode);
@@ -554,7 +600,14 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
554600
i_uid_write(inode, 0);
555601
i_gid_write(inode, 0);
556602
inode->i_mode = 0;
603+
604+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
605+
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = 0;
606+
inode_set_ctime(inode, 0, 0);
607+
#else
557608
inode->i_ctime.tv_sec = inode->i_mtime.tv_sec = inode->i_atime.tv_sec = 0;
609+
#endif
610+
558611
drop_nlink(inode);
559612
mark_inode_dirty(inode);
560613

@@ -593,6 +646,11 @@ static int simplefs_rename(struct inode *old_dir,
593646
struct buffer_head *bh_new = NULL, *bh2 = NULL;
594647
struct simplefs_file_ei_block *eblock_new = NULL;
595648
struct simplefs_dir_block *dblock = NULL;
649+
650+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
651+
struct timespec64 cur_time;
652+
#endif
653+
596654
int new_pos = -1, ret = 0;
597655
int ei = 0 , bi = 0, fi = 0, bno = 0;
598656

@@ -685,8 +743,14 @@ static int simplefs_rename(struct inode *old_dir,
685743
brelse(bh2);
686744

687745
/* Update new parent inode metadata */
688-
new_dir->i_atime = new_dir->i_ctime = new_dir->i_mtime =
689-
current_time(new_dir);
746+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
747+
cur_time = current_time(new_dir);
748+
new_dir->i_atime = new_dir->i_mtime = cur_time;
749+
inode_set_ctime_to_ts(new_dir, cur_time);
750+
#else
751+
new_dir->i_atime = new_dir->i_ctime = new_dir->i_mtime = current_time(new_dir);
752+
#endif
753+
690754
if (S_ISDIR(src->i_mode))
691755
inc_nlink(new_dir);
692756
mark_inode_dirty(new_dir);
@@ -697,8 +761,14 @@ static int simplefs_rename(struct inode *old_dir,
697761
goto release_new;
698762

699763
/* Update old parent inode metadata */
700-
old_dir->i_atime = old_dir->i_ctime = old_dir->i_mtime =
701-
current_time(old_dir);
764+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
765+
cur_time = current_time(old_dir);
766+
old_dir->i_atime = old_dir->i_mtime = cur_time;
767+
inode_set_ctime_to_ts(old_dir, cur_time);
768+
#else
769+
old_dir->i_atime = old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
770+
#endif
771+
702772
if (S_ISDIR(src->i_mode))
703773
drop_nlink(old_dir);
704774
mark_inode_dirty(old_dir);

super.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ static int simplefs_write_inode(struct inode *inode,
6969
disk_inode->i_uid = i_uid_read(inode);
7070
disk_inode->i_gid = i_gid_read(inode);
7171
disk_inode->i_size = inode->i_size;
72+
73+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0)
74+
struct timespec64 ctime = inode_get_ctime(inode);
75+
disk_inode->i_ctime = ctime.tv_sec;
76+
#else
7277
disk_inode->i_ctime = inode->i_ctime.tv_sec;
78+
#endif
79+
80+
7381
disk_inode->i_atime = inode->i_atime.tv_sec;
7482
disk_inode->i_mtime = inode->i_mtime.tv_sec;
7583
disk_inode->i_blocks = inode->i_blocks;

0 commit comments

Comments
 (0)