X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/6123f482e39d9488df03898a0aadca3bdaf8673f..32e0a2bfcc7def9128fb7f385b603f2c5fe34e4d:/components/disk.c diff --git a/components/disk.c b/components/disk.c index 8112981..9d2284e 100644 --- a/components/disk.c +++ b/components/disk.c @@ -1,7 +1,5 @@ /* See LICENSE file for copyright and license details. */ -#include #include -#include #include #include "../util.h" @@ -12,12 +10,11 @@ disk_free(const char *mnt) struct statvfs fs; if (statvfs(mnt, &fs) < 0) { - fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno)); + warn("statvfs '%s':", mnt); return NULL; } - return bprintf("%f", - (float)fs.f_bsize * (float)fs.f_bfree / 1024 / 1024 / 1024); + return fmt_human(fs.f_frsize * fs.f_bavail, 1024); } const char * @@ -26,12 +23,12 @@ disk_perc(const char *mnt) struct statvfs fs; if (statvfs(mnt, &fs) < 0) { - fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno)); + warn("statvfs '%s':", mnt); return NULL; } return bprintf("%d", (int)(100 * - (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks)))); + (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks)))); } const char * @@ -40,12 +37,11 @@ disk_total(const char *mnt) struct statvfs fs; if (statvfs(mnt, &fs) < 0) { - fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno)); + warn("statvfs '%s':", mnt); return NULL; } - return bprintf("%f", - (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024); + return fmt_human(fs.f_frsize * fs.f_blocks, 1024); } const char * @@ -54,11 +50,9 @@ disk_used(const char *mnt) struct statvfs fs; if (statvfs(mnt, &fs) < 0) { - fprintf(stderr, "statvfs '%s': %s\n", mnt, strerror(errno)); + warn("statvfs '%s':", mnt); return NULL; } - return bprintf("%f", - (float)fs.f_bsize * ((float)fs.f_blocks - - (float)fs.f_bfree) / 1024 / 1024 / 1024); + return fmt_human(fs.f_frsize * (fs.f_blocks - fs.f_bfree), 1024); }