* [U-Boot] [PATCH] [v2] allow print_size to print large numbers on 32-bit systems
@ 2010-04-12 19:43 Timur Tabi
2010-04-12 19:54 ` Scott Wood
0 siblings, 1 reply; 2+ messages in thread
From: Timur Tabi @ 2010-04-12 19:43 UTC (permalink / raw)
To: u-boot
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>
---
lib_generic/display_options.c | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/lib_generic/display_options.c b/lib_generic/display_options.c
index da17a62..53b154d 100644
--- a/lib_generic/display_options.c
+++ b/lib_generic/display_options.c
@@ -40,22 +40,22 @@ 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
+ * xxx GB, xxx.y GB, etc as needed; allow for optional trailing string
* (like "\n")
*/
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[] = {'K', 'M', 'G', 'T', 'P', 'E'};
+ unsigned long long d;
+ char c;
+ unsigned int i;
+
+ for (i = ARRAY_SIZE(names); i > 0 ; i--) {
+ d = 1ULL << (10 * i);
+ c = names[i - 1];
+ if (size >= d)
+ break;
}
n = size / d;
@@ -74,7 +74,7 @@ void print_size(unsigned long long size, const char *s)
if (m) {
printf (".%ld", m);
}
- printf (" %cB%s", c, s);
+ printf (" %ciB%s", c, s);
}
/*
--
1.6.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH] [v2] allow print_size to print large numbers on 32-bit systems
2010-04-12 19:43 [U-Boot] [PATCH] [v2] allow print_size to print large numbers on 32-bit systems Timur Tabi
@ 2010-04-12 19:54 ` Scott Wood
0 siblings, 0 replies; 2+ messages in thread
From: Scott Wood @ 2010-04-12 19:54 UTC (permalink / raw)
To: u-boot
Timur Tabi wrote:
> 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>
> ---
> lib_generic/display_options.c | 22 +++++++++++-----------
> 1 files changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/lib_generic/display_options.c b/lib_generic/display_options.c
> index da17a62..53b154d 100644
> --- a/lib_generic/display_options.c
> +++ b/lib_generic/display_options.c
> @@ -40,22 +40,22 @@ 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
> + * xxx GB, xxx.y GB, etc as needed; allow for optional trailing string
[snip]
> - printf (" %cB%s", c, s);
> + printf (" %ciB%s", c, s);
Comment should be updated to match the code.
-Scott
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-04-12 19:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-12 19:43 [U-Boot] [PATCH] [v2] allow print_size to print large numbers on 32-bit systems Timur Tabi
2010-04-12 19:54 ` Scott Wood
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.