X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstat%2Fstatvfs.c;h=f65d1b548d41eae429223ddca818b3a71ba8d6b7;hb=3b7b4155570b4b9054465785be2992c92cb7d7b1;hp=e72c225c74aa98ecb5cc0038904019856ec7e7de;hpb=fc0cf2852d1c1254a0e6ab25018f02b325eadf43;p=musl diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c index e72c225c..f65d1b54 100644 --- a/src/stat/statvfs.c +++ b/src/stat/statvfs.c @@ -1,9 +1,10 @@ #include +#include #include "syscall.h" -#include "libc.h" -int statvfs(const char *path, struct statvfs *buf) +static int __statfs(const char *path, struct statfs *buf) { + *buf = (struct statfs){0}; #ifdef SYS_statfs64 return syscall(SYS_statfs64, path, sizeof *buf, buf); #else @@ -11,7 +12,52 @@ int statvfs(const char *path, struct statvfs *buf) #endif } -weak_alias(statvfs, statfs); +static int __fstatfs(int fd, struct statfs *buf) +{ + *buf = (struct statfs){0}; +#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 = (struct statvfs){0}; + out->f_bsize = in->f_bsize; + out->f_frsize = in->f_frsize ? in->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 = in->f_ffree; + out->f_fsid = in->f_fsid.__val[0]; + out->f_flag = in->f_flags; + out->f_namemax = in->f_namelen; +} + +int statvfs(const char *restrict path, struct statvfs *restrict 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); +weak_alias(statvfs, statvfs64); +weak_alias(statfs, statfs64); +weak_alias(fstatvfs, fstatvfs64); +weak_alias(fstatfs, fstatfs64);