From e4c86af69014f1a129098c5edf8706e9d08dbb4e Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Sat, 7 Sep 2019 10:59:00 +0000 Subject: [PATCH] Config: Added support for terabyte values, for example "123T". --- ucw/conf-parse.c | 24 ++++++++++++++---------- ucw/doc/config.txt | 1 + ucw/stkstring.c | 8 ++++++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ucw/conf-parse.c b/ucw/conf-parse.c index 490b03be..fc185049 100644 --- a/ucw/conf-parse.c +++ b/ucw/conf-parse.c @@ -3,6 +3,7 @@ * * (c) 2001--2006 Robert Spalek * (c) 2003--2006 Martin Mares + * (c) 2019 Pavel Charvat * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -18,19 +19,22 @@ struct unit { uint name; // one-letter name of the unit - uint num, den; // fraction + uint den; // fraction + u64 num; }; static const struct unit units[] = { - { 'd', 86400, 1 }, - { 'h', 3600, 1 }, - { 'k', 1000, 1 }, - { 'm', 1000000, 1 }, - { 'g', 1000000000, 1 }, - { 'K', 1024, 1 }, - { 'M', 1048576, 1 }, - { 'G', 1073741824, 1 }, - { '%', 1, 100 }, + { 'd', 1, 86400 }, + { 'h', 1, 3600 }, + { 'k', 1, 1000 }, + { 'm', 1, 1000000 }, + { 'g', 1, 1000000000 }, + { 't', 1, 1000000000000LLU }, + { 'K', 1, 1<<10 }, + { 'M', 1, 1<<20 }, + { 'G', 1, 1<<30 }, + { 'T', 1, 1LLU<<40 }, + { '%', 100, 1 }, { 0, 0, 0 } }; diff --git a/ucw/doc/config.txt b/ucw/doc/config.txt index 52598016..6b32c5ad 100644 --- a/ucw/doc/config.txt +++ b/ucw/doc/config.txt @@ -72,6 +72,7 @@ supported: d=86400 k=1000 K=1024 h=3600 m=1000000 M=1048576 %=0.01 g=1000000000 G=1073741824 + t=1000000000000 T=1099511627776 Attributes of a section or a list node can be set in two ways. First, you can write the name of the section or list, open a bracket, and then diff --git a/ucw/stkstring.c b/ucw/stkstring.c index d3c6d554..bb3b97a0 100644 --- a/ucw/stkstring.c +++ b/ucw/stkstring.c @@ -3,7 +3,7 @@ * * (c) 2005--2007 Martin Mares * (c) 2005 Tomas Valla - * (c) 2008 Pavel Charvat + * (c) 2008--2019 Pavel Charvat * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -105,8 +105,12 @@ stk_fsize_internal(char *buf, u64 x) sprintf(buf, "%dM", (int)(x/(1<<20))); else if (x < (u64)10<<30) sprintf(buf, "%.1fG", (double)x/(1<<30)); + else if (x < (u64)1<<40) + sprintf(buf, "%dG", (int)x/(1<<30)); + else if (x < (u64)10<<40) + sprintf(buf, "%.1fT", (double)x/((u64)1<<40)); else if (x != ~(u64)0) - sprintf(buf, "%dG", (int)(x/(1<<30))); + sprintf(buf, "%dT", (int)(x/((u64)1<<40))); else strcpy(buf, "unknown"); } -- 2.39.2