bdc76f
commit 5dad6ffbb2b76215cfcd38c3001778536ada8e8a
bdc76f
Author: Florian Weimer <fweimer@redhat.com>
bdc76f
Date:   Wed Jun 12 12:04:09 2019 +0200
bdc76f
bdc76f
    <sys/stat.h>: Use Linux UAPI header for statx if available and useful
bdc76f
    
bdc76f
    This will automatically import new STATX_* constants.  It also avoids
bdc76f
    a conflict between <sys/stat.h> and <linux/stat.h>.
bdc76f
bdc76f
Conflicts:
bdc76f
	io/bits/statx.h
bdc76f
	  (Year range in copyright header.)
bdc76f
bdc76f
diff --git a/include/bits/statx-generic.h b/include/bits/statx-generic.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..21674721b6d85265
bdc76f
--- /dev/null
bdc76f
+++ b/include/bits/statx-generic.h
bdc76f
@@ -0,0 +1 @@
bdc76f
+#include <io/bits/statx-generic.h>
bdc76f
diff --git a/include/bits/types/struct_statx.h b/include/bits/types/struct_statx.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..82add6484f2ee963
bdc76f
--- /dev/null
bdc76f
+++ b/include/bits/types/struct_statx.h
bdc76f
@@ -0,0 +1 @@
bdc76f
+#include <io/bits/types/struct_statx.h>
bdc76f
diff --git a/include/bits/types/struct_statx_timestamp.h b/include/bits/types/struct_statx_timestamp.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..9fbedd5749fc1172
bdc76f
--- /dev/null
bdc76f
+++ b/include/bits/types/struct_statx_timestamp.h
bdc76f
@@ -0,0 +1 @@
bdc76f
+#include <io/bits/types/struct_statx_timestamp.h>
bdc76f
diff --git a/io/Makefile b/io/Makefile
bdc76f
index ec5c6d7a2fb87914..787a5c550ab64b17 100644
bdc76f
--- a/io/Makefile
bdc76f
+++ b/io/Makefile
bdc76f
@@ -25,7 +25,9 @@ include ../Makeconfig
bdc76f
 headers := sys/stat.h bits/stat.h sys/statfs.h bits/statfs.h sys/vfs.h \
bdc76f
 	   sys/statvfs.h bits/statvfs.h fcntl.h sys/fcntl.h bits/fcntl.h \
bdc76f
 	   poll.h sys/poll.h bits/poll.h bits/fcntl2.h bits/poll2.h \
bdc76f
-	   bits/statx.h utime.h ftw.h fts.h sys/sendfile.h
bdc76f
+	   bits/statx.h bits/statx-generic.h bits/types/struct_statx.h \
bdc76f
+	   bits/types/struct_statx_timestamp.h \
bdc76f
+	   utime.h ftw.h fts.h sys/sendfile.h
bdc76f
 
bdc76f
 routines :=								\
bdc76f
 	utime								\
