Skip to content

Commit 4fa6311

Browse files
aalexandrovichgregkh
authored andcommitted
fs/ntfs3: Support timestamps prior to epoch
[ Upstream commit 5180138604323895b5c291eca6aa7c20be494ade ] Before it used an unsigned 64-bit type, which prevented proper handling of timestamps earlier than 1970-01-01. Switch to a signed 64-bit type to support pre-epoch timestamps. The issue was caught by xfstests. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5da872d commit 4fa6311

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/ntfs3/ntfs_fs.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,11 +980,12 @@ static inline __le64 kernel2nt(const struct timespec64 *ts)
980980
*/
981981
static inline void nt2kernel(const __le64 tm, struct timespec64 *ts)
982982
{
983-
u64 t = le64_to_cpu(tm) - _100ns2seconds * SecondsToStartOf1970;
983+
s32 t32;
984+
/* use signed 64 bit to support timestamps prior to epoch. xfstest 258. */
985+
s64 t = le64_to_cpu(tm) - _100ns2seconds * SecondsToStartOf1970;
984986

985-
// WARNING: do_div changes its first argument(!)
986-
ts->tv_nsec = do_div(t, _100ns2seconds) * 100;
987-
ts->tv_sec = t;
987+
ts->tv_sec = div_s64_rem(t, _100ns2seconds, &t32);
988+
ts->tv_nsec = t32 * 100;
988989
}
989990

990991
static inline struct ntfs_sb_info *ntfs_sb(struct super_block *sb)

0 commit comments

Comments
 (0)