1
0

added disk functions for details

This commit is contained in:
Aaron Marcher 2016-06-10 19:13:13 +02:00 committed by Aaron Marcher (drkhsh)
parent 688c2d43e2
commit fb524b6050
3 changed files with 58 additions and 1 deletions

View File

@ -15,11 +15,17 @@ static unsigned int update_interval = 1;
- battery_perc (battery percentage) [argument: battery name] - battery_perc (battery percentage) [argument: battery name]
- cpu_perc (cpu usage in percent) [argument: NULL] - cpu_perc (cpu usage in percent) [argument: NULL]
- datetime (date and time) [argument: format] - datetime (date and time) [argument: format]
- disk_free (disk usage in percent) [argument: mountpoint]
- disk_perc (disk usage in percent) [argument: mountpoint] - disk_perc (disk usage in percent) [argument: mountpoint]
- disk_total (disk usage in percent) [argument: mountpoint]
- disk_used (disk usage in percent) [argument: mountpoint]
- entropy (available entropy) [argument: NULL] - entropy (available entropy) [argument: NULL]
- hostname [argument: NULL] - hostname [argument: NULL]
- ip (ip address) [argument: interface] - ip (ip address) [argument: interface]
- ram_free (ram usage in percent) [argument: NULL]
- ram_perc (ram usage in percent) [argument: NULL] - ram_perc (ram usage in percent) [argument: NULL]
- ram_total (ram usage in percent) [argument: NULL]
- ram_used (ram usage in percent) [argument: NULL]
- temp (temperature in degrees) [argument: temperature file] - temp (temperature in degrees) [argument: temperature file]
- vol_perc (alsa volume and mute status in percent) [argument: soundcard] - vol_perc (alsa volume and mute status in percent) [argument: soundcard]
- wifi_perc (wifi signal in percent) [argument: wifi card interface name] */ - wifi_perc (wifi signal in percent) [argument: wifi card interface name] */

View File

@ -166,6 +166,22 @@ datetime(const char *timeformat)
return ret; return ret;
} }
/* disk free */
char *
disk_free(const char *mountpoint)
{
struct statvfs fs;
/* try to open mountpoint */
if (statvfs(mountpoint, &fs) < 0) {
fprintf(stderr, "Could not get filesystem info.\n");
return smprintf("n/a");
}
/* return free */
return smprintf("%f", (float)fs.f_bsize * (float)fs.f_bfree / 1024 / 1024 / 1024);
}
/* disk usage percentage */ /* disk usage percentage */
char * char *
disk_perc(const char *mountpoint) disk_perc(const char *mountpoint)
@ -180,12 +196,44 @@ disk_perc(const char *mountpoint)
} }
/* calculate percent */ /* calculate percent */
perc = 100 * (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks)); perc = 100 * (1.0f - ((float)fs.f_bfree / (float)fs.f_blocks));
/* return perc */ /* return perc */
return smprintf("%d%%", perc); return smprintf("%d%%", perc);
} }
/* disk total */
char *
disk_total(const char *mountpoint)
{
struct statvfs fs;
/* try to open mountpoint */
if (statvfs(mountpoint, &fs) < 0) {
fprintf(stderr, "Could not get filesystem info.\n");
return smprintf("n/a");
}
/* return total */
return smprintf("%f", (float)fs.f_bsize * (float)fs.f_blocks / 1024 / 1024 / 1024);
}
/* disk used */
char *
disk_used(const char *mountpoint)
{
struct statvfs fs;
/* try to open mountpoint */
if (statvfs(mountpoint, &fs) < 0) {
fprintf(stderr, "Could not get filesystem info.\n");
return smprintf("n/a");
}
/* return used */
return smprintf("%f", (float)fs.f_bsize * ((float)fs.f_blocks - (float)fs.f_bfree) / 1024 / 1024 / 1024);
}
/* entropy available */ /* entropy available */
char * char *
entropy(const char *null) entropy(const char *null)

View File

@ -17,7 +17,10 @@ char *smprintf(const char *, ...);
char *battery_perc(const char *); char *battery_perc(const char *);
char *cpu_perc(const char *); char *cpu_perc(const char *);
char *datetime(const char *); char *datetime(const char *);
char *disk_free(const char *);
char *disk_perc(const char *); char *disk_perc(const char *);
char *disk_total(const char *);
char *disk_used(const char *);
char *entropy(const char*); char *entropy(const char*);
char *hostname(const char *); char *hostname(const char *);
char *ip(const char *); char *ip(const char *);