unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC
@ 2015-10-12 22:30 Samuel Thibault
  2015-11-09 18:56 ` Roland McGrath
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Thibault @ 2015-10-12 22:30 UTC (permalink / raw
  To: libc-alpha, roland; +Cc: bug-hurd, Flávio Cruz

Hello,

Roland, Flávio worked on adding a file_utimens RPC, which handles
nanosecond-precision utimes, as well as implementing UTIME_NOW and
UTIME_OMIT, here is first the RPC definition and documentation:

diff --git a/hurd/fs.defs b/hurd/fs.defs
index a4a48cc..171e43f 100644
--- a/hurd/fs.defs
+++ b/hurd/fs.defs
@@ -371,3 +371,13 @@ routine file_get_source (
 	file: file_t;
 	RPT
 	out source: string_t);
+
+/* Change access and modify times with nanosecond precision */
+/* If the nanoseconds value is UTIME_NOW then the time should be
+   set to the current time and the remainder of the time_value_t ignored.
+   If the nanoseconds value is UTIME_OMIT then the time is ignored. */
+routine file_utimens (
+	utimes_file: file_t;
+	RPT
+	new_atime: timespec_t;
+	new_mtime: timespec_t);
diff --git a/doc/hurd.texi b/doc/hurd.texi
index 2f36bdc..26e51e1 100644
--- a/doc/hurd.texi
+++ b/doc/hurd.texi
@@ -2723,6 +2723,14 @@ the file.  Making this call must cause the @var{ctime} to be updated as
 well, even if no actual change to either the @var{mtime} or the
 @var{atime} occurs.
 
+@findex file_utimens
+The @code{file_utimens} RPC changes the @var{atime} and @var{mtime} of
+the file with nanosecond precision. Making this call must cause the
+@var{ctime} to be updated as well, even if no actual change to either the
+@var{mtime} or the @var{atime} occurs. The arguments @var{atime} and
+@var{mtime} follow the POSIX standard and may use the flags
+@code{UTIME_OMIT} and @code{UTIME_NOW}.
+
 @findex file_set_size
 The @code{file_set_size} RPC is special; not only does it change the
 status word specifying the size of the file, but it also changes the

Any objection to this?  The entailed glibc changes are below.

Samuel



2015-09-20  Flávio Cruz  <flaviocruz@gmail.com>

	Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC.

	* sysdeps/mach/hurd/bits/stat.h (UTIME_NOW, UTIME_OMIT): New macros.
	* sysdeps/mach/hurd/futimens.c (__futimens): Convert `tsp' to struct
	timespec to try to use the file_utimens RPC, before rolling back to
	using file_utimes.
	* sysdeps/mach/hurd/futimes (__futimes): Likewise.
	* sysdeps/mach/hurd/lutimes (__lutimes): Likewise.
	* sysdeps/mach/hurd/utimes (__utimes): Likewise.

diff --git a/sysdeps/mach/hurd/bits/stat.h b/sysdeps/mach/hurd/bits/stat.h
index f60a58a..c2d0cc2 100644
--- a/sysdeps/mach/hurd/bits/stat.h
+++ b/sysdeps/mach/hurd/bits/stat.h
@@ -246,6 +246,10 @@ struct stat64
 # define SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
 # define SF_SNAPSHOT	0x00200000	/* snapshot inode */
 
+/* Time flags for futimens. */
+#define UTIME_NOW   -1  /* corresponds to the current time */
+#define UTIME_OMIT  -2  /* target time is omitted */
+
 __BEGIN_DECLS
 
 /* Set file flags for FILE to FLAGS.  */
diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c
index 4f82f1e..3159cb0 100644
--- a/sysdeps/mach/hurd/futimens.c
+++ b/sysdeps/mach/hurd/futimens.c
@@ -27,24 +27,51 @@
 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
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      atime.microseconds = mtime.microseconds = -1;
+      atime.tv_sec = 0;
+      atime.tv_nsec = UTIME_NOW;
+      mtime.tv_sec = 0;
+      mtime.tv_nsec = UTIME_NOW;
     }
   else
     {
-      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;
+      atime = tsp[0];
+      mtime = tsp[1];
     }
 
