Files
fastfetch/src/modules/disk.c
T

25 lines
665 B
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
#include <sys/statvfs.h>
2021-02-27 18:30:05 +01:00
void ffPrintDisk(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
struct statvfs fs;
int ret = statvfs("/", &fs);
if(ret != 0)
{
2021-02-27 18:30:05 +01:00
ffPrintError(instance, "Disk (/)", "statvfs(\"/\", &fs) != 0");
2021-02-18 22:25:36 +01:00
return;
}
const uint32_t GB = (1024 * 1024) * 1024;
const uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
const uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
const uint32_t used = total - available;
const uint32_t percentage = (used / (double) total) * 100.0;
2021-02-27 18:30:05 +01:00
ffPrintLogoAndKey(instance, "Disk (/)");
2021-02-19 10:07:00 +01:00
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
2021-02-18 22:25:36 +01:00
}