[PATCH 36/46] fstatfs: Add __libc_fstatfs wrapper
Markos Chandras
markos.chandras at gmail.com
Tue Nov 13 11:31:45 UTC 2012
From: Markos Chandras <markos.chandras at imgtec.com>
New architectures don't have fstatfs anymore, so we use a wrapper for
__libc_fstatfs which will use fstatfs64 internally. The interface however
needs to remain the same (i.e accepting a struct statfs as a second
argument) for backwards compatibility
Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
libc/sysdeps/linux/common/fstatfs.c | 43 ++++++++++++++++++++++++++++++++++-
1 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/libc/sysdeps/linux/common/fstatfs.c b/libc/sysdeps/linux/common/fstatfs.c
index fa0024a..82efdc9 100644
--- a/libc/sysdeps/linux/common/fstatfs.c
+++ b/libc/sysdeps/linux/common/fstatfs.c
@@ -9,8 +9,9 @@
#include <sys/syscall.h>
#include <sys/vfs.h>
+#include <string.h>
-#ifndef __USE_FILE_OFFSET64
+#if ! defined(__USE_FILE_OFFSET64)
extern int fstatfs (int __fildes, struct statfs *__buf)
__THROW __nonnull ((2));
#else
@@ -23,8 +24,48 @@ extern int __REDIRECT_NTH (fstatfs, (int __fildes, struct statfs *__buf),
#endif
extern __typeof(fstatfs) __libc_fstatfs attribute_hidden;
+#ifdef __NR_fstatfs
#define __NR___libc_fstatfs __NR_fstatfs
_syscall2(int, __libc_fstatfs, int, fd, struct statfs *, buf)
+#else
+/* Backwards compatibility for __libc_fstatfs */
+int __libc_fstatfs (int __fildes, struct statfs *__buf)
+{
+ struct statfs64 b;
+ int err;
+
+ /*
+ * Check if __buf has a sane value.
+ * This does not prevent the user from passing
+ * an artitrary possitive value that can lead to
+ * segfault or other security problems
+ */
+ if ( __buf == NULL || (int)__buf < 0) {
+ __set_errno(EFAULT);
+ return -1;
+ }
+
+ err = INLINE_SYSCALL(fstatfs64, 3, __fildes, sizeof(b), &b);
+
+ if (err < 0)
+ return -1;
+
+ memset(__buf, 0x00, sizeof(*__buf));
+ __buf->f_type = b.f_type;
+ __buf->f_bsize = b.f_bsize;
+ __buf->f_blocks = b.f_blocks;
+ __buf->f_bfree = b.f_bfree;
+ __buf->f_bavail = b.f_bavail;
+ __buf->f_files = b.f_files;
+ __buf->f_ffree = b.f_ffree;
+ __buf->f_namelen = b.f_namelen;
+ __buf->f_frsize = b.f_frsize;
+ __buf->f_fsid = b.f_fsid;
+ memcpy(__buf->f_spare, b.f_spare, sizeof(b.f_spare));
+ return err;
+};
+/* Redefined fstatfs because we need it for backwards compatibility */
+#endif /* __NR_fstatfs */
#if defined __UCLIBC_LINUX_SPECIFIC__
weak_alias(__libc_fstatfs,fstatfs)
--
1.7.1
More information about the uClibc
mailing list