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