Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1309713
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 04/11] lib/string_helpers: export string_units_{2,10} for others |
| Date | 2016-01-14 23:30 +0100 |
| Message-ID | <qQYz1-5b5-29@gated-at.bofh.it> (permalink) |
| References | <qQYz0-5b5-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
There is one user coming which would like to use those string arrays. It might
be useful for any other user in the future.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string_helpers.h | 6 ++++++
lib/string_helpers.c | 21 ++++++++++++---------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index dabe643..a55c9cc 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -10,6 +10,12 @@ enum string_size_units {
STRING_UNITS_2, /* use binary powers of 2^10 */
};
+#define STRING_UNITS_10_NUM 9
+#define STRING_UNITS_2_NUM 9
+
+extern const char *const string_units_10[STRING_UNITS_10_NUM];
+extern const char *const string_units_2[STRING_UNITS_2_NUM];
+
void string_get_size(u64 size, u64 blk_size, enum string_size_units units,
char *buf, int len);
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 5c88204..c62acc0 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -13,6 +13,15 @@
#include <linux/string.h>
#include <linux/string_helpers.h>
+const char * const string_units_10[STRING_UNITS_10_NUM] = {
+ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB",
+};
+EXPORT_SYMBOL(string_units_10);
+const char * const string_units_2[STRING_UNITS_2_NUM] = {
+ "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB",
+};
+EXPORT_SYMBOL(string_units_2);
+
/**
* string_get_size - get the size in the specified units
* @size: The size to be converted in blocks
@@ -29,15 +38,9 @@
void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
char *buf, int len)
{
- static const char *const units_10[] = {
- "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"
- };
- static const char *const units_2[] = {
- "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"
- };
static const char *const *const units_str[] = {
- [STRING_UNITS_10] = units_10,
- [STRING_UNITS_2] = units_2,
+ [STRING_UNITS_10] = string_units_10,
+ [STRING_UNITS_2] = string_units_2,
};
static const unsigned int divisor[] = {
[STRING_UNITS_10] = 1000,
@@ -115,7 +118,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
}
out:
- if (i >= ARRAY_SIZE(units_2))
+ if (i >= STRING_UNITS_2_NUM)
unit = "UNK";
else
unit = units_str[units][i];
--
2.6.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 00/11] lib/vsprintf: refactor and introduce %pl specifier Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 08/11] lib/vsprintf: allow range of prefix for %pl[From[To]] Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
Re: [PATCH v2 08/11] lib/vsprintf: allow range of prefix for %pl[From[To]] Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 22:50 +0100
[PATCH v2 02/11] lib/vsprintf: make default_dec_spec global Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
Re: [PATCH v2 02/11] lib/vsprintf: make default_dec_spec global Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 21:40 +0100
[PATCH v2 11/11] pcmciamtd: print value in human-readable form via %.0plKM Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 04/11] lib/string_helpers: export string_units_{2,10} for others Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 03/11] lib/vsprintf: make default_str_spec global Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 07/11] x86/efi: print size and base in binary units in efi_print_memmap Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 10/11] cxgb4: print value in human-readable form via %.0plKM Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 05/11] lib/string_helpers: fix indentation in few places Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
[PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form Joe Perches <joe@perches.com> - 2016-01-15 04:10 +0100
Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 22:00 +0100
Re: [PATCH v2 06/11] lib/vsprintf: introduce %pl to print in human-readable form "H. Peter Anvin" <hpa@zytor.com> - 2016-01-21 22:20 +0100
[PATCH v2 09/11] lib/vsprintf: use precision field with %pl[From[To]] Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
Re: [PATCH v2 09/11] lib/vsprintf: use precision field with %pl[From[To]] Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 23:30 +0100
[PATCH v2 01/11] lib/vsprintf: introduce put_one_char() for 3 line idiom Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-14 23:30 +0100
Re: [PATCH v2 01/11] lib/vsprintf: introduce put_one_char() for 3 line idiom Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-18 21:40 +0100
Re: [PATCH v2 00/11] lib/vsprintf: refactor and introduce %pl specifier Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-21 14:00 +0100
csiph-web