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>
This commit is contained in:
parent
52dbac69c2
commit
4b42c9059e
@ -218,7 +218,7 @@ void hang (void) __attribute__ ((noreturn));
|
|||||||
/* */
|
/* */
|
||||||
phys_size_t initdram (int);
|
phys_size_t initdram (int);
|
||||||
int display_options (void);
|
int display_options (void);
|
||||||
void print_size (phys_size_t, const char *);
|
void print_size(unsigned long long, const char *);
|
||||||
int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
|
int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
|
||||||
|
|
||||||
/* common/main.c */
|
/* common/main.c */
|
||||||
|
@ -39,25 +39,30 @@ int display_options (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* print sizes as "xxx kB", "xxx.y kB", "xxx MB", "xxx.y MB",
|
* print sizes as "xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
|
||||||
* xxx GB, or xxx.y GB as needed; allow for optional trailing string
|
* xxx GiB, xxx.y GiB, etc as needed; allow for optional trailing string
|
||||||
* (like "\n")
|
* (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 m = 0, n;
|
||||||
unsigned long long d = 1 << 30; /* 1 GB */
|
static const char names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
|
||||||
char c = 'G';
|
unsigned long long d = 1ULL << (10 * ARRAY_SIZE(names));
|
||||||
|
char c = 0;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
if (size < d) { /* try MB */
|
for (i = 0; i < ARRAY_SIZE(names); i++, d >>= 10) {
|
||||||
c = 'M';
|
if (size >= d) {
|
||||||
d = 1 << 20;
|
c = names[i];
|
||||||
if (size < d) { /* print in kB */
|
break;
|
||||||
c = 'k';
|
|
||||||
d = 1 << 10;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!c) {
|
||||||
|
printf("%llu Bytes%s", size, s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
n = size / d;
|
n = size / d;
|
||||||
|
|
||||||
/* If there's a remainder, deal with it */
|
/* 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) {
|
if (m) {
|
||||||
printf (".%ld", m);
|
printf (".%ld", m);
|
||||||
}
|
}
|
||||||
printf (" %cB%s", c, s);
|
printf (" %ciB%s", c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user