bdc76f
diff --git a/io/bits/statx-generic.h b/io/bits/statx-generic.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..1f5abbf148681e9b
bdc76f
--- /dev/null
bdc76f
+++ b/io/bits/statx-generic.h
bdc76f
@@ -0,0 +1,60 @@
bdc76f
+/* Generic statx-related definitions and declarations.
bdc76f
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+/* This interface is based on <linux/stat.h> in Linux.  */
bdc76f
+
bdc76f
+#ifndef _SYS_STAT_H
bdc76f
+# error Never include <bits/statx-generic.h> directly, include <sys/stat.h> instead.
bdc76f
+#endif
bdc76f
+
bdc76f
+#include <bits/types/struct_statx_timestamp.h>
bdc76f
+#include <bits/types/struct_statx.h>
bdc76f
+
bdc76f
+#ifndef STATX_TYPE
bdc76f
+# define STATX_TYPE 0x0001U
bdc76f
+# define STATX_MODE 0x0002U
bdc76f
+# define STATX_NLINK 0x0004U
bdc76f
+# define STATX_UID 0x0008U
bdc76f
+# define STATX_GID 0x0010U
bdc76f
+# define STATX_ATIME 0x0020U
bdc76f
+# define STATX_MTIME 0x0040U
bdc76f
+# define STATX_CTIME 0x0080U
bdc76f
+# define STATX_INO 0x0100U
bdc76f
+# define STATX_SIZE 0x0200U
bdc76f
+# define STATX_BLOCKS 0x0400U
bdc76f
+# define STATX_BASIC_STATS 0x07ffU
bdc76f
+# define STATX_ALL 0x0fffU
bdc76f
+# define STATX_BTIME 0x0800U
bdc76f
+# define STATX__RESERVED 0x80000000U
bdc76f
+
bdc76f
+# define STATX_ATTR_COMPRESSED 0x0004
bdc76f
+# define STATX_ATTR_IMMUTABLE 0x0010
bdc76f
+# define STATX_ATTR_APPEND 0x0020
bdc76f
+# define STATX_ATTR_NODUMP 0x0040
bdc76f
+# define STATX_ATTR_ENCRYPTED 0x0800
bdc76f
+# define STATX_ATTR_AUTOMOUNT 0x1000
bdc76f
+#endif /* !STATX_TYPE */
bdc76f
+
bdc76f
+__BEGIN_DECLS
bdc76f
+
bdc76f
+/* Fill *BUF with information about PATH in DIRFD.  */
bdc76f
+int statx (int __dirfd, const char *__restrict __path, int __flags,
bdc76f
+           unsigned int __mask, struct statx *__restrict __buf)
bdc76f
+  __THROW __nonnull ((2, 5));
bdc76f
+
bdc76f
+__END_DECLS
bdc76f
diff --git a/io/bits/statx.h b/io/bits/statx.h
bdc76f
index e31254e3617bb17b..b3147bfa8af1818f 100644
bdc76f
--- a/io/bits/statx.h
bdc76f
+++ b/io/bits/statx.h
bdc76f
@@ -1,5 +1,5 @@
bdc76f
-/* statx-related definitions and declarations.
bdc76f
-   Copyright (C) 2018 Free Software Foundation, Inc.
bdc76f
+/* statx-related definitions and declarations.  Generic version.
bdc76f
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
bdc76f
    This file is part of the GNU C Library.
bdc76f
 
bdc76f
    The GNU C Library is free software; you can redistribute it and/or
bdc76f
@@ -19,73 +19,8 @@
bdc76f
 /* This interface is based on <linux/stat.h> in Linux.  */
bdc76f
 
bdc76f
 #ifndef _SYS_STAT_H
bdc76f
-# error Never include <bits/stat.x.h> directly, include <sys/stat.h> instead.
bdc76f
+# error Never include <bits/statx.h> directly, include <sys/stat.h> instead.
bdc76f
 #endif
bdc76f
 
