[2/4] generic/wordsize-32: don't duplicate statfs syscalls if not needed
diff mbox

Message ID 1473854559-11103-3-git-send-email-ynorov@caviumnetworks.com
State New
Headers show

Commit Message

Yury Norov Sept. 14, 2016, 12:02 p.m. UTC
If __fsblkcnt_t and __fsfilcnt_t are 64-bit types, struct statfs
is identical to struct statfs64, and therefore 64-bit syscalls may
be reused.

In this patch, syscalls redirected to their 64-bit versions. At now, the
only user of it is aarch64/ilp32 that is under development, but the
patch may be applied separately because it's generic.

2016-09-13: Yury Norov  <ynorov@caviumnetworks.com>

	* sysdeps/unix/sysv/linux/generic/bits/statfs.h: New option
	  __STATFS_IS_STATFS64
	* sysdeps/unix/sysv/linux/fstatfs64.c: declare fstatfs()
	  and symbols, if struct statfs is identical to struct statfs64
	* sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c: don't
	  declare fstatfs() and symbols if struct statfs is identical
	  to struct statfs64
	* sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c: don't
	  declare statfs() and symbols if struct statfs is identical
	  to struct statfs64
	* sysdeps/unix/sysv/linux/statfs64.c: declare statfs() and
	  symbols, if struct statfs is identical to struct statfs64

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 sysdeps/unix/sysv/linux/fstatfs64.c                   |  9 +++++++++
 sysdeps/unix/sysv/linux/generic/bits/statfs.h         | 16 +++++++++++++++-
 sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c |  2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c  |  2 ++
 sysdeps/unix/sysv/linux/statfs64.c                    | 11 ++++++++++-
 5 files changed, 38 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/sysdeps/unix/sysv/linux/fstatfs64.c b/sysdeps/unix/sysv/linux/fstatfs64.c
index a624de6..c6d7fde 100644
--- a/sysdeps/unix/sysv/linux/fstatfs64.c
+++ b/sysdeps/unix/sysv/linux/fstatfs64.c
@@ -15,6 +15,8 @@ 
    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/>.  */
+#define __fstatfs __fstatfs_disabled
+#define fstatfs fstatfs_disabled
 
 #include <errno.h>
 #include <string.h>
@@ -70,3 +72,10 @@  __fstatfs64 (int fd, struct statfs64 *buf)
 #endif
 }
 weak_alias (__fstatfs64, fstatfs64)
+
+#undef __fstatfs
+#undef fstatfs
+#if __STATFS_IS_STATFS64
+weak_alias (__fstatfs64, __fstatfs)
+weak_alias (__fstatfs64, fstatfs)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 7d5aa2d..f8975b8 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -24,6 +24,20 @@ 
 #include <bits/types.h>
 #include <bits/wordsize.h>
 
+#if ((defined (__FSBLKCNT_T_TYPE_MATCHES_FSBLKCNT64_T_TYPE)		\
+  && !defined (__FSFILCNT_T_TYPE_MATCHES_FSFILCNT64_T_TYPE))) ||	\
+    (!defined (__FSBLKCNT_T_TYPE_MATCHES_FSBLKCNT64_T_TYPE)		\
+   && defined (__FSFILCNT_T_TYPE_MATCHES_FSFILCNT64_T_TYPE))
+# error "__fsblkcnt_t and __fsfilcnt_t should both be 32- or 64-bit."
+#endif
+
+#if (defined (__FSBLKCNT_T_TYPE_MATCHES_FSBLKCNT64_T_TYPE) \
+  && defined (__FSFILCNT_T_TYPE_MATCHES_FSFILCNT64_T_TYPE))
+# define __STATFS_IS_STATFS64	1
+#else
+# define __STATFS_IS_STATFS64	0
+#endif
+
 /* 64-bit libc uses the kernel's 'struct statfs', accessed via the
    statfs() syscall; 32-bit libc uses the kernel's 'struct statfs64'
    and accesses it via the statfs64() syscall.  All the various
@@ -34,7 +48,7 @@ 
 
 #if defined __USE_FILE_OFFSET64
 # define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
+#elif __WORDSIZE == 64 || __STATFS_IS_STATFS64
 # define __field64(type, type64, name) type name
 #elif __BYTE_ORDER == __LITTLE_ENDIAN
 # define __field64(type, type64, name) \
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
index be9599a..f8bc6fb 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fstatfs.c
@@ -20,6 +20,7 @@ 
 #include <sys/statfs.h>
 #include <stddef.h>
 
+#if !__STATFS_IS_STATFS64
 #include "overflow.h"
 
 /* Return information about the filesystem on which FD resides.  */
@@ -30,3 +31,4 @@  __fstatfs (int fd, struct statfs *buf)
   return rc ?: statfs_overflow (buf);
 }
 weak_alias (__fstatfs, fstatfs)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
index 1937f05..68c7e4e 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/statfs.c
@@ -20,6 +20,7 @@ 
 #include <sys/statfs.h>
 #include <stddef.h>
 
+#if !__STATFS_IS_STATFS64
 #include "overflow.h"
 
 /* Return information about the filesystem on which FILE resides.  */
@@ -31,3 +32,4 @@  __statfs (const char *file, struct statfs *buf)
 }
 libc_hidden_def (__statfs)
 weak_alias (__statfs, statfs)
+#endif
diff --git a/sysdeps/unix/sysv/linux/statfs64.c b/sysdeps/unix/sysv/linux/statfs64.c
index de42261..c3a86b8 100644
--- a/sysdeps/unix/sysv/linux/statfs64.c
+++ b/sysdeps/unix/sysv/linux/statfs64.c
@@ -15,6 +15,8 @@ 
    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/>.  */
+#define __statfs __statfs_disabled
+#define statfs statfs_disabled
 
 #include <errno.h>
 #include <string.h>
@@ -23,7 +25,6 @@ 
 #include <sysdep.h>
 #include <kernel-features.h>
 
-
 # if __ASSUME_STATFS64 == 0
 int __no_statfs64 attribute_hidden;
 #endif
@@ -72,3 +73,11 @@  __statfs64 (const char *file, struct statfs64 *buf)
 #endif
 }
 weak_alias (__statfs64, statfs64)
+
+#undef __statfs
+#undef statfs
+#if __STATFS_IS_STATFS64
+weak_alias (__statfs64, __statfs)
+weak_alias (__statfs64, statfs)
+libc_hidden_ver (__statfs64, __statfs)
+#endif