From 472a80be90ddc43d3d4ef2f0834599dae98e0e26 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 12 Aug 2010 20:41:28 +0200 Subject: [PATCH] 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. --- src/fs.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/fs.c b/src/fs.c index 54617c6..2152552 100644 --- a/src/fs.c +++ b/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); } -void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size) +static double get_fs_perc(struct fs_stat *fs, int get_free) { - double val = 1.0; - struct fs_stat *fs = obj->data.opaque; - - if (!fs) - return; + double ret = 0.0; - if (fs->size) - val = (double)fs->avail / (double)fs->size; + if(fs && fs->size) { + if(get_free) + ret = fs->avail; + else + ret = fs->size - fs->free; + ret /= fs->size; + } - if (!be_free_bar) - val = 1.0 - val; + return ret; +} - new_bar(obj, p, p_max_size, (int)(255 * val)); +void print_fs_bar(struct text_object *obj, int be_free_bar, char *p, int p_max_size) +{ + 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) \ -- 1.7.9.5