mirror of
https://github.com/vale981/yabar
synced 2025-03-06 10:01:41 -05:00
add comments to disk usage block
This commit is contained in:
parent
03328b61a6
commit
f3849ee4c5
1 changed files with 6 additions and 0 deletions
|
@ -575,7 +575,10 @@ ya_volume_error:
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -- Disk usage block -- */
|
||||||
static const char const symbols[5] = {0, 'K', 'M', 'G', 'T'};
|
static const char const symbols[5] = {0, 'K', 'M', 'G', 'T'};
|
||||||
|
/* bytes to human-readable str: convert an amount of bytes to a string with the
|
||||||
|
corresponding suffix. e.g. "123456789" -> "117.7M" (bytes) */
|
||||||
static int btohstr(char *str, uint64_t bytes)
|
static int btohstr(char *str, uint64_t bytes)
|
||||||
{
|
{
|
||||||
double size = bytes;
|
double size = bytes;
|
||||||
|
@ -597,6 +600,8 @@ void ya_int_diskspace(ya_block_t *blk) {
|
||||||
int8_t mntpntcount = -1;
|
int8_t mntpntcount = -1;
|
||||||
FILE *mntentfile = setmntent("/etc/mtab", "r");;
|
FILE *mntentfile = setmntent("/etc/mtab", "r");;
|
||||||
struct mntent *m;
|
struct mntent *m;
|
||||||
|
/* read /etc/mtab to get all mountpoints where the underlying device or
|
||||||
|
volume group matches the internal-option1 */
|
||||||
while ( (m = getmntent(mntentfile)) != NULL ) {
|
while ( (m = getmntent(mntentfile)) != NULL ) {
|
||||||
if (strncmp(m->mnt_fsname, blk->internal->option[0],
|
if (strncmp(m->mnt_fsname, blk->internal->option[0],
|
||||||
strlen(blk->internal->option[0])) == 0) {
|
strlen(blk->internal->option[0])) == 0) {
|
||||||
|
@ -622,6 +627,7 @@ void ya_int_diskspace(ya_block_t *blk) {
|
||||||
while (1) {
|
while (1) {
|
||||||
free = 0;
|
free = 0;
|
||||||
total = 0;
|
total = 0;
|
||||||
|
/* get and sum used / total space of every mountpoints */
|
||||||
for( int i = 0; i <= mntpntcount; i++) {
|
for( int i = 0; i <= mntpntcount; i++) {
|
||||||
if ( statvfs(mountpoints[i], &stat) != -1 ) {
|
if ( statvfs(mountpoints[i], &stat) != -1 ) {
|
||||||
free += (uint64_t)(stat.f_bfree * stat.f_bsize);
|
free += (uint64_t)(stat.f_bfree * stat.f_bsize);
|
||||||
|
|
Loading…
Add table
Reference in a new issue