summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2010-04-13 13:16:03 -0500
committerWolfgang Denk <wd@denx.de>2010-05-05 22:17:34 +0200
commit4b42c9059e165500353174601a8e97b2cf81d3f4 (patch)
tree30608de1b0b5314a5320d36dd9c102dc3bf8b324 /lib
parent52dbac69c27dee67a4c051b1055d93b0ac4e2062 (diff)
downloadu-boot-imx-4b42c9059e165500353174601a8e97b2cf81d3f4.zip
u-boot-imx-4b42c9059e165500353174601a8e97b2cf81d3f4.tar.gz
u-boot-imx-4b42c9059e165500353174601a8e97b2cf81d3f4.tar.bz2
allow print_size to print large numbers on 32-bit systems
Modify print_size() so that it can accept numbers larger than 4GB on 32-bit systems. Add support for display terabyte, petabyte, and exabyte sizes. Change the output to use International Electrotechnical Commission binary prefix standard. Signed-off-by: Timur Tabi <timur@freescale.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/display_options.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/display_options.c b/lib/display_options.c
index 08a7914..86df05d 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -39,25 +39,30 @@ int display_options (void)
}
/*
- * print sizes as "xxx kB", "xxx.y kB", "xxx MB", "xxx.y MB",
- * xxx GB, or xxx.y GB as needed; allow for optional trailing string
+ * print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
+ * xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string
* (like "\n")
*/
-void print_size (phys_size_t size, const char *s)
+void print_size(unsigned long long size, const char *s)
{
unsigned long m = 0, n;
- unsigned long long d = 1 << 30; /* 1 GB */
- char c = 'G';
-
- if (size < d) { /* try MB */
- c = 'M';
- d = 1 << 20;
- if (size < d) { /* print in kB */
- c = 'k';
- d = 1 << 10;
+ static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
+ unsigned long long d = 1ULL << (10 * ARRAY_SIZE(names));
+ char c = 0;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(names); i++, d >>= 10) {
+ if (size >= d) {
+ c = names[i];
+ break;
}
}
+ if (!c) {
+ printf("%llu Bytes%s", size, s);
+ return;
+ }
+
n = size / d;
/* If there's a remainder, deal with it */
@@ -70,11 +75,11 @@ void print_size (phys_size_t size, const char *s)
}
}
- printf ("%2ld", n);
+ printf ("%lu", n);
if (m) {
printf (".%ld", m);
}
- printf (" %cB%s", c, s);
+ printf (" %ciB%s", c, s);
}
/*