6 #include <linux/kernel.h>
8 #include <linux/export.h>
26 static const char *units_10[] = {
"B",
"kB",
"MB",
"GB",
"TB",
"PB",
27 "EB",
"ZB",
"YB",
NULL};
28 static const char *units_2[] = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
29 "EiB",
"ZiB",
"YiB",
NULL };
30 static const char **units_str[] = {
34 static const unsigned int divisor[] = {
39 u64 remainder = 0, sf_cap;
44 if (size >= divisor[units]) {
45 while (size >= divisor[units] && units_str[units][i]) {
46 remainder =
do_div(size, divisor[units]);
51 for (j = 0; sf_cap*10 < 1000; j++)
56 do_div(remainder, divisor[units]);
57 snprintf(tmp,
sizeof(tmp),
".%03lld",
58 (
unsigned long long)remainder);
63 snprintf(buf, len,
"%lld%s %s", (
unsigned long long)size,
64 tmp, units_str[units][i]);