-  err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime));
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tsp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else if (tsp[0].tv_nsec == UTIME_OMIT || tsp[1].tv_nsec == UTIME_OMIT)
+        return EOPNOTSUPP;
+      else
+        {
+          if (tsp[0].tv_nsec == UTIME_NOW)
+            atim.microseconds = -1;
+          else
+            TIMESPEC_TO_TIME_VALUE (&atim, &(tsp[0]));
+          if (tsp[1].tv_nsec == UTIME_NOW)
+            mtim.microseconds = -1;
+          else
+            TIMESPEC_TO_TIME_VALUE (&mtim, &(tsp[1]));
+        }
+
+      err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
+  }
+
   return err ? __hurd_dfail (fd, err) : 0;
 }
 weak_alias (__futimens, futimens)
diff --git a/sysdeps/mach/hurd/futimes.c b/sysdeps/mach/hurd/futimes.c
index c325d44..dc8ae61 100644
--- a/sysdeps/mach/hurd/futimes.c
+++ b/sysdeps/mach/hurd/futimes.c
@@ -27,24 +27,44 @@
 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)
     {
-      /* Setting the number of microseconds to `-1' tells the
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
+      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);
+    }
+
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+  if (err == EMIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tvp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else
+        {
+          atim.seconds = tvp[0].tv_sec;
+          atim.microseconds = tvp[0].tv_usec;
+          mtim.seconds = tvp[1].tv_sec;
+          mtim.microseconds = tvp[1].tv_usec;
+        }
+
+      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/lutimes.c b/sysdeps/mach/hurd/lutimes.c
index 260842d..c1d5566 100644
--- a/sysdeps/mach/hurd/lutimes.c
+++ b/sysdeps/mach/hurd/lutimes.c
@@ -27,28 +27,50 @@
 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];
+  struct timespec atime, mtime;
   error_t err;
   file_t port;
 
+  port = __file_name_lookup (file, O_NOLINK, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
   if (tvp == NULL)
     {
-      /* Setting the number of microseconds to `-1' tells the
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
+      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);
+    }
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tvp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else
+        {
+          atim.seconds = tvp[0].tv_sec;
+          atim.microseconds = tvp[0].tv_usec;
+          mtim.seconds = tvp[1].tv_sec;
+          mtim.microseconds = tvp[1].tv_usec;
+        }
+
+      err = __file_utimes (port, atim, mtim);
     }
 
-  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);
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
     return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/utimes.c b/sysdeps/mach/hurd/utimes.c
index 6739b79..1578637 100644
--- a/sysdeps/mach/hurd/utimes.c
+++ b/sysdeps/mach/hurd/utimes.c
@@ -27,28 +27,50 @@ __utimes (file, tvp)
      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];
+  struct timespec atime, mtime;
   error_t err;
   file_t port;
 
+  port = __file_name_lookup (file, 0, 0);
+  if (port == MACH_PORT_NULL)
+    return -1;
+
   if (tvp == NULL)
     {
-      /* Setting the number of microseconds to `-1' tells the
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1;
-      u = nulltv;
+      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);
+    }
+
+  err = __file_utimens (port, atime, mtime);
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tvp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else
+        {
+          atim.seconds = tvp[0].tv_sec;
+          atim.microseconds = tvp[0].tv_usec;
+          mtim.seconds = tvp[1].tv_sec;
+          mtim.microseconds = tvp[1].tv_usec;
+        }
+
+      err = __file_utimes (port, atim, mtim);
     }
 
-  port = __file_name_lookup (file, 0, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-  err = __file_utimes (port, u[0].tvt, u[1].tvt);
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
     return __hurd_fail (err);


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC
  2015-10-12 22:30 [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC Samuel Thibault
@ 2015-11-09 18:56 ` Roland McGrath
  2015-11-17 23:19   ` Flavio Cruz
  0 siblings, 1 reply; 4+ messages in thread
From: Roland McGrath @ 2015-11-09 18:56 UTC (permalink / raw
  To: Samuel Thibault; +Cc: libc-alpha, bug-hurd, Flávio Cruz

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=unknown, Size: 1136 bytes --]

Don't repeat all that code.  Make a shared helper function _hurd_futimens
or suchlike.

> 2015-09-20  Flávio Cruz  <flaviocruz@gmail.com>
> 
> 	Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC.
> 
> 	* sysdeps/mach/hurd/bits/stat.h (UTIME_NOW, UTIME_OMIT): New macros.

No blank line there.  A ChangeLog paragraph (sequence with no blank lines)
covers a single logical change.  If you want to put a descriptive sentence
(not associated with a particular file) at the top of the change, then it
is the first line of the paragraph.

> --- a/sysdeps/mach/hurd/bits/stat.h
> +++ b/sysdeps/mach/hurd/bits/stat.h
> @@ -246,6 +246,10 @@ struct stat64
>  # define SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
>  # define SF_SNAPSHOT	0x00200000	/* snapshot inode */
>  
> +/* Time flags for futimens. */
> +#define UTIME_NOW   -1  /* corresponds to the current time */
> +#define UTIME_OMIT  -2  /* target time is omitted */

These should be under #ifdef __USE_ATFILE as they are in other bits/stat.h
files.  These are not "flags".  They are special values for the tv_nsec
field.  Two spaces after a period.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC
  2015-11-09 18:56 ` Roland McGrath
@ 2015-11-17 23:19   ` Flavio Cruz
  2018-03-06  7:46     ` Samuel Thibault
  0 siblings, 1 reply; 4+ messages in thread
From: Flavio Cruz @ 2015-11-17 23:19 UTC (permalink / raw
  To: Roland McGrath; +Cc: Samuel Thibault, libc-alpha, bug-hurd

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=utf-8, Size: 10503 bytes --]

On Mon, Nov 09, 2015 at 10:56:19AM -0800, Roland McGrath wrote:
> Don't repeat all that code.  Make a shared helper function _hurd_futimens
> or suchlike.

Done. I've added a new file utime-helper.c that is included by the other files and refactors common code into 3 functions.

> 
> > 2015-09-20  Flávio Cruz  <flaviocruz@gmail.com>
> > 
> > 	Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC.
> > 
> > 	* sysdeps/mach/hurd/bits/stat.h (UTIME_NOW, UTIME_OMIT): New macros.
> 
> No blank line there.  A ChangeLog paragraph (sequence with no blank lines)
> covers a single logical change.  If you want to put a descriptive sentence
> (not associated with a particular file) at the top of the change, then it
> is the first line of the paragraph.
> 
> > --- a/sysdeps/mach/hurd/bits/stat.h
> > +++ b/sysdeps/mach/hurd/bits/stat.h
> > @@ -246,6 +246,10 @@ struct stat64
> >  # define SF_NOUNLINK	0x00100000	/* file may not be removed or renamed */
> >  # define SF_SNAPSHOT	0x00200000	/* snapshot inode */
> >  
> > +/* Time flags for futimens. */
> > +#define UTIME_NOW   -1  /* corresponds to the current time */
> > +#define UTIME_OMIT  -2  /* target time is omitted */
> 
> These should be under #ifdef __USE_ATFILE as they are in other bits/stat.h
> files.  These are not "flags".  They are special values for the tv_nsec
> field.  Two spaces after a period.
> 

Done. Please take another look.

Thanks!

diff --git a/sysdeps/mach/hurd/bits/stat.h b/sysdeps/mach/hurd/bits/stat.h
index f60a58a..7f7a124 100644
--- a/sysdeps/mach/hurd/bits/stat.h
+++ b/sysdeps/mach/hurd/bits/stat.h
@@ -246,6 +246,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.  */
diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c
index 4f82f1e..3159cb0 100644
--- a/sysdeps/mach/hurd/futimens.c
+++ b/sysdeps/mach/hurd/futimens.c
@@ -27,24 +27,51 @@
 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
+      /* Setting the number of nanoseconds to UTIME_NOW tells the
          underlying filesystems to use the current time.  */
-      atime.microseconds = mtime.microseconds = -1;
+      atime.tv_sec = 0;
+      atime.tv_nsec = UTIME_NOW;
+      mtime.tv_sec = 0;
+      mtime.tv_nsec = UTIME_NOW;
     }
   else
     {
-      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;
+      atime = tsp[0];
+      mtime = tsp[1];
     }
 
-  err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime));
+  err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime));
+
+  if (err == MIG_BAD_ID || err == EOPNOTSUPP)
+    {
+      time_value_t atim, mtim;
+
+      if (tsp == NULL)
+        /* Setting the number of microseconds to `-1' tells the
+           underlying filesystems to use the current time.  */
+        atim.microseconds = mtim.microseconds = -1;
+      else if (tsp[0].tv_nsec == UTIME_OMIT || tsp[1].tv_nsec == UTIME_OMIT)
+        return EOPNOTSUPP;
+      else
+        {
+          if (tsp[0].tv_nsec == UTIME_NOW)
+            atim.microseconds = -1;
+          else
+            TIMESPEC_TO_TIME_VALUE (&atim, &(tsp[0]));
+          if (tsp[1].tv_nsec == UTIME_NOW)
+            mtim.microseconds = -1;
+          else
+            TIMESPEC_TO_TIME_VALUE (&mtim, &(tsp[1]));
+        }
+
+      err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim));
+  }
+
   return err ? __hurd_dfail (fd, err) : 0;
 }
 weak_alias (__futimens, futimens)
