mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 12:27:52 +00:00
Make $fs_used_perc and $fs_bar report used space correctly
they reported fs->size - fs->avail, which is not correct if fs has super-user reserved blocks. note that now $fs_used_perc and $fs_free_perc need not add up to 100%, but that is consistent with what $fs_used and $fs_free do.
This commit is contained in:
parent
ad4f12281b
commit
472a80be90
43
src/fs.c
43
src/fs.c
@ -212,21 +212,24 @@ void init_fs_bar(struct text_object *obj, const char *arg)
|
||||
obj->data.opaque = prepare_fs_stat(arg);
|
||||
}
|
||||
|
||||
static double get_fs_perc(struct fs_stat *fs, int get_free)
|
||||
{
|
||||
double ret = 0.0;
|
||||
|
||||
if(fs && fs->size) {
|
||||
if(get_free)
|
||||
ret = fs->avail;
|
||||
else
|
||||
ret = fs->size - fs->free;
|
||||
ret /= fs->size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size)
|
||||
{
|
||||
double val = 1.0;
|
||||
struct fs_stat *fs = obj->data.opaque;
|
||||
|
||||
if (!fs)
|
||||
return;
|
||||
|
||||
if (fs->size)
|
||||
val = (double)fs->avail / (double)fs->size;
|
||||
|
||||
if (!be_free_bar)
|
||||
val = 1.0 - val;
|
||||
|
||||
new_bar(obj, p, p_max_size, (int)(255 * val));
|
||||
new_bar(obj, p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free_bar) * 255) );
|
||||
}
|
||||
|
||||
void init_fs(struct text_object *obj, const char *arg)
|
||||
@ -236,19 +239,7 @@ void init_fs(struct text_object *obj, const char *arg)
|
||||
|
||||
void print_fs_perc(struct text_object *obj, int be_free, char *p, int p_max_size)
|
||||
{
|
||||
struct fs_stat *fs = obj->data.opaque;
|
||||
int val = 100;
|
||||
|
||||
if (!fs)
|
||||
return;
|
||||
|
||||
if (fs->size)
|
||||
val = fs->avail * 100 / fs->size;
|
||||
|
||||
if (!be_free)
|
||||
val = 100 - val;
|
||||
|
||||
percent_print(p, p_max_size, val);
|
||||
percent_print(p, p_max_size, (int)(get_fs_perc(obj->data.opaque, be_free) * 100) );
|
||||
}
|
||||
|
||||
#define HUMAN_PRINT_FS_GENERATOR(name, expr) \
|
||||
|
Loading…
Reference in New Issue
Block a user