Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
3 #include <sys/statvfs.h>
8 disk_free(const char *path
)
12 if (statvfs(path
, &fs
) < 0) {
13 warn("statvfs '%s':", path
);
17 return fmt_human(fs
.f_frsize
* fs
.f_bavail
, 1024);
21 disk_perc(const char *path
)
25 if (statvfs(path
, &fs
) < 0) {
26 warn("statvfs '%s':", path
);
30 return bprintf("%d", (int)(100 *
31 (1.0f
- ((float)fs
.f_bavail
/ (float)fs
.f_blocks
))));
35 disk_total(const char *path
)
39 if (statvfs(path
, &fs
) < 0) {
40 warn("statvfs '%s':", path
);
44 return fmt_human(fs
.f_frsize
* fs
.f_blocks
, 1024);
48 disk_used(const char *path
)
52 if (statvfs(path
, &fs
) < 0) {
53 warn("statvfs '%s':", path
);
57 return fmt_human(fs
.f_frsize
* (fs
.f_blocks
- fs
.f_bfree
), 1024);