Files
fastfetch/src/modules/disk.c
T

36 lines
1008 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;
2021-02-18 22:25:36 +01:00
2021-03-19 20:57:07 +01:00
uint32_t total = (fs.f_blocks * fs.f_frsize) / GB;
uint32_t available = (fs.f_bfree * fs.f_frsize) / GB;
uint32_t used = total - available;
2021-03-19 20:57:07 +01:00
uint8_t percentage = (used / (double) total) * 100.0;
2021-02-18 22:25:36 +01:00
2021-03-23 19:48:52 +01:00
if(instance->config.diskFormat.length == 0)
2021-03-19 20:57:07 +01:00
{
ffPrintLogoAndKey(instance, "Disk (/)");
2021-03-19 20:57:07 +01:00
printf("%uGB / %uGB (%u%%)\n", used, total, percentage);
}
else
{
ffPrintFormatString(instance, "Disk (/)", &instance->config.diskFormat, 3,
2021-03-19 20:57:07 +01:00
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &used},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT, &total},
(FFformatarg){FF_FORMAT_ARG_TYPE_UINT8, &percentage}
);
}
2021-03-27 18:14:19 +01:00
}