Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
4 #include <sys/statvfs.h>
9 disk_free(const char *mnt
)
13 if (statvfs(mnt
, &fs
) < 0) {
14 warn("Failed to get filesystem info");
18 return bprintf("%f", (float)fs
.f_bsize
* (float)fs
.f_bfree
/ 1024 / 1024 / 1024);
22 disk_perc(const char *mnt
)
27 if (statvfs(mnt
, &fs
) < 0) {
28 warn("Failed to get filesystem info");
32 perc
= 100 * (1.0f
- ((float)fs
.f_bfree
/ (float)fs
.f_blocks
));
34 return bprintf("%d", perc
);
38 disk_total(const char *mnt
)
42 if (statvfs(mnt
, &fs
) < 0) {
43 warn("Failed to get filesystem info");
47 return bprintf("%f", (float)fs
.f_bsize
* (float)fs
.f_blocks
/ 1024 / 1024 / 1024);
51 disk_used(const char *mnt
)
55 if (statvfs(mnt
, &fs
) < 0) {
56 warn("Failed to get filesystem info");
60 return bprintf("%f", (float)fs
.f_bsize
* ((float)fs
.f_blocks
- (float)fs
.f_bfree
) / 1024 / 1024 / 1024);