diff --git a/sysdeps/mach/hurd/futimes.c b/sysdeps/mach/hurd/futimes.c
index c325d44..5963151 100644
--- a/sysdeps/mach/hurd/futimes.c
+++ b/sysdeps/mach/hurd/futimes.c
@@ -22,29 +22,29 @@
 #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/lutimes.c b/sysdeps/mach/hurd/lutimes.c
index 260842d..bddc54f 100644
--- a/sysdeps/mach/hurd/lutimes.c
+++ b/sysdeps/mach/hurd/lutimes.c
@@ -22,33 +22,22 @@
 #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_futimens (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
index e69de29..93a556a 100644
--- a/sysdeps/mach/hurd/utime-helper.c
+++ b/sysdeps/mach/hurd/utime-helper.c
@@ -0,0 +1,84 @@
+/* Threshold at which to diagnose ELOOP.  Hurd version.
+   Copyright (C) 2015 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_futimens (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;
+}
diff --git a/sysdeps/mach/hurd/utimes.c b/sysdeps/mach/hurd/utimes.c
index 6739b79..ae1921e 100644
--- a/sysdeps/mach/hurd/utimes.c
+++ b/sysdeps/mach/hurd/utimes.c
@@ -20,6 +20,8 @@
 #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
@@ -27,28 +29,15 @@ __utimes (file, tvp)
      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_futimens (port, tvp);
+
   __mach_port_deallocate (__mach_task_self (), port);
   if (err)
     return __hurd_fail (err);



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC
  2015-11-17 23:19   ` Flavio Cruz
@ 2018-03-06  7:46     ` Samuel Thibault
  0 siblings, 0 replies; 4+ messages in thread
From: Samuel Thibault @ 2018-03-06  7:46 UTC (permalink / raw
  To: Flavio Cruz; +Cc: libc-alpha, bug-hurd

Hello,

I have fixed and completed this a bit and commited.

Thanks!
Samuel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-06  7:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-12 22:30 [PATCH] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC Samuel Thibault
2015-11-09 18:56 ` Roland McGrath
2015-11-17 23:19   ` Flavio Cruz
2018-03-06  7:46     ` Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).