• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <sys/statvfs.h>
2 #include <sys/statfs.h>
3 #include "syscall.h"
4 
__statfs(const char * path,struct statfs * buf)5 static int __statfs(const char *path, struct statfs *buf)
6 {
7 	*buf = (struct statfs){0};
8 #ifdef SYS_statfs64
9 	return syscall(SYS_statfs64, path, sizeof *buf, buf);
10 #else
11 	return syscall(SYS_statfs, path, buf);
12 #endif
13 }
14 
__fstatfs(int fd,struct statfs * buf)15 static int __fstatfs(int fd, struct statfs *buf)
16 {
17 	*buf = (struct statfs){0};
18 #ifdef SYS_fstatfs64
19 	return syscall(SYS_fstatfs64, fd, sizeof *buf, buf);
20 #else
21 	return syscall(SYS_fstatfs, fd, buf);
22 #endif
23 }
24 
25 weak_alias(__statfs, statfs);
26 weak_alias(__fstatfs, fstatfs);
27 
fixup(struct statvfs * out,const struct statfs * in)28 static void fixup(struct statvfs *out, const struct statfs *in)
29 {
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;
42 }
43 
statvfs(const char * restrict path,struct statvfs * restrict buf)44 int statvfs(const char *restrict path, struct statvfs *restrict buf)
45 {
46 	struct statfs kbuf;
47 	if (__statfs(path, &kbuf)<0) return -1;
48 	fixup(buf, &kbuf);
49 	return 0;
50 }
51 
fstatvfs(int fd,struct statvfs * buf)52 int fstatvfs(int fd, struct statvfs *buf)
53 {
54 	struct statfs kbuf;
55 	if (__fstatfs(fd, &kbuf)<0) return -1;
56 	fixup(buf, &kbuf);
57 	return 0;
58 }
59 
60 weak_alias(statvfs, statvfs64);
61 weak_alias(statfs, statfs64);
62 weak_alias(fstatvfs, fstatvfs64);
63 weak_alias(fstatfs, fstatfs64);
64