]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Display size with human_size_brief with a chosen prefix
authorMaciej Naruszewicz <maciej.naruszewicz@intel.com>
Tue, 2 Oct 2012 06:41:13 +0000 (16:41 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 2 Oct 2012 06:41:13 +0000 (16:41 +1000)
When using human_size_brief, only IEC prefixes were supported. Now
it's possible to specify which format we want to see - either IEC
(kibi, mibi, gibi) or JEDEC (kilo, mega, giga).

Signed-off-by: Maciej Naruszewicz <maciej.naruszewicz@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Query.c
mdadm.h
util.c

diff --git a/Query.c b/Query.c
index b9c209f7993a39513592fdbbc28eb5740504dec6..329e58390bd265fe864bf896783fc8ed87e809b8 100644 (file)
--- a/Query.c
+++ b/Query.c
@@ -76,7 +76,7 @@ int Query(char *dev)
        else {
                printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
                       dev,
-                      human_size_brief(larray_size),
+                      human_size_brief(larray_size,IEC),
                       map_num(pers, array.level),
                       array.raid_disks,
                       array.spare_disks, array.spare_disks==1?"":"s");
diff --git a/mdadm.h b/mdadm.h
index 6d219f7f85f83837a24cf0c6e28d7aa297220d38..fe28d3de1d3733b49c2711ca920ba6bb4b07cdb3 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -328,6 +328,11 @@ enum special_options {
        KillOpt,
 };
 
+enum prefix_standard {
+       JEDEC,
+       IEC
+};
+
 /* structures read from config file */
 /* List of mddevice names and identifiers
  * Identifiers can be:
@@ -1240,7 +1245,7 @@ extern int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info);
 unsigned long long min_recovery_start(struct mdinfo *array);
 
 extern char *human_size(long long bytes);
-extern char *human_size_brief(long long bytes);
+extern char *human_size_brief(long long bytes, int prefix);
 extern void print_r10_layout(int layout);
 
 #define NoMdDev (1<<23)
diff --git a/util.c b/util.c
index 09971a29d1306d1f7472bef57df756860b4f6654..cb97816c346f5d4b5e88068d423090d00c10a2bc 100644 (file)
--- 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;
 }