1 #include <sys/statvfs.h>
2 #include <sys/statfs.h>
5 static int __statfs(const char *path
, struct statfs
*buf
)
7 *buf
= (struct statfs
){0};
9 return syscall(SYS_statfs64
, path
, sizeof *buf
, buf
);
11 return syscall(SYS_statfs
, path
, buf
);
15 static int __fstatfs(int fd
, struct statfs
*buf
)
17 *buf
= (struct statfs
){0};
19 return syscall(SYS_fstatfs64
, fd
, sizeof *buf
, buf
);
21 return syscall(SYS_fstatfs
, fd
, buf
);
25 weak_alias(__statfs
, statfs
);
26 weak_alias(__fstatfs
, fstatfs
);
28 static void fixup(struct statvfs
*out
, const struct statfs
*in
)
30 *out
= (struct statvfs
){0};
31 out
->f_bsize
= in
->f_bsize
;
32 out
->f_frsize
= in
->f_frsize
? in
->f_frsize
: in
->f_bsize
;
33 out
->f_blocks
= in
->f_blocks
;
34 out
->f_bfree
= in
->f_bfree
;
35 out
->f_bavail
= in
->f_bavail
;
36 out
->f_files
= in
->f_files
;
37 out
->f_ffree
= in
->f_ffree
;
38 out
->f_favail
= in
->f_ffree
;
39 out
->f_fsid
= in
->f_fsid
.__val
[0];
40 out
->f_flag
= in
->f_flags
;
41 out
->f_namemax
= in
->f_namelen
;
44 int statvfs(const char *restrict path
, struct statvfs
*restrict buf
)
47 if (__statfs(path
, &kbuf
)<0) return -1;
52 int fstatvfs(int fd
, struct statvfs
*buf
)
55 if (__fstatfs(fd
, &kbuf
)<0) return -1;
60 weak_alias(statvfs
, statvfs64
);
61 weak_alias(statfs
, statfs64
);
62 weak_alias(fstatvfs
, fstatvfs64
);
63 weak_alias(fstatfs
, fstatfs64
);