summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Bukatovic <martin.bukatovic@gmail.com>2019-03-02 19:57:17 -0800
committerPádraig Brady <P@draigBrady.com>2019-03-03 23:33:51 -0800
commit186896d65f6182dff15cad6c1045d22ad2004962 (patch)
tree9a9d475a330bb89b56dfd6e1a51ae70b67f40cd9
parent811493e2a9fc9a4fee2a3161d78a03f8af1c2392 (diff)
downloadcoreutils-186896d65f6182dff15cad6c1045d22ad2004962.tar.gz
stat: print birth time on systems supporting statx
* configure.ac: Check for statx(), available on glibc >= 2.28. * src/stat.c (get_birthtime): Call statx() when available. * NEWS: Mention the improvement.
-rw-r--r--NEWS3
-rw-r--r--configure.ac3
-rw-r--r--src/stat.c19
3 files changed, 25 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index f4c6c6b64..029ef56aa 100644
--- a/NEWS
+++ b/NEWS
@@ -98,6 +98,9 @@ GNU coreutils NEWS -*- outline -*-
stat and tail now know about the "sdcardfs" file system on Android.
stat -f -c%T now reports the file system type, and tail -f uses inotify.
+ stat now prints file creation time when supported by the file system,
+ on GNU Linux systems with glibc >= 2.28 and kernel >= 4.11.
+
* Noteworthy changes in release 8.30 (2018-07-01) [stable]
diff --git a/configure.ac b/configure.ac
index 23086cd64..0ee01b2cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -317,6 +317,9 @@ if test $ac_cv_func_getattrat = yes; then
AC_SUBST([LIB_NVPAIR])
fi
+# glibc >= 2.28 and linux kernel >= 4.11
+AC_CHECK_FUNCS([statx])
+
# SCO-ODT-3.0 is reported to need -los to link programs using initgroups
AC_CHECK_FUNCS([initgroups])
if test $ac_cv_func_initgroups = no; then
diff --git a/src/stat.c b/src/stat.c
index c8f180948..6e2f4a3ac 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -1009,6 +1009,25 @@ get_birthtime (int fd, char const *filename, struct stat const *st)
}
#endif
+#if HAVE_STATX
+ if (ts.tv_nsec < 0)
+ {
+ struct statx stx;
+ if ((fd < 0
+ ? statx (AT_FDCWD, filename,
+ follow_links ? 0 : AT_SYMLINK_NOFOLLOW,
+ STATX_BTIME, &stx)
+ : statx (fd, "", AT_EMPTY_PATH, STATX_BTIME, &stx)) == 0)
+ {
+ if ((stx.stx_mask & STATX_BTIME) && stx.stx_btime.tv_sec != 0)
+ {
+ ts.tv_sec = stx.stx_btime.tv_sec;
+ ts.tv_nsec = stx.stx_btime.tv_nsec;
+ }
+ }
+ }
+#endif
+
return ts;
}