]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
stat: print birth time on systems supporting statx
authorMartin Bukatovic <martin.bukatovic@gmail.com>
Sun, 3 Mar 2019 03:57:17 +0000 (19:57 -0800)
committerPádraig Brady <P@draigBrady.com>
Mon, 4 Mar 2019 07:33:51 +0000 (23:33 -0800)
* configure.ac: Check for statx(), available on glibc >= 2.28.
* src/stat.c (get_birthtime): Call statx() when available.
* NEWS: Mention the improvement.

NEWS
configure.ac
src/stat.c

diff --git a/NEWS b/NEWS
index f4c6c6b6430b027a1c0d82ba12a9af940f0afe5f..029ef56aa28e8f1c922723f87f97eeef37ac076c 100644 (file)
--- 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]
 
index 23086cd640594c6022fcfe0e3ba6fe9401c1b899..0ee01b2cd83438d138ed3820e8048b72d813312f 100644 (file)
@@ -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
index c8f18094850e051145e02a5af5b0d32ff4bfa7ef..6e2f4a3acc612f9884a823ae675bf94349a8ede2 100644 (file)
@@ -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;
 }