about summary refs log tree commit diff
path: root/src/stat/statvfs.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-09-19 23:35:48 -0400
committerRich Felker <dalias@aerifal.cx>2011-09-19 23:35:48 -0400
commit114c80f1416617399c85c2df09dd307532399903 (patch)
tree5168ccc178e9b854385fa23caab3e055ea7a555c /src/stat/statvfs.c
parent8c07f6eac843c2acb217083d48c4cef95f2b891c (diff)
downloadmusl-114c80f1416617399c85c2df09dd307532399903.tar.gz
musl-114c80f1416617399c85c2df09dd307532399903.tar.xz
musl-114c80f1416617399c85c2df09dd307532399903.zip
fix the definition of struct statvfs to match lsb abi
at the same time, make struct statfs match the traditional definition
and make it more useful, especially the fsid_t stuff.
Diffstat (limited to 'src/stat/statvfs.c')
-rw-r--r--src/stat/statvfs.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
index e72c225c..11ad7543 100644
--- a/src/stat/statvfs.c
+++ b/src/stat/statvfs.c
@@ -1,8 +1,9 @@
 #include <sys/statvfs.h>
+#include <sys/statfs.h>
 #include "syscall.h"
 #include "libc.h"
 
-int statvfs(const char *path, struct statvfs *buf)
+int __statfs(const char *path, struct statfs *buf)
 {
 #ifdef SYS_statfs64
 	return syscall(SYS_statfs64, path, sizeof *buf, buf);
@@ -11,7 +12,50 @@ int statvfs(const char *path, struct statvfs *buf)
 #endif
 }
 
-weak_alias(statvfs, statfs);
+int __fstatfs(int fd, struct statfs *buf)
+{
+#ifdef SYS_fstatfs64
+	return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
+#else
+	return syscall(SYS_fstatfs, fd, buf);
+#endif
+}
+
+weak_alias(__statfs, statfs);
+weak_alias(__fstatfs, fstatfs);
+
+static void fixup(struct statvfs *out, const struct statfs *in)
+{
+	out->f_bsize = in->f_bsize;
+	out->f_frsize = in->f_bsize;
+	out->f_blocks = in->f_blocks;
+	out->f_bfree = in->f_bfree;
+	out->f_bavail = in->f_bavail;
+	out->f_files = in->f_files;
+	out->f_ffree = in->f_ffree;
+	out->f_favail = 0;
+	out->f_fsid = in->f_fsid.val[0];
+	out->f_flag = in->f_flags;
+	out->f_namemax = in->f_namelen;
+}
+
+int statvfs(const char *path, struct statvfs *buf)
+{
+	struct statfs kbuf;
+	if (__statfs(path, &kbuf)<0) return -1;
+	fixup(buf, &kbuf);
+	return 0;
+}
+
+int fstatvfs(int fd, struct statvfs *buf)
+{
+	struct statfs kbuf;
+	if (__fstatfs(fd, &kbuf)<0) return -1;
+	fixup(buf, &kbuf);
+	return 0;
+}
 
 LFS64(statvfs);
 LFS64(statfs);
+LFS64(fstatvfs);
+LFS64(fstatfs);