git-UTIME
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Thu, 29 Mar 2018 19:47:29 +0000 (20:47 +0100)
committerAurelien Jarno <aurel32@debian.org>
Thu, 29 Mar 2018 19:47:29 +0000 (20:47 +0100)
commit bbe762d1e596d7f5a1cd560a229387cb856916e0
Author: Flávio Cruz <flaviocruz@gmail.com>
Date:   Mon Mar 5 23:25:00 2018 +0100

    hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC

            * sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW,
            UTIME_OMIT): New macros.
            * sysdeps/mach/hurd/futimens.c (__futimens): Try to use __file_utimens
            before reverting to converting time spec to time value and calling
            __file_utimes.
            * sysdeps/mach/hurd/utime-helper.c: New file.
            * sysdeps/mach/hurd/futimes.c: Include "utime-helper.c".
            (__futimes): Try to use utime_ts_from_tval and __file_utimens before
            reverting to utime_tvalue_from_tval and __file_utimes.
            * sysdeps/mach/hurd/lutimes.c: Include "utime-helper.c".
            (__lutimes): Just call hurd_futimens after lookup.
            * sysdeps/mach/hurd/utimes.c: Likewise.

commit ec1300cfc83c716f33ee3231bba0a6e270abfc73
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Tue Mar 6 00:13:54 2018 +0100

    hurd: Add futimesat and utimensat support

            * sysdeps/mach/hurd/utime-helper.c (hurd_futimens): Rename function to
            hurd_futimes.
            * sysdeps/mach/hurd/utimes.c (__utimes): Update call accordingly.
            * sysdeps/mach/hurd/lutimes.c (__lutimes): Likewise.
            * sysdeps/mach/hurd/futimens.c: Include "utime-helper.c".
            (__futimens): Move implementation to...
            * sysdeps/mach/hurd/utime-helper.c (utime_ts_from_tspec,
            utime_tvalue_from_tspec): ... new helper functions.
            (hurd_futimens): New function.
            * sysdeps/mach/hurd/futimesat.c: New file.
            * sysdeps/mach/hurd/utimensat.c: New file.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name git-UTIME.diff

sysdeps/mach/hurd/bits/stat.h
sysdeps/mach/hurd/futimens.c
sysdeps/mach/hurd/futimes.c
sysdeps/mach/hurd/futimesat.c [new file with mode: 0644]
sysdeps/mach/hurd/lutimes.c
sysdeps/mach/hurd/utime-helper.c [new file with mode: 0644]
sysdeps/mach/hurd/utimensat.c [new file with mode: 0644]
sysdeps/mach/hurd/utimes.c

index 7296cd2dccd3948bba7518b0a980ef6519393ed3..e354a05237af3e493169c969226cb33e2624d55f 100644 (file)
@@ -244,6 +244,11 @@ struct stat64
 # define SF_NOUNLINK   0x00100000      /* file may not be removed or renamed */
 # define SF_SNAPSHOT   0x00200000      /* snapshot inode */
 
+#ifdef __USE_ATFILE
+# define UTIME_NOW  -1 /* corresponds to the current time */
+# define UTIME_OMIT -2 /* target time is omitted */
+#endif
+
 __BEGIN_DECLS
 
 /* Set file flags for FILE to FLAGS.  */
index 218779d4c372796cfece4f4cc1030c70b9812923..9fd3387e87ebe9ee36be5700044aeb1c6ab0d91e 100644 (file)
 #include <hurd.h>
 #include <hurd/fd.h>
 
+#include "utime-helper.c"
+
 /* Change the access time of FD to TSP[0] and
    the modification time of FD to TSP[1].  */
 int
 __futimens (int fd, const struct timespec tsp[2])
 {
-  time_value_t atime, mtime;
+  struct timespec atime, mtime;
   error_t err;
 
-  if (tsp == NULL)
-    {
-      /* Setting the number of microseconds to `-1' tells the
-         underlying filesystems to use the current time.  */
-      atime.microseconds = mtime.microseconds = -1;
-    }
-  else
+  utime_ts_from_tspec (tsp, &atime, &mtime);
+
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
     {
-      atime.seconds = tsp[0].tv_sec;
-      atime.microseconds = tsp[0].tv_nsec / 1000;
-      mtime.seconds = tsp[1].tv_sec;
-      mtime.microseconds = tsp[1].tv_nsec / 1000;
-    }
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tspec (tsp, &atim, &mtim);
+
+      err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
+  }
 
-  err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime));
   return err ? __hurd_dfail (fd, err) : 0;
 }
 weak_alias (__futimens, futimens)
index cc2a68f64158f54d0821a3ea984e17806f61cbf1..1b521e3e51f0641e877ce844fd2ccea37bb84444 100644 (file)
 #include <hurd.h>
 #include <hurd/fd.h>
 
