1 #include <sys/statvfs.h>
2 #include <sys/statfs.h>
6 static int __statfs(const char *path
, struct statfs
*buf
)
8 *buf
= (struct statfs
){0};
10 return syscall(SYS_statfs64
, path
, sizeof *buf
, buf
);
12 return syscall(SYS_statfs
, path
, buf
);
16 static int __fstatfs(int fd
, struct statfs
*buf
)
18 *buf
= (struct statfs
){0};
20 return syscall(SYS_fstatfs64
, fd
, sizeof *buf
, buf
);
22 return syscall(SYS_fstatfs
, fd
, buf
);
26 weak_alias(__statfs
, statfs
);
27 weak_alias(__fstatfs
, fstatfs
);
29 static void fixup(struct statvfs
*out
, const struct statfs
*in
)
31 *out
= (struct statvfs
){0};
32 out
->f_bsize
= in
->f_bsize
;
33 out
->f_frsize
= in
->f_frsize
? in
->f_frsize
: in
->f_bsize
;
34 out
->f_blocks
= in
->f_blocks
;
35 out
->f_bfree
= in
->f_bfree
;
36 out
->f_bavail
= in
->f_bavail
;
37 out
->f_files
= in
->f_files
;
38 out
->f_ffree
= in
->f_ffree
;
39 out
->f_favail
= in
->f_ffree
;
40 out
->f_fsid
= in
->f_fsid
.__val
[0];
41 out
->f_flag
= in
->f_flags
;
42 out
->f_namemax
= in
->f_namelen
;
45 int statvfs(const char *restrict path
, struct statvfs
*restrict buf
)
48 if (__statfs(path
, &kbuf
)<0) return -1;
53 int fstatvfs(int fd
, struct statvfs
*buf
)
56 if (__fstatfs(fd
, &kbuf
)<0) return -1;