bdc76f
-struct statx_timestamp
bdc76f
-{
bdc76f
-  __int64_t tv_sec;
bdc76f
-  __uint32_t tv_nsec;
bdc76f
-  __int32_t __statx_timestamp_pad1[1];
bdc76f
-};
bdc76f
-
bdc76f
-/* Warning: The kernel may add additional fields to this struct in the
bdc76f
-   future.  Only use this struct for calling the statx function, not
bdc76f
-   for storing data.  (Expansion will be controlled by the mask
bdc76f
-   argument of the statx function.)  */
bdc76f
-struct statx
bdc76f
-{
bdc76f
-  __uint32_t stx_mask;
bdc76f
-  __uint32_t stx_blksize;
bdc76f
-  __uint64_t stx_attributes;
bdc76f
-  __uint32_t stx_nlink;
bdc76f
-  __uint32_t stx_uid;
bdc76f
-  __uint32_t stx_gid;
bdc76f
-  __uint16_t stx_mode;
bdc76f
-  __uint16_t __statx_pad1[1];
bdc76f
-  __uint64_t stx_ino;
bdc76f
-  __uint64_t stx_size;
bdc76f
-  __uint64_t stx_blocks;
bdc76f
-  __uint64_t stx_attributes_mask;
bdc76f
-  struct statx_timestamp stx_atime;
bdc76f
-  struct statx_timestamp stx_btime;
bdc76f
-  struct statx_timestamp stx_ctime;
bdc76f
-  struct statx_timestamp stx_mtime;
bdc76f
-  __uint32_t stx_rdev_major;
bdc76f
-  __uint32_t stx_rdev_minor;
bdc76f
-  __uint32_t stx_dev_major;
bdc76f
-  __uint32_t stx_dev_minor;
bdc76f
-  __uint64_t __statx_pad2[14];
bdc76f
-};
bdc76f
-
bdc76f
-#define STATX_TYPE 0x0001U
bdc76f
-#define STATX_MODE 0x0002U
bdc76f
-#define STATX_NLINK 0x0004U
bdc76f
-#define STATX_UID 0x0008U
bdc76f
-#define STATX_GID 0x0010U
bdc76f
-#define STATX_ATIME 0x0020U
bdc76f
-#define STATX_MTIME 0x0040U
bdc76f
-#define STATX_CTIME 0x0080U
bdc76f
-#define STATX_INO 0x0100U
bdc76f
-#define STATX_SIZE 0x0200U
bdc76f
-#define STATX_BLOCKS 0x0400U
bdc76f
-#define STATX_BASIC_STATS 0x07ffU
bdc76f
-#define STATX_ALL 0x0fffU
bdc76f
-#define STATX_BTIME 0x0800U
bdc76f
-#define STATX__RESERVED 0x80000000U
bdc76f
-
bdc76f
-#define STATX_ATTR_COMPRESSED 0x0004
bdc76f
-#define STATX_ATTR_IMMUTABLE 0x0010
bdc76f
-#define STATX_ATTR_APPEND 0x0020
bdc76f
-#define STATX_ATTR_NODUMP 0x0040
bdc76f
-#define STATX_ATTR_ENCRYPTED 0x0800
bdc76f
-#define STATX_ATTR_AUTOMOUNT 0x1000
bdc76f
-
bdc76f
-__BEGIN_DECLS
bdc76f
-
bdc76f
-/* Fill *BUF with information about PATH in DIRFD.  */
bdc76f
-int statx (int __dirfd, const char *__restrict __path, int __flags,
bdc76f
-           unsigned int __mask, struct statx *__restrict __buf)
bdc76f
-  __THROW __nonnull ((2, 5));
bdc76f
-
bdc76f
-__END_DECLS
bdc76f
+/* Use the generic definitions.  */
bdc76f
+#include <bits/statx-generic.h>
bdc76f
diff --git a/io/bits/types/struct_statx.h b/io/bits/types/struct_statx.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..4f3ae3ece62a0ad2
bdc76f
--- /dev/null
bdc76f
+++ b/io/bits/types/struct_statx.h
bdc76f
@@ -0,0 +1,55 @@
bdc76f
+/* Definition of the generic version of struct statx.
bdc76f
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+#ifndef _SYS_STAT_H
bdc76f
+# error Never include <bits/types/struct_statx.h> directly, include <sys/stat.h> instead.
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifndef __statx_defined
bdc76f
+#define __statx_defined 1
bdc76f
+
bdc76f
+/* Warning: The kernel may add additional fields to this struct in the
bdc76f
+   future.  Only use this struct for calling the statx function, not
bdc76f
+   for storing data.  (Expansion will be controlled by the mask
bdc76f
+   argument of the statx function.)  */
bdc76f
+struct statx
bdc76f
+{
bdc76f
+  __uint32_t stx_mask;
bdc76f
+  __uint32_t stx_blksize;
bdc76f
+  __uint64_t stx_attributes;
bdc76f
+  __uint32_t stx_nlink;
bdc76f
+  __uint32_t stx_uid;
bdc76f
+  __uint32_t stx_gid;
bdc76f
+  __uint16_t stx_mode;
bdc76f
+  __uint16_t __statx_pad1[1];
bdc76f
+  __uint64_t stx_ino;
bdc76f
+  __uint64_t stx_size;
bdc76f
+  __uint64_t stx_blocks;
bdc76f
+  __uint64_t stx_attributes_mask;
bdc76f
+  struct statx_timestamp stx_atime;
bdc76f
+  struct statx_timestamp stx_btime;
bdc76f
+  struct statx_timestamp stx_ctime;
bdc76f
+  struct statx_timestamp stx_mtime;
bdc76f
+  __uint32_t stx_rdev_major;
bdc76f
+  __uint32_t stx_rdev_minor;
bdc76f
+  __uint32_t stx_dev_major;
bdc76f
+  __uint32_t stx_dev_minor;
bdc76f
+  __uint64_t __statx_pad2[14];
bdc76f
+};
bdc76f
+
bdc76f
+#endif /* __statx_defined */
bdc76f
diff --git a/io/bits/types/struct_statx_timestamp.h b/io/bits/types/struct_statx_timestamp.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..0f104ef84ed7d356
bdc76f
--- /dev/null
bdc76f
+++ b/io/bits/types/struct_statx_timestamp.h
bdc76f
@@ -0,0 +1,33 @@
bdc76f
+/* Definition of the generic version of struct statx_timestamp.
bdc76f
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+#ifndef _SYS_STAT_H
bdc76f
+# error Never include <bits/types/struct_statx_timestamp.h> directly, include <sys/stat.h> instead.
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifndef __statx_timestamp_defined
bdc76f
+#define __statx_timestamp_defined 1
bdc76f
+
bdc76f
+struct statx_timestamp
bdc76f
+{
bdc76f
+  __int64_t tv_sec;
bdc76f
+  __uint32_t tv_nsec;
bdc76f
+  __int32_t __statx_timestamp_pad1[1];
bdc76f
+};
bdc76f
+
bdc76f
+#endif /* __statx_timestamp_defined */
bdc76f
diff --git a/io/statx_generic.c b/io/statx_generic.c
bdc76f
index df327f8c525f748c..987c84fb45f5db63 100644
bdc76f
--- a/io/statx_generic.c
bdc76f
+++ b/io/statx_generic.c
bdc76f
@@ -18,9 +18,16 @@
bdc76f
 
