提交 114c80f1 编写于 作者: R Rich Felker

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.
上级 8c07f6ea
struct statvfs { struct statfs {
unsigned long f_type; unsigned long f_type, f_bsize;
unsigned long f_bsize; fsblkcnt_t f_blocks, f_bfree, f_bavail;
fsblkcnt_t f_blocks; fsfilcnt_t f_files, f_ffree;
fsblkcnt_t f_bfree; fsid_t f_fsid;
fsblkcnt_t f_bavail; unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
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 statvfs { struct statfs {
unsigned long f_type; unsigned long f_type, f_bsize;
unsigned long f_bsize; fsblkcnt_t f_blocks, f_bfree, f_bavail;
fsblkcnt_t f_blocks; fsfilcnt_t f_files, f_ffree;
fsblkcnt_t f_bfree; fsid_t f_fsid;
fsblkcnt_t f_bavail; unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
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 statvfs { struct statfs {
unsigned long f_type; unsigned long f_type, f_bsize;
unsigned long f_bsize; fsblkcnt_t f_blocks, f_bfree, f_bavail;
fsblkcnt_t f_blocks; fsfilcnt_t f_files, f_ffree;
fsblkcnt_t f_bfree; fsid_t f_fsid;
fsblkcnt_t f_bavail; unsigned long f_namelen, f_frsize, f_flags, f_spare[4];
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];
}; };
...@@ -3,8 +3,13 @@ ...@@ -3,8 +3,13 @@
#include <sys/statvfs.h> #include <sys/statvfs.h>
#define statfs statvfs typedef struct {
#define fstatfs fstatvfs int val[2];
#define f_namelen f_namemax } fsid_t;
#include <bits/statfs.h>
int statfs (const char *, struct statfs *);
int fstatfs (int, struct statfs *);
#endif #endif
...@@ -6,15 +6,28 @@ ...@@ -6,15 +6,28 @@
#define __NEED_fsfilcnt_t #define __NEED_fsfilcnt_t
#include <bits/alltypes.h> #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 statvfs (const char *, struct statvfs *);
int fstatvfs (int, struct statvfs *); int fstatvfs (int, struct statvfs *);
#define ST_RDONLY 1 #define ST_RDONLY 1
#define ST_NOSUID 2 #define ST_NOSUID 2
#if 0
#define ST_NODEV 4 #define ST_NODEV 4
#define ST_NOEXEC 8 #define ST_NOEXEC 8
#define ST_SYNCHRONOUS 16 #define ST_SYNCHRONOUS 16
...@@ -24,7 +37,6 @@ int fstatvfs (int, struct statvfs *); ...@@ -24,7 +37,6 @@ int fstatvfs (int, struct statvfs *);
#define ST_IMMUTABLE 512 #define ST_IMMUTABLE 512
#define ST_NOATIME 1024 #define ST_NOATIME 1024
#define ST_NODIRATIME 2048 #define ST_NODIRATIME 2048
#endif
#endif #endif
#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);
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include <sys/statfs.h>
#include "syscall.h" #include "syscall.h"
#include "libc.h" #include "libc.h"
int statvfs(const char *path, struct statvfs *buf) int __statfs(const char *path, struct statfs *buf)
{ {
#ifdef SYS_statfs64 #ifdef SYS_statfs64
return syscall(SYS_statfs64, path, sizeof *buf, buf); return syscall(SYS_statfs64, path, sizeof *buf, buf);
...@@ -11,7 +12,50 @@ int statvfs(const char *path, struct statvfs *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(statvfs);
LFS64(statfs); LFS64(statfs);
LFS64(fstatvfs);
LFS64(fstatfs);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册