Skip to content

Commit 7b62b29

Browse files
arndbtytso
authored andcommitted
ext4: use timespec64 for all inode times
This is the last missing piece for the inode times on 32-bit systems: now that VFS interfaces use timespec64, we just need to stop truncating the tv_sec values for y2038 compatibililty. Reviewed-by: Andreas Dilger <adilger@dilger.ca> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 5ffff83 commit 7b62b29

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -789,17 +789,16 @@ struct move_extent {
789789
* affected filesystem before 2242.
790790
*/
791791

792-
static inline __le32 ext4_encode_extra_time(struct timespec *time)
792+
static inline __le32 ext4_encode_extra_time(struct timespec64 *time)
793793
{
794-
u32 extra = sizeof(time->tv_sec) > 4 ?
795-
((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK : 0;
794+
u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK;
796795
return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS));
797796
}
798797

799-
static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
798+
static inline void ext4_decode_extra_time(struct timespec64 *time,
799+
__le32 extra)
800800
{
801-
if (unlikely(sizeof(time->tv_sec) > 4 &&
802-
(extra & cpu_to_le32(EXT4_EPOCH_MASK)))) {
801+
if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) {
803802

804803
#if 1
805804
/* Handle legacy encoding of pre-1970 dates with epoch
@@ -821,9 +820,8 @@ static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
821820
do { \
822821
(raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
823822
if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\
824-
struct timespec ts = timespec64_to_timespec((inode)->xtime); \
825823
(raw_inode)->xtime ## _extra = \
826-
ext4_encode_extra_time(&ts); \
824+
ext4_encode_extra_time(&(inode)->xtime); \
827825
} \
828826
} while (0)
829827

@@ -840,10 +838,8 @@ do { \
840838
do { \
841839
(inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
842840
if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \
843-
struct timespec ts = timespec64_to_timespec((inode)->xtime); \
844-
ext4_decode_extra_time(&ts, \
841+
ext4_decode_extra_time(&(inode)->xtime, \
845842
raw_inode->xtime ## _extra); \
846-
(inode)->xtime = timespec_to_timespec64(ts); \
847843
} \
848844
else \
849845
(inode)->xtime.tv_nsec = 0; \
@@ -993,9 +989,9 @@ struct ext4_inode_info {
993989

994990
/*
995991
* File creation time. Its function is same as that of
996-
* struct timespec i_{a,c,m}time in the generic inode.
992+
* struct timespec64 i_{a,c,m}time in the generic inode.
997993
*/
998-
struct timespec i_crtime;
994+
struct timespec64 i_crtime;
999995

1000996
/* mballoc */
1001997
struct list_head i_prealloc_list;

‎fs/ext4/ialloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
10861086
/* This is the optimal IO size (for stat), not the fs block size */
10871087
inode->i_blocks = 0;
10881088
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
1089-
ei->i_crtime = timespec64_to_timespec(inode->i_mtime);
1089+
ei->i_crtime = inode->i_mtime;
10901090

10911091
memset(ei->i_data, 0, sizeof(ei->i_data));
10921092
ei->i_dir_start_lookup = 0;

0 commit comments

Comments
 (0)