From e73d481a76a5814076ff78a1c3a70e9b7da7c0e9 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 12 Dec 2022 18:51:12 +0200 Subject: [PATCH] mkntfs.c: Enable microsecond-precision volume creation time. Previously the creation time was filled in with seconds (obtained using time(NULL)) but the microsecond part was left zeroed. Fixed by using gettimeofday when available. --- ntfsprogs/mkntfs.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 3e127a3d..5c3a367b 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -776,8 +776,20 @@ static ntfs_time mkntfs_time(void) ts.tv_sec = 0; ts.tv_nsec = 0; - if (!opts.use_epoch_time) - ts.tv_sec = time(NULL); + if (!opts.use_epoch_time) { +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv = { 0, 0, }; + + if (!gettimeofday(&tv, NULL)) { + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000L; + } + else +#endif + { + ts.tv_sec = time(NULL); + } + } return timespec2ntfs(ts); }