Skip to content

Commit bcf451e

Browse files
arndbtorvalds
authored andcommitted
fs/ntfs: use timespec64 directly for timestamp conversion
Now that the VFS has been converted from timespec to timespec64 timestamps, only the conversion to/from ntfs timestamps uses 32-bit seconds. This changes that last missing piece to get the ntfs implementation y2038 safe on 32-bit architectures. Link: http://lkml.kernel.org/r/20180718115017.742609-2-arnd@arndb.de Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Anton Altaparmakov <anton@tuxera.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a3fda0f commit bcf451e

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

‎fs/ntfs/inode.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,18 @@ static int ntfs_read_locked_inode(struct inode *vi)
667667
* mtime is the last change of the data within the file. Not changed
668668
* when only metadata is changed, e.g. a rename doesn't affect mtime.
669669
*/
670-
vi->i_mtime = timespec_to_timespec64(ntfs2utc(si->last_data_change_time));
670+
vi->i_mtime = ntfs2utc(si->last_data_change_time);
671671
/*
672672
* ctime is the last change of the metadata of the file. This obviously
673673
* always changes, when mtime is changed. ctime can be changed on its
674674
* own, mtime is then not changed, e.g. when a file is renamed.
675675
*/
676-
vi->i_ctime = timespec_to_timespec64(ntfs2utc(si->last_mft_change_time));
676+
vi->i_ctime = ntfs2utc(si->last_mft_change_time);
677677
/*
678678
* Last access to the data within the file. Not changed during a rename
679679
* for example but changed whenever the file is written to.
680680
*/
681-
vi->i_atime = timespec_to_timespec64(ntfs2utc(si->last_access_time));
681+
vi->i_atime = ntfs2utc(si->last_access_time);
682682

683683
/* Find the attribute list attribute if present. */
684684
ntfs_attr_reinit_search_ctx(ctx);
@@ -2997,7 +2997,7 @@ int __ntfs_write_inode(struct inode *vi, int sync)
29972997
si = (STANDARD_INFORMATION*)((u8*)ctx->attr +
29982998
le16_to_cpu(ctx->attr->data.resident.value_offset));
29992999
/* Update the access times if they have changed. */
3000-
nt = utc2ntfs(timespec64_to_timespec(vi->i_mtime));
3000+
nt = utc2ntfs(vi->i_mtime);
30013001
if (si->last_data_change_time != nt) {
30023002
ntfs_debug("Updating mtime for inode 0x%lx: old = 0x%llx, "
30033003
"new = 0x%llx", vi->i_ino, (long long)
@@ -3006,7 +3006,7 @@ int __ntfs_write_inode(struct inode *vi, int sync)
30063006
si->last_data_change_time = nt;
30073007
modified = true;
30083008
}
3009-
nt = utc2ntfs(timespec64_to_timespec(vi->i_ctime));
3009+
nt = utc2ntfs(vi->i_ctime);
30103010
if (si->last_mft_change_time != nt) {
30113011
ntfs_debug("Updating ctime for inode 0x%lx: old = 0x%llx, "
30123012
"new = 0x%llx", vi->i_ino, (long long)
@@ -3015,7 +3015,7 @@ int __ntfs_write_inode(struct inode *vi, int sync)
30153015
si->last_mft_change_time = nt;
30163016
modified = true;
30173017
}
3018-
nt = utc2ntfs(timespec64_to_timespec(vi->i_atime));
3018+
nt = utc2ntfs(vi->i_atime);
30193019
if (si->last_access_time != nt) {
30203020
ntfs_debug("Updating atime for inode 0x%lx: old = 0x%llx, "
30213021
"new = 0x%llx", vi->i_ino,

‎fs/ntfs/time.h‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@
3636
* Convert the Linux UTC time @ts to its corresponding NTFS time and return
3737
* that in little endian format.
3838
*
39-
* Linux stores time in a struct timespec consisting of a time_t (long at
40-
* present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
41-
* intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
42-
* 1-nano-second intervals since the value of tv_sec.
39+
* Linux stores time in a struct timespec64 consisting of a time64_t tv_sec
40+
* and a long tv_nsec where tv_sec is the number of 1-second intervals since
41+
* 1st January 1970, 00:00:00 UTC and tv_nsec is the number of 1-nano-second
42+
* intervals since the value of tv_sec.
4343
*
4444
* NTFS uses Microsoft's standard time format which is stored in a s64 and is
4545
* measured as the number of 100-nano-second intervals since 1st January 1601,
4646
* 00:00:00 UTC.
4747
*/
48-
static inline sle64 utc2ntfs(const struct timespec ts)
48+
static inline sle64 utc2ntfs(const struct timespec64 ts)
4949
{
5050
/*
5151
* Convert the seconds to 100ns intervals, add the nano-seconds
@@ -63,7 +63,10 @@ static inline sle64 utc2ntfs(const struct timespec ts)
6363
*/
6464
static inline sle64 get_current_ntfs_time(void)
6565
{
66-
return utc2ntfs(current_kernel_time());
66+
struct timespec64 ts;
67+
68+
ktime_get_coarse_real_ts64(&ts);
69+
return utc2ntfs(ts);
6770
}
6871

6972
/**
@@ -73,18 +76,18 @@ static inline sle64 get_current_ntfs_time(void)
7376
* Convert the little endian NTFS time @time to its corresponding Linux UTC
7477
* time and return that in cpu format.
7578
*
76-
* Linux stores time in a struct timespec consisting of a time_t (long at
77-
* present) tv_sec and a long tv_nsec where tv_sec is the number of 1-second
78-
* intervals since 1st January 1970, 00:00:00 UTC and tv_nsec is the number of
79-
* 1-nano-second intervals since the value of tv_sec.
79+
* Linux stores time in a struct timespec64 consisting of a time64_t tv_sec
80+
* and a long tv_nsec where tv_sec is the number of 1-second intervals since
81+
* 1st January 1970, 00:00:00 UTC and tv_nsec is the number of 1-nano-second
82+
* intervals since the value of tv_sec.
8083
*
8184
* NTFS uses Microsoft's standard time format which is stored in a s64 and is
8285
* measured as the number of 100 nano-second intervals since 1st January 1601,
8386
* 00:00:00 UTC.
8487
*/
85-
static inline struct timespec ntfs2utc(const sle64 time)
88+
static inline struct timespec64 ntfs2utc(const sle64 time)
8689
{
87-
struct timespec ts;
90+
struct timespec64 ts;
8891

8992
/* Subtract the NTFS time offset. */
9093
u64 t = (u64)(sle64_to_cpu(time) - NTFS_TIME_OFFSET);

0 commit comments

Comments
 (0)