This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struct stat.h with nanosecond resolution


Roland McGrath <roland@redhat.com> writes:

>> It's too much for my taste.
>
> I was gagging too much last night to even write about it. :-)
>
> I think your suggestion is fine.  I'd go for __USE_MISC, there is no harm
> in it and miscellaneous other systems have similar members in struct stat
> (though BSD's are called `st_mtimensec' and the like, no second _).

Ok, I followed this suggestion now.

> Checking the feature-test macros is what BSD's struct stat does now.
> In nonstandard mode they use the names `st_mtimespec' et al rather than
> `st_mtim'.  I am guessing the latter names are used by Solaris or something?

st_mtim is used by Solaris and this is what GNU fileutils checks for.

> I was thinking about ways to avoid the ugliness and nothing fits to avoid
> the macros for the struct timespec type.  You can avoid the st_* macros
> that need to use tv_sec in the rhs with:
>
> struct stat {
>   ...;
>   __extension__ union {
>     struct timespec st_mtim;
>     __extension__ struct {
>       time_t st_mtime;
>       __suseconds_t st_mtime_nsec;
>     };
>   };
> };
>
> But that doesn't really help since `struct timespec' itself must be defined
> using `tv_sec' or else st_mtim cannot be used normally.  

I haven't used this idea - or should I?

Here's an updated patch for x86 only.  If this one is ok, I'll do the
other archs also.

Shall I continue this road?  This patch build and passed the testsuite
on i686-linux-gnu.

Andreas

2002-12-28  Andreas Jaeger  <aj@suse.de>

	* sysdeps/unix/sysv/linux/xstatconv.c (xstat_conv): Adjust for
	nsec resolution changes.
	(xstat64_conv): Likewise.
	(xstat32_conv): Likewise.

	* sysdeps/unix/sysv/linux/kernel_stat.h: Add nsec resolution for
	struct kernel_stat.

	* sysdeps/unix/sysv/linux/bits/stat.h: Add nsec resolution for
	structs stat and stat64.

	* time/time.h (__timespec_defined): Define for __USE_MISC.

	* io/sys/stat.h [__USE_MISC]: Define __need_timespec for struct
	stat.

============================================================
Index: sysdeps/unix/sysv/linux/bits/stat.h
--- sysdeps/unix/sysv/linux/bits/stat.h	8 Feb 2002 07:48:10 -0000	1.15
+++ sysdeps/unix/sysv/linux/bits/stat.h	28 Dec 2002 14:38:47 -0000
@@ -60,12 +60,21 @@ struct stat
 #else
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
 #endif
-    __time_t st_atime;			/* Time of last access.  */
-    unsigned long int __unused1;
+#ifdef __USE_MISC
+    struct timespec st_atim;		/* Time of last access.  */
+    struct timespec st_mtim;		/* Time of last modification.  */
+    struct timespec st_ctim;		/* Time of last status change.  */
+# define st_atime st_atim.tv_sec	/* Backward compatibility.  */
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#else
+    time_t st_atime;			/* Time of last access.  */
+    unsigned long int st_atimensec;	/* Nscecs of last access.  */
     __time_t st_mtime;			/* Time of last modification.  */
-    unsigned long int __unused2;
+    unsigned long int st_mtimensec;	/* Nsecs of last modification.  */
     __time_t st_ctime;			/* Time of last status change.  */
-    unsigned long int __unused3;
+    unsigned long int st_ctimensec;	/* Nsecs of last status change.  */
+#endif
 #ifndef __USE_FILE_OFFSET64
     unsigned long int __unused4;
     unsigned long int __unused5;
@@ -91,12 +100,18 @@ struct stat64
     __blksize_t st_blksize;		/* Optimal block size for I/O.  */
 
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
-    __time_t st_atime;			/* Time of last access.  */
-    unsigned long int __unused1;
+#ifdef __USE_MISC
+    struct timespec st_atim;		/* Time of last access.  */
+    struct timespec st_mtim;		/* Time of last modification.  */
+    struct timespec st_ctim;		/* Time of last status change.  */
+#else
+    time_t st_atime;			/* Time of last access.  */
+    unsigned long int st_atimensec;	/* Nscecs of last access.  */
     __time_t st_mtime;			/* Time of last modification.  */
-    unsigned long int __unused2;
+    unsigned long int st_mtimensec;	/* Nsecs of last modification.  */
     __time_t st_ctime;			/* Time of last status change.  */
-    unsigned long int __unused3;
+    unsigned long int st_ctimensec;	/* Nsecs of last status change.  */
+#endif
     __ino64_t st_ino;			/* File serial number.		*/
   };
 #endif
============================================================
Index: io/sys/stat.h
--- io/sys/stat.h	19 Oct 2002 20:03:44 -0000	1.37
+++ io/sys/stat.h	28 Dec 2002 14:38:47 -0000
@@ -28,6 +28,12 @@
 
 #include <bits/types.h>		/* For __mode_t and __dev_t.  */
 
+#ifdef __USE_MISC
+# define __need_timespec
+/* __USE_MISC implies __USE_XOPEN and therefore <time.h> will get included
+   later.  */
+#endif
+
 #ifdef __USE_XOPEN
 # define __need_time_t
 # include <time.h>		/* For time_t.  */
============================================================
Index: time/time.h
--- time/time.h	28 Aug 2002 08:01:10 -0000	1.66
+++ time/time.h	28 Dec 2002 14:38:47 -0000
@@ -107,8 +107,10 @@ typedef __timer_t timer_t;
 #undef	__need_timer_t
 
 
-#if !defined __timespec_defined && \
-    ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timespec)
+#if !defined __timespec_defined &&				\
+    ((defined _TIME_H &&					\
+      (defined __USE_POSIX199309 || defined __USE_MISC)) ||	\
+      defined __need_timespec)
 # define __timespec_defined	1
 
 /* POSIX.1b structure for a time value.  This is like a `struct timeval' but
