bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib support for st_birthtime


From: James Youngman
Subject: gnulib support for st_birthtime
Date: Sat, 24 Mar 2007 19:35:01 +0000

Apologies if I have something signficant wrong; it's my first
nontrivial gnulib patch.


2007-03-24  James Youngman  <address@hidden>

        * lib/stat-time.h (get_stat_birthtime): New function for
         retrieving st_birthtime as provided by UFS2 (hence *BSD).
        * m4/stat-time.m4 (gl_STAT_BIRTHTIME): Probe for st_birthtime
          and its variants.
        * /modules/stat-time (configure.ac): call gl_STAT_BIRTHTIME.
        

Index: lib/stat-time.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/stat-time.h,v
retrieving revision 1.4
diff -u -p -r1.4 stat-time.h
--- lib/stat-time.h     23 Feb 2007 18:25:21 -0000      1.4
+++ lib/stat-time.h     24 Mar 2007 19:27:33 -0000
@@ -131,4 +131,66 @@ get_stat_mtime (struct stat const *st)
#endif
}

+/* Return *ST's birth time, if available, in *PTS.  A nonzero value is
+ * returned if the stat structure appears to indicate that the
+ * timestamp is available.
+ *
+ * The return value of this function does not reliably indicate that the
+ * returned data is valid; see the comments within the body of the
+ * function for an explanation.
+ */
+#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIME) ||
defined(HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC) ||
defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
+static inline int
+get_stat_birthtime (struct stat const *st,
+                   struct timespec *pts)
+{
+#ifdef STAT_TIMESPEC
+  *pts = STAT_TIMESPEC (st, st_birthtim);
+#else
+  struct timespec t;
+  pts->tv_sec = st->st_birthtime;
+  pts->tv_nsec = get_stat_birthtime_ns (st);
#endif
+
+#if 0 && defined(UTIME_OMIT)
+  /* This code is disabled because UTIME_OMIT is not currently specified
+   * to be set in any field by any stat() function.  UTIME_OMIT is
+   * introduced in current (Sat Mar 24 15:30:59 2007) POSIX drafts for
+   * utimensat().  It is defined in <sys/time.h>.
+   */
+  if (UTIME_OMIT == pts->tv_nsec)
+    return 0;
+#endif
+
+  /* NetBSD sometimes signals the absence of knowledge of the file's
+   * birth time by using zero.  Indicate we don't know.  This is
+   * slightly problematic since (time_t)0 is otherwise a valid, albeit
+   * unlikely, timestamp.  NetBSD sometimes returns 0 for unknown
+   * values (for example on ffs) and sometimes begative values for
+   * tv_nsec (for example on NFS).
+   *
+   * For some filesystems (e.g. msdos) NetBSD also appears to fail to
+   * update the st_birthtime member at all.  Therefore callers are
+   * advised to initialise the tv_nsec number to a negative value
+   * before they call stat in order to detect this problem.
+   */
+  if (pts->tv_sec == (time_t)0)
+    return 0;
+  else
+    return (pts->tv_nsec >= 0) && (pts->tv_nsec <= 1000000000);
+}
+#else
+/* Birth time not supported. */
+static inline int
+get_stat_birthtime (struct stat const *st,
+                   struct timespec *pts)
+{
+  pts->tv_sec = 0;
+  pts->tv_nsec = 0;
+  return 0;
+}
+#endif
+
+#endif
+
+
Index: m4/stat-time.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/stat-time.m4,v
retrieving revision 1.4
diff -u -p -r1.4 stat-time.m4
--- m4/stat-time.m4     18 Jan 2007 08:33:35 -0000      1.4
+++ m4/stat-time.m4     24 Mar 2007 19:27:33 -0000
@@ -10,11 +10,13 @@
dnl From Paul Eggert.

# st_atim.tv_nsec - Linux, Solaris
-# st_atimespec.tv_nsec - FreeBSD, if ! defined _POSIX_SOURCE
-# st_atimensec - FreeBSD, if defined _POSIX_SOURCE
+# st_atimespec.tv_nsec - FreeBSD, NetBSD, if ! defined _POSIX_SOURCE
+# st_atimensec - FreeBSD, NetBSD, if defined _POSIX_SOURCE
# st_atim.st__tim.tv_nsec - UnixWare (at least 2.1.2 through 7.1)
# st_spare1 - Cygwin?

+# st_birthtimespec present on NetBSD (probably also FreBSD, OpenBSD)
+
AC_DEFUN([gl_STAT_TIME],
[
  AC_REQUIRE([AC_C_INLINE])
@@ -61,3 +63,24 @@ AC_DEFUN([gl_STAT_TIME],
    [#include <sys/types.h>
     #include <sys/stat.h>])
])
+
+# Checks for st_birthtime, which is a feature from UFS2 (FreeBSD,
NetBSD, OpenBSD, etc.)
+# There was a time when this field was named st_createtime (21 June
2002 to 16 July 2002)
+# But that window is very small and applied only to development code,
so systems still
+# using that configuration are not a realistic development target.
+# See revisions 1.10 and 1.11 of FreeBSD's src/sys/ufs/ufs/dinode.h.
+#
+AC_DEFUN([gl_STAT_BIRTHTIME],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_CHECK_HEADERS_ONCE([sys/time.h])
+  AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_sec,
+                    struct stat.st_birthtimespec.tv_nsec], [],
+       dnl If not found, check for st_birthtime and st_birthtimensec
+       AC_CHECK_MEMBERS([struct stat.st_birthtime, struct
stat.st_birthtimensec], [], [],
+                       [#include <sys/types.h>
+                        #include <sys/stat.h>]),
+       [#include <sys/types.h>
+       #include <sys/stat.h>])
+])
Index: modules/stat-time
===================================================================
RCS file: /sources/gnulib/gnulib/modules/stat-time,v
retrieving revision 1.4
diff -u -p -r1.4 stat-time
--- modules/stat-time   12 Feb 2007 18:49:19 -0000      1.4
+++ modules/stat-time   24 Mar 2007 19:27:34 -0000
@@ -10,6 +10,7 @@ time

configure.ac:
gl_STAT_TIME
+gl_STAT_BIRTHTIME

Makefile.am:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]