+#include "utime-helper.c"
+
 /* Change the access time of FD to TVP[0] and
    the modification time of FD to TVP[1].  */
 int
 __futimes (int fd, const struct timeval tvp[2])
 {
-  union tv
-  {
-    struct timeval tv;
-    time_value_t tvt;
-  };
-  const union tv *u = (const union tv *) tvp;
-  union tv nulltv[2];
+  struct timespec atime, mtime;
   error_t err;
 
-  if (tvp == NULL)
+  utime_ts_from_tval (tvp, &atime, &mtime);
+
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+
+  if (err == EMIG_BAD_ID || err == EOPNOTSUPP)
     {
-      /* Setting the number of microseconds to `-1' tells the
-         underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tval (tvp, &atim, &mtim);
+
+      err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
     }
 
-  err = HURD_DPORT_USE (fd, __file_utimes (port, u[0].tvt, u[1].tvt));
   return err ? __hurd_dfail (fd, err) : 0;
 }
 weak_alias (__futimes, futimes)
diff --git a/sysdeps/mach/hurd/futimesat.c b/sysdeps/mach/hurd/futimesat.c
new file mode 100644 (file)
index 0000000..99c4c63
--- /dev/null
@@ -0,0 +1,44 @@
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stddef.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+
+#include "utime-helper.c"
+
+/* Change the access time of FILE relative to FD to TVP[0] and
+   the modification time of FILE to TVP[1].  */
+int
+futimesat (int fd, const char *file, const struct timeval tvp[2])
+{
+  error_t err;
+  file_t port;
+
+  port = __file_name_lookup_at (fd, 0, file, 0, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
+  err = hurd_futimes (port, tvp);
+
+  __mach_port_deallocate (__mach_task_self (), port);
+  if (err)
+    return __hurd_fail (err);
+  return 0;
+}
index e6b0f04172166d025b3946fcac1c5f073fd9c62b..375ab3feb39f25c5220a3ef09157497da36bdee2 100644 (file)
 #include <hurd.h>
 #include <fcntl.h>
 
+#include "utime-helper.c"
+
 /* Change the access time of FILE to TVP[0] and
    the modification time of FILE to TVP[1].  */
 int
 __lutimes (const char *file, const struct timeval tvp[2])
 {
-  union tv
-  {
-    struct timeval tv;
-    time_value_t tvt;
-  };
-  const union tv *u = (const union tv *) tvp;
-  union tv nulltv[2];
   error_t err;
   file_t port;
 
-  if (tvp == NULL)
-    {
-      /* Setting the number of microseconds to `-1' tells the
-         underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
-    }
-
   port = __file_name_lookup (file, O_NOLINK, 0);
   if (port == MACH_PORT_NULL)
     return -1;
-  err = __file_utimes (port, u[0].tvt, u[1].tvt);
+
+  err = hurd_futimes (port, tvp);
+
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
     return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/utime-helper.c b/sysdeps/mach/hurd/utime-helper.c
new file mode 100644 (file)
index 0000000..6aed331
--- /dev/null
@@ -0,0 +1,154 @@
+/* Helpers for utimes/utimens conversions.
+   Copyright (C) 2015-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <hurd/hurd_types.h>
+#include <stddef.h>
+#include <sys/time.h>
+
+/* Initializes atime/mtime timespec structures from an array of timeval.  */
+static inline void
+utime_ts_from_tval (const struct timeval tvp[2],
+                    struct timespec *atime, struct timespec *mtime)
+{
+  if (tvp == NULL)
+    {
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
+         underlying filesystems to use the current time.  */
+      atime->tv_sec = 0;
+      atime->tv_nsec = UTIME_NOW;
+      mtime->tv_sec = 0;
+      mtime->tv_nsec = UTIME_NOW;
+    }
+  else
+    {
+      TIMEVAL_TO_TIMESPEC (&tvp[0], atime);
+      TIMEVAL_TO_TIMESPEC (&tvp[1], mtime);
+    }
+}
+
+/* Initializes atime/mtime time_value_t structures from an array of timeval.  */
+static inline void
+utime_tvalue_from_tval (const struct timeval tvp[2],
+                        time_value_t *atime, time_value_t *mtime)
+{
+  if (tvp == NULL)
+    /* Setting the number of microseconds to `-1' tells the
+       underlying filesystems to use the current time.  */
+    atime->microseconds = mtime->microseconds = -1;
+  else
+    {
+      atime->seconds = tvp[0].tv_sec;
+      atime->microseconds = tvp[0].tv_usec;
+      mtime->seconds = tvp[1].tv_sec;
+      mtime->microseconds = tvp[1].tv_usec;
+    }
+}
+
+/* Changes the access time of the file behind PORT using a timeval array.  */
+static inline error_t
+hurd_futimes (const file_t port, const struct timeval tvp[2])
+{
+  error_t err;
+  struct timespec atime, mtime;
+
+  utime_ts_from_tval (tvp, &atime, &mtime);
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tval (tvp, &atim, &mtim);
+
+      err = __file_utimes (port, atim, mtim);
+    }
+
+  return err;
+}
+
+/* Initializes atime/mtime timespec structures from an array of timespec.  */
+static inline void
+utime_ts_from_tspec (const struct timespec tsp[2],
+                     struct timespec *atime, struct timespec *mtime)
+{
+  if (tsp == NULL)
+    {
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
+         underlying filesystems to use the current time.  */
+      atime->tv_sec = 0;
+      atime->tv_nsec = UTIME_NOW;
+      mtime->tv_sec = 0;
+      mtime->tv_nsec = UTIME_NOW;
+    }
+  else
+    {
+      *atime = tsp[0];
+      *mtime = tsp[1];
+    }
+}
+
+/* Initializes atime/mtime time_value_t structures from an array of timespec.  */
+static inline void
+utime_tvalue_from_tspec (const struct timespec tsp[2],
+                         time_value_t *atime, time_value_t *mtime)
+{
+  if (tsp == NULL)
+    /* Setting the number of microseconds to `-1' tells the
+       underlying filesystems to use the current time.  */
+    atime->microseconds = mtime->microseconds = -1;
+  else
+    {
+      if (tsp[0].tv_nsec == UTIME_NOW)
+       atime->microseconds = -1;
+      else if (tsp[0].tv_nsec == UTIME_OMIT)
+       atime->microseconds = -2;
+      else
+       TIMESPEC_TO_TIME_VALUE (atime, &(tsp[0]));
+      if (tsp[1].tv_nsec == UTIME_NOW)
+       mtime->microseconds = -1;
+      else if (tsp[1].tv_nsec == UTIME_OMIT)
+       mtime->microseconds = -2;
+      else
+       TIMESPEC_TO_TIME_VALUE (mtime, &(tsp[1]));
+    }
+}
+
+/* Changes the access time of the file behind PORT using a timespec array.  */
+static inline error_t
+hurd_futimens (const file_t port, const struct timespec tsp[2])
+{
+  error_t err;
+  struct timespec atime, mtime;
+
+  utime_ts_from_tspec (tsp, &atime, &mtime);
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      utime_tvalue_from_tspec (tsp, &atim, &mtim);
+
+      err = __file_utimes (port, atim, mtim);
+    }
+
+  return err;
+}
diff --git a/sysdeps/mach/hurd/utimensat.c b/sysdeps/mach/hurd/utimensat.c
new file mode 100644 (file)
index 0000000..ac9bc53
--- /dev/null
@@ -0,0 +1,46 @@
+/* Change access and modification times of open file.  Hurd version.
+   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stddef.h>
+#include <hurd.h>
+#include <hurd/fd.h>
+
+#include "utime-helper.c"
+
+/* Change the access time of FILE to TSP[0] and
+   the modification time of FILE to TSP[1].  */
+int
+utimensat (int fd, const char *file, const struct timespec tsp[2],
+          int flags)
+{
+  error_t err;
+  file_t port;
+
+  port = __file_name_lookup_at (fd, flags, file, 0, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
+  err = hurd_futimens (port, tsp);
+
+  __mach_port_deallocate (__mach_task_self (), port);
+  if (err)
+    return __hurd_fail (err);
+  return 0;
+}
index 2f7c8c228dc3bd74f00eb870a551cc53159bbb37..fa8a79239bc4ab08620dad66f5a2cc76e2becfa4 100644 (file)
 #include <stddef.h>
 #include <hurd.h>
 
+#include "utime-helper.c"
+
 /* Change the access time of FILE to TVP[0] and
    the modification time of FILE to TVP[1].  */
 int
 __utimes (const char *file, const struct timeval tvp[2])
 {
-  union tv
-  {
-    struct timeval tv;
-    time_value_t tvt;
-  };
-  const union tv *u = (const union tv *) tvp;
-  union tv nulltv[2];
   error_t err;
   file_t port;
 
-  if (tvp == NULL)
-    {
-      /* Setting the number of microseconds to `-1' tells the
-         underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
-    }
-
   port = __file_name_lookup (file, 0, 0);
   if (port == MACH_PORT_NULL)
     return -1;
-  err = __file_utimes (port, u[0].tvt, u[1].tvt);
+
+  err = hurd_futimes (port, tvp);
+
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
     return __hurd_fail (err);