X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=util.c;h=cb97816c346f5d4b5e88068d423090d00c10a2bc;hp=09971a29d1306d1f7472bef57df756860b4f6654;hb=f0ec67106c00f8dd1cadebfdff933fd8aefa0ff2;hpb=570abc6f3881b5152cb1244d5e6afcc421c5a4ce diff --git a/util.c b/util.c index 09971a29..cb97816c 100644 --- a/util.c +++ b/util.c @@ -682,7 +682,7 @@ char *human_size(long long bytes) return buf; } -char *human_size_brief(long long bytes) +char *human_size_brief(long long bytes, int prefix) { static char buf[30]; @@ -693,19 +693,37 @@ char *human_size_brief(long long bytes) * gigabytes, as that shows more precision and isn't * too large a number. * Terabytes are not yet handled. + * + * If prefix == IEC, we mean prefixes like kibi,mebi,gibi etc. + * If prefix == JEDEC, we mean prefixes like kilo,mega,giga etc. */ if (bytes < 5000*1024) buf[0] = 0; - else if (bytes < 2*1024LL*1024LL*1024LL) { - long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2; - snprintf(buf, sizeof(buf), " (%ld.%02ldMiB)", - cMiB/100 , cMiB % 100); - } else { - long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2; - snprintf(buf, sizeof(buf), " (%ld.%02ldGiB)", - cGiB/100 , cGiB % 100); + else if (prefix == IEC) { + if (bytes < 2*1024LL*1024LL*1024LL) { + long cMiB = (bytes / ( (1LL<<20) / 200LL ) +1) /2; + snprintf(buf, sizeof(buf), "%ld.%02ldMiB", + cMiB/100 , cMiB % 100); + } else { + long cGiB = (bytes / ( (1LL<<30) / 200LL ) +1) /2; + snprintf(buf, sizeof(buf), "%ld.%02ldGiB", + cGiB/100 , cGiB % 100); + } + } + else if (prefix == JEDEC) { + if (bytes < 2*1024LL*1024LL*1024LL) { + long cMB = (bytes / ( 1000000LL / 200LL ) +1) /2; + snprintf(buf, sizeof(buf), "%ld.%02ldMB", + cMB/100, cMB % 100); + } else { + long cGB = (bytes / (1000000000LL/200LL ) +1) /2; + snprintf(buf, sizeof(buf), "%ld.%02ldGB", + cGB/100 , cGB % 100); + } } + else + buf[0] = 0; return buf; }