fix the definition of struct statvfs to match lsb abi
authorRich Felker <dalias@aerifal.cx>
Tue, 20 Sep 2011 03:35:48 +0000 (23:35 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 20 Sep 2011 03:35:48 +0000 (23:35 -0400)
at the same time, make struct statfs match the traditional definition
and make it more useful, especially the fsid_t stuff.

arch/arm/bits/statfs.h
arch/i386/bits/statfs.h
arch/x86_64/bits/statfs.h
include/sys/statfs.h
include/sys/statvfs.h
src/stat/fstatvfs.c [deleted file]
src/stat/statvfs.c

index 9dda440..f103f4e 100644 (file)
@@ -1,16 +1,7 @@
-struct statvfs {
-       unsigned long f_type;
-       unsigned long f_bsize;
-       fsblkcnt_t f_blocks;
-       fsblkcnt_t f_bfree;
-       fsblkcnt_t f_bavail;
-       fsfilcnt_t f_files;
-       fsfilcnt_t f_ffree;
-       unsigned long f_fsid;
-       unsigned long __unused;
-       unsigned long f_namemax;
-       unsigned long f_frsize;
-       fsfilcnt_t f_favail;
-       unsigned long f_flag;
-       unsigned long __reserved[2];
+struct statfs {
+       unsigned long f_type, f_bsize;
+       fsblkcnt_t f_blocks, f_bfree, f_bavail;
+       fsfilcnt_t f_files, f_ffree;
+       fsid_t f_fsid;
+       unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
 };
 };
index 9dda440..f103f4e 100644 (file)
@@ -1,16 +1,7 @@
-struct statvfs {
-       unsigned long f_type;
-       unsigned long f_bsize;
-       fsblkcnt_t f_blocks;
-       fsblkcnt_t f_bfree;
-       fsblkcnt_t f_bavail;
-       fsfilcnt_t f_files;
-       fsfilcnt_t f_ffree;
-       unsigned long f_fsid;
-       unsigned long __unused;
-       unsigned long f_namemax;
-       unsigned long f_frsize;
-       fsfilcnt_t f_favail;
-       unsigned long f_flag;
-       unsigned long __reserved[2];
+struct statfs {
+       unsigned long f_type, f_bsize;
+       fsblkcnt_t f_blocks, f_bfree, f_bavail;
+       fsfilcnt_t f_files, f_ffree;
+       fsid_t f_fsid;
+       unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
 };
 };
index 63de75b..f103f4e 100644 (file)
@@ -1,15 +1,7 @@
-struct statvfs {
-       unsigned long f_type;
-       unsigned long f_bsize;
-       fsblkcnt_t f_blocks;
-       fsblkcnt_t f_bfree;
-       fsblkcnt_t f_bavail;
-       fsfilcnt_t f_files;
-       fsfilcnt_t f_ffree;
-       unsigned long f_fsid;
-       unsigned long f_namemax;
-       unsigned long f_frsize;
-       fsfilcnt_t f_favail;
-       unsigned long f_flag;
-       unsigned long __reserved[3];
+struct statfs {
+       unsigned long f_type, f_bsize;
+       fsblkcnt_t f_blocks, f_bfree, f_bavail;
+       fsfilcnt_t f_files, f_ffree;
+       fsid_t f_fsid;
+       unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
 };
 };
index 7eaa7e7..51ef30a 100644 (file)
@@ -3,8 +3,13 @@
 
 #include <sys/statvfs.h>
 
 
 #include <sys/statvfs.h>
 
-#define statfs statvfs
-#define fstatfs fstatvfs
-#define f_namelen f_namemax
+typedef struct {
+       int val[2];
+} fsid_t;
+
+#include <bits/statfs.h>
+
+int statfs (const char *, struct statfs *);
+int fstatfs (int, struct statfs *);
 
 #endif
 
 #endif
index 6479be6..fd22fab 100644 (file)
@@ -6,15 +6,28 @@
 #define __NEED_fsfilcnt_t
 #include <bits/alltypes.h>
 
 #define __NEED_fsfilcnt_t
 #include <bits/alltypes.h>
 
-#include <bits/statfs.h>
+#include <endian.h>
+
+struct statvfs {
+       unsigned long f_bsize, f_frsize;
+       fsblkcnt_t f_blocks, f_bfree, f_bavail;
+       fsfilcnt_t f_files, f_ffree, f_favail;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+       unsigned long f_fsid;
+       unsigned :8*(2*sizeof(int)-sizeof(long));
+#else
+       unsigned :8*(2*sizeof(int)-sizeof(long));
+       unsigned long f_fsid;
+#endif
+       unsigned long f_flag, f_namemax;
+       int __reserved[6];
+};
 
 int statvfs (const char *, struct statvfs *);
 int fstatvfs (int, struct statvfs *);
 
 #define ST_RDONLY 1
 #define ST_NOSUID 2
 
 int statvfs (const char *, struct statvfs *);
 int fstatvfs (int, struct statvfs *);
 
 #define ST_RDONLY 1
 #define ST_NOSUID 2
-
-#if 0
 #define ST_NODEV  4
 #define ST_NOEXEC 8
 #define ST_SYNCHRONOUS 16
 #define ST_NODEV  4
 #define ST_NOEXEC 8
 #define ST_SYNCHRONOUS 16
@@ -24,7 +37,6 @@ int fstatvfs (int, struct statvfs *);
 #define ST_IMMUTABLE   512
 #define ST_NOATIME     1024
 #define ST_NODIRATIME  2048
 #define ST_IMMUTABLE   512
 #define ST_NOATIME     1024
 #define ST_NODIRATIME  2048
-#endif
 
 
 #endif
 
 
 #endif
diff --git a/src/stat/fstatvfs.c b/src/stat/fstatvfs.c
deleted file mode 100644 (file)
index 806c3fd..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <sys/statvfs.h>
-#include "syscall.h"
-#include "libc.h"
-
-int fstatvfs(int fd, struct statvfs *buf)
-{
-#ifdef SYS_fstatfs64
-       return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
-#else
-       return syscall(SYS_fstatfs, fd, buf);
-#endif
-}
-
-weak_alias(fstatvfs, fstatfs);
-
-LFS64(fstatvfs);
-LFS64(fstatfs);
index e72c225..11ad754 100644 (file)
@@ -1,8 +1,9 @@
 #include <sys/statvfs.h>
 #include <sys/statvfs.h>
+#include <sys/statfs.h>
 #include "syscall.h"
 #include "libc.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);
 {
 #ifdef SYS_statfs64
        return syscall(SYS_statfs64, path, sizeof *buf, buf);
@@ -11,7 +12,50 @@ int statvfs(const char *path, struct statvfs *buf)
 #endif
 }
 
 #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(statvfs);
 LFS64(statfs);
+LFS64(fstatvfs);
+LFS64(fstatfs);