提交 954c2422 编写于 作者: J Joern Engel 提交者: David Woodhouse

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: NJoern Engel <joern@wohnheim.fh-wedel.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
上级 373d5e71
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* block2mtd.c - create an mtd from a block device * block2mtd.c - create an mtd from a block device
* *
* Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk> * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk>
* Copyright (C) 2004,2005 Jrn Engel <joern@wh.fh-wedel.de> * Copyright (C) 2004-2006 Jrn Engel <joern@wh.fh-wedel.de>
* *
* Licence: GPL * Licence: GPL
*/ */
...@@ -351,6 +351,12 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) ...@@ -351,6 +351,12 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
} }
/* This function works similar to reguler strtoul. In addition, it
* allows some suffixes for a more human-readable number format:
* ki, Ki, kiB, KiB - multiply result with 1024
* Mi, MiB - multiply result with 1024^2
* Gi, GiB - multiply result with 1024^3
*/
static int ustrtoul(const char *cp, char **endp, unsigned int base) static int ustrtoul(const char *cp, char **endp, unsigned int base)
{ {
unsigned long result = simple_strtoul(cp, endp, base); unsigned long result = simple_strtoul(cp, endp, base);
...@@ -359,11 +365,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base) ...@@ -359,11 +365,16 @@ static int ustrtoul(const char *cp, char **endp, unsigned int base)
result *= 1024; result *= 1024;
case 'M': case 'M':
result *= 1024; result *= 1024;
case 'K':
case 'k': case 'k':
result *= 1024; result *= 1024;
/* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */ /* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
if ((*endp)[1] == 'i') if ((*endp)[1] == 'i') {
(*endp) += 2; if ((*endp)[2] == 'B')
(*endp) += 3;
else
(*endp) += 2;
}
} }
return result; return result;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册