aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/devices
diff options
context:
space:
mode:
authorJoern Engel <joern@wohnheim.fh-wedel.de>2006-04-19 00:03:08 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2006-04-19 04:10:06 -0400
commit954c24227318c166ec1925e1229db442e1f56f51 (patch)
tree6fab80f6c186bc83dd06e697774fbb5bf83e4235 /drivers/mtd/devices
parent373d5e71833978fe3d91264d86857762bb92cfe2 (diff)
mtd: improve parameter parsing for block2mtd
Expand the parameter parsing for block2mtd. It now accepts: Ki, Mi, Gi - the official prefixes for binary multiples, see http://physics.nist.gov/cuu/Units/binary.html, ki - mistake on my side and analog to "k" for decimal multiples, KiB, MiB, GiB - for people that prefer to add a "B" for byte, kiB - combination of the above. There were complaints about not accepting "k" for 1024. This has long been common practice, but is known to lead to confusion. Hence the new SI units and hence block2mtd only accepts units that cannot be confused with decimal units. Diverging from common practice doesn't always please people, even if the change is for the better. Signed-off-by: Joern Engel <joern@wohnheim.fh-wedel.de> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Andrew Morton <akpm@osdl.org>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r--drivers/mtd/devices/block2mtd.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 4160b8334c53..f54e4bf9b968 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -4,7 +4,7 @@
4 * block2mtd.c - create an mtd from a block device 4 * block2mtd.c - create an mtd from a block device
5 * 5 *
6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk> 6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk>
7 * Copyright (C) 2004,2005 Jörn Engel <joern@wh.fh-wedel.de> 7 * Copyright (C) 2004-2006 Jörn Engel <joern@wh.fh-wedel.de>
8 * 8 *
9 * Licence: GPL 9 * Licence: GPL
10 */ 10 */
@@ -351,6 +351,12 @@ devinit_err:
351} 351}
352 352
353 353
354/* This function works similar to reguler strtoul. In addition, it
355 * allows some suffixes for a more human-readable number format:
356 * ki, Ki, kiB, KiB - multiply result with 1024
357 * Mi, MiB - multiply result with 1024^2
358 * Gi, GiB - multiply result with 1024^3
359 */
354static int ustrtoul(const char *cp, char **endp, unsigned int base) 360static int ustrtoul(const char *cp, char **endp, unsigned int base)
355{ 361{
356 unsigned long result = simple_strtoul(cp, endp, base); 362 unsigned long result = simple_strtoul(cp, endp, base);
@@ -359,11 +365,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base)
359 result *= 1024; 365 result *= 1024;
360 case 'M': 366 case 'M':
361 result *= 1024; 367 result *= 1024;
368 case 'K':
362 case 'k': 369 case 'k':
363 result *= 1024; 370 result *= 1024;
364 /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */ 371 /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
365 if ((*endp)[1] == 'i') 372 if ((*endp)[1] == 'i') {
366 (*endp) += 2; 373 if ((*endp)[2] == 'B')
374 (*endp) += 3;
375 else
376 (*endp) += 2;
377 }
367 } 378 }
368 return result; 379 return result;
369} 380}