1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | #include <stdio.h> #include <errno.h> #include <sys/statvfs.h> int main(int argc, char *argv[]) { const char* path = argc > 1 ? argv[1] : "/writable"; struct statvfs buf; if (statvfs(path, &buf) < 0) { perror("statvfs"); return 1; } printf("%s has %lu blocks of %lu bytes available (~%0f%%)\n", path, buf.f_bavail, buf.f_bsize, 100.*buf.f_bavail/buf.f_blocks*buf.f_bsize/buf.f_frsize); return 0; } |