[PATCH v2 38/46] fstatfs64: Prefer fstatfs64 system call instead of __libc_fstatfs

Markos Chandras markos.chandras at gmail.com
Mon Nov 26 14:24:20 UTC 2012


From: Markos Chandras <markos.chandras at imgtec.com>

Using __libc_fstatfs for fstatfs64 adds a small delay as it needs to
use a 32-bit data structure to get the file info and them pass them to
the 64-bit data structure which was given as a fstatfs64 argument. Using
the system call directly should make the entire process much faster.
Also fix the arguments for fstatfs64. It takes three arguments
(see fs/fstatfs.c in Linux kernel sources) so despite what the manpage
says, the size of the buffer needs to be passed as the second argument

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 libc/misc/statfs/fstatfs64.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libc/misc/statfs/fstatfs64.c b/libc/misc/statfs/fstatfs64.c
index 27bb8d6..0cb710f 100644
--- a/libc/misc/statfs/fstatfs64.c
+++ b/libc/misc/statfs/fstatfs64.c
@@ -23,8 +23,10 @@
 #include <string.h>
 #include <sys/statfs.h>
 #include <sys/statvfs.h>
+#include <sys/syscall.h>
 #include <stddef.h>
 
+#if defined(__NR_fstatfs)
 extern __typeof(fstatfs) __libc_fstatfs;
 
 /* Return information about the filesystem on which FD resides.  */
@@ -48,4 +50,16 @@ int fstatfs64 (int fd, struct statfs64 *buf)
 
     return 0;
 }
+#else
+/*
+ * Use the fstatfs64 system call if fstatfs is not defined
+ * This is for backwards compatibility and it should be
+ * made default in the future
+ */
+int fstatfs64(int fd, struct statfs64 *buf)
+{
+	/* Signature has 2 arguments but syscalls wants 3 */
+	return INLINE_SYSCALL(fstatfs64, 3, fd, sizeof(*buf), buf);
+}
+#endif
 libc_hidden_def(fstatfs64)
-- 
1.8.0




More information about the uClibc mailing list