Skip to content

Commit fe2c325

Browse files
arndbjankara
authored andcommitted
ext2: use ktime_get_real_seconds for timestamps
get_seconds() is deprecated because of the y2038 overflow, so users should migrate to 64-bit timestamps using ktime_get_real_seconds(). In ext2, the timestamps in the superblock and in the inode are all limited to 32-bit, and this won't get fixed, so let's just stop using the deprecated interface and keep truncating. All users of ext2 should migrate to ext4 before 2038 to prevent this from causing problems. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent c3b9cec commit fe2c325

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

fs/ext2/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void ext2_evict_inode(struct inode * inode)
8686
if (want_delete) {
8787
sb_start_intwrite(inode->i_sb);
8888
/* set dtime */
89-
EXT2_I(inode)->i_dtime = get_seconds();
89+
EXT2_I(inode)->i_dtime = ktime_get_real_seconds();
9090
mark_inode_dirty(inode);
9191
__ext2_write_inode(inode, inode_needs_sync(inode));
9292
/* truncate to 0 */

fs/ext2/super.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ static int ext2_setup_super (struct super_block * sb,
682682
"running e2fsck is recommended");
683683
else if (le32_to_cpu(es->s_checkinterval) &&
684684
(le32_to_cpu(es->s_lastcheck) +
685-
le32_to_cpu(es->s_checkinterval) <= get_seconds()))
685+
le32_to_cpu(es->s_checkinterval) <=
686+
ktime_get_real_seconds()))
686687
ext2_msg(sb, KERN_WARNING,
687688
"warning: checktime reached, "
688689
"running e2fsck is recommended");
@@ -1248,7 +1249,7 @@ void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
12481249
spin_lock(&EXT2_SB(sb)->s_lock);
12491250
es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
12501251
es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
1251-
es->s_wtime = cpu_to_le32(get_seconds());
1252+
es->s_wtime = cpu_to_le32(ktime_get_real_seconds());
12521253
/* unlock before we do IO */
12531254
spin_unlock(&EXT2_SB(sb)->s_lock);
12541255
mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
@@ -1360,7 +1361,7 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data)
13601361
* the rdonly flag and then mark the partition as valid again.
13611362
*/
13621363
es->s_state = cpu_to_le16(sbi->s_mount_state);
1363-
es->s_mtime = cpu_to_le32(get_seconds());
1364+
es->s_mtime = cpu_to_le32(ktime_get_real_seconds());
13641365
spin_unlock(&sbi->s_lock);
13651366

13661367
err = dquot_suspend(sb, -1);

0 commit comments

Comments
 (0)