============================================================
Index: sysdeps/unix/sysv/linux/xstatconv.c
--- sysdeps/unix/sysv/linux/xstatconv.c	2 Oct 2002 08:33:46 -0000	1.10
+++ sysdeps/unix/sysv/linux/xstatconv.c	28 Dec 2002 14:38:47 -0000
@@ -60,18 +60,12 @@ xstat_conv (int vers, struct kernel_stat
 	buf->st_size = kbuf->st_size;
 	buf->st_blksize = kbuf->st_blksize;
 	buf->st_blocks = kbuf->st_blocks;
-	buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT___UNUSED1
-	buf->__unused1 = 0;
-#endif
-	buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT___UNUSED2
-	buf->__unused2 = 0;
-#endif
-	buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT___UNUSED3
-	buf->__unused3 = 0;
-#endif
+	buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+	buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+	buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+	buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+	buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+	buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
 #ifdef _HAVE_STAT___UNUSED4
 	buf->__unused4 = 0;
 #endif
@@ -121,18 +115,12 @@ xstat64_conv (int vers, struct kernel_st
 	buf->st_size = kbuf->st_size;
 	buf->st_blksize = kbuf->st_blksize;
 	buf->st_blocks = kbuf->st_blocks;
-	buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT64___UNUSED1
-	buf->__unused1 = 0;
-#endif
-	buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT64___UNUSED2
-	buf->__unused2 = 0;
-#endif
-	buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT64___UNUSED3
-	buf->__unused3 = 0;
-#endif
+	buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+	buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+	buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+	buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+	buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+	buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
 #ifdef _HAVE_STAT64___UNUSED4
 	buf->__unused4 = 0;
 #endif
@@ -216,18 +204,12 @@ xstat32_conv (int vers, struct stat64 *k
 	    __set_errno (EOVERFLOW);
 	    return -1;
 	  }
-	buf->st_atime = kbuf->st_atime;
-#ifdef _HAVE_STAT___UNUSED1
-	buf->__unused1 = 0;
-#endif
-	buf->st_mtime = kbuf->st_mtime;
-#ifdef _HAVE_STAT___UNUSED2
-	buf->__unused2 = 0;
-#endif
-	buf->st_ctime = kbuf->st_ctime;
-#ifdef _HAVE_STAT___UNUSED3
-	buf->__unused3 = 0;
-#endif
+	buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
+	buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
+	buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
+	buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
+	buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
+	buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
 #ifdef _HAVE_STAT___UNUSED4
 	buf->__unused4 = 0;
 #endif
============================================================
Index: sysdeps/unix/sysv/linux/kernel_stat.h
--- sysdeps/unix/sysv/linux/kernel_stat.h	12 Aug 2000 04:38:53 -0000	1.4
+++ sysdeps/unix/sysv/linux/kernel_stat.h	28 Dec 2002 14:38:47 -0000
@@ -15,31 +15,19 @@ struct kernel_stat
     unsigned long int st_size;
     unsigned long int st_blksize;
     unsigned long int st_blocks;
-    unsigned long int st_atime;
-    unsigned long int __unused1;
-#define _HAVE___UNUSED1
-    unsigned long int st_mtime;
-    unsigned long int __unused2;
-#define _HAVE___UNUSED2
-    unsigned long int st_ctime;
-    unsigned long int __unused3;
-#define _HAVE___UNUSED3
+    struct timespec st_atim;
+    struct timespec st_mtim;
+    struct timespec st_ctim;
     unsigned long int __unused4;
 #define _HAVE___UNUSED4
     unsigned long int __unused5;
 #define _HAVE___UNUSED5
   };
 
-#define _HAVE_STAT___UNUSED1
-#define _HAVE_STAT___UNUSED2
-#define _HAVE_STAT___UNUSED3
 #define _HAVE_STAT___UNUSED4
 #define _HAVE_STAT___UNUSED5
 #define _HAVE_STAT___PAD1
 #define _HAVE_STAT___PAD2
-#define _HAVE_STAT64___UNUSED1
-#define _HAVE_STAT64___UNUSED2
-#define _HAVE_STAT64___UNUSED3
 #define _HAVE_STAT64___PAD1
 #define _HAVE_STAT64___PAD2
 #define _HAVE_STAT64___ST_INO

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]