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


Ulrich Drepper <drepper@redhat.com> writes:

> The patch looks mostly OK.  I don't like the transparent union thing
> very much.  Let's keep it simple.
>
> =====================
>> 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.  */
>
> Why is the type changed to time_t?  It should remain __time_t.  See the

A typo :-(

> other fields, they are not changed.

I agree.


> The struct definitions should also contain a comment explaining this
> ugly hack.  There are people out there who compile their sources with
> the POSIX options only enabled.  If this code gets reused in a
> _GNU_SOURCE context or so it might be a surprise that it fails.

What do you think about the appended comment?  Or what have you had in
mind?

Ok now?

Andreas

============================================================
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	29 Dec 2002 16:57:30 -0000
@@ -60,12 +60,26 @@ struct stat
 #else
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
 #endif
+#ifdef __USE_MISC
+    /* For nanosecond resolution OSes changed st_atime to a struct
+       timespec.  This change cannot be done for POSIX since it would
+       violate the namespace rules and is therefore only available as
+       an extension.  It is advised to use struct timespec instead of
+       st_atime and st_atimensec.  */       
+    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 __unused1;
+    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 +105,23 @@ struct stat64
     __blksize_t st_blksize;		/* Optimal block size for I/O.  */
 
     __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
+#ifdef __USE_MISC
+    /* For nanosecond resolution OSes changed st_atime to a struct
+       timespec.  This change cannot be done for POSIX since it would
+       violate the namespace rules and is therefore only available as
+       an extension.  It is advised to use struct timespec instead of
+       st_atime and st_atimensec.  */       
+    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 __unused1;
+    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	29 Dec 2002 16:57:30 -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	29 Dec 2002 16:57:30 -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	29 Dec 2002 16:57:30 -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	29 Dec 2002 16:57:30 -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]