bdc76f
 #include <errno.h>
bdc76f
 #include <fcntl.h>
bdc76f
+#include <string.h>
bdc76f
 #include <sys/stat.h>
bdc76f
 #include <sys/sysmacros.h>
bdc76f
 
bdc76f
+/* Obtain the original definition of struct statx.  */
bdc76f
+#undef __statx_defined
bdc76f
+#define statx original_statx
bdc76f
+#include <bits/types/struct_statx.h>
bdc76f
+#undef statx
bdc76f
+
bdc76f
 static inline struct statx_timestamp
bdc76f
 statx_convert_timestamp (struct timespec tv)
bdc76f
 {
bdc76f
@@ -57,7 +64,7 @@ statx_generic (int fd, const char *path, int flags,
bdc76f
   /* The interface is defined in such a way that unused (padding)
bdc76f
      fields have to be cleared.  STATX_BASIC_STATS corresponds to the
bdc76f
      data which is available via fstatat64.  */
bdc76f
-  *buf = (struct statx)
bdc76f
+  struct original_statx obuf =
bdc76f
     {
bdc76f
       .stx_mask = STATX_BASIC_STATS,
bdc76f
       .stx_blksize = st.st_blksize,
bdc76f
@@ -76,6 +83,8 @@ statx_generic (int fd, const char *path, int flags,
bdc76f
       .stx_dev_major = major (st.st_dev),
bdc76f
       .stx_dev_minor = minor (st.st_dev),
bdc76f
     };
bdc76f
+  _Static_assert (sizeof (*buf) >= sizeof (obuf), "struct statx size");
bdc76f
+  memcpy (buf, &obuf, sizeof (obuf));
bdc76f
 
bdc76f
   return 0;
bdc76f
 }
bdc76f
diff --git a/sysdeps/unix/sysv/linux/bits/statx.h b/sysdeps/unix/sysv/linux/bits/statx.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..d36f44efc60a0bed
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/unix/sysv/linux/bits/statx.h
bdc76f
@@ -0,0 +1,34 @@
bdc76f
+/* statx-related definitions and declarations.  Linux version.
bdc76f
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+/* This interface is based on <linux/stat.h> in Linux.  */
bdc76f
+
bdc76f
+#ifndef _SYS_STAT_H
bdc76f
+# error Never include <bits/statx.h> directly, include <sys/stat.h> instead.
bdc76f
+#endif
bdc76f
+
bdc76f
+/* Use the Linux kernel header if available.  */
bdc76f
+#if __glibc_has_include (<linux/stat.h>)
bdc76f
+# include <linux/stat.h>
bdc76f
+# ifdef STATX_TYPE
bdc76f
+#  define __statx_timestamp_defined 1
bdc76f
+#  define __statx_defined 1
bdc76f
+# endif
bdc76f
+#endif
bdc76f
+
bdc76f
+#include <bits/statx-generic.h>