mtd: improve parameter parsing for block2mtd

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed May 3 13:56:32 EDT 2006


commit 954c24227318c166ec1925e1229db442e1f56f51
tree 6fab80f6c186bc83dd06e697774fbb5bf83e4235
parent 373d5e71833978fe3d91264d86857762bb92cfe2
author Joern Engel <joern at wohnheim.fh-wedel.de> Wed, 19 Apr 2006 11:03:08 -0700
committer David Woodhouse <dwmw2 at infradead.org> Wed, 19 Apr 2006 09:10:06 +0100

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 at wohnheim.fh-wedel.de>
Cc: David Woodhouse <dwmw2 at infradead.org>
Cc: Thomas Gleixner <tglx at linutronix.de>
Signed-off-by: Andrew Morton <akpm at osdl.org>

 drivers/mtd/devices/block2mtd.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 4160b83..f54e4bf 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -4,7 +4,7 @@
  * block2mtd.c - create an mtd from a block device
  *
  * Copyright (C) 2001,2002	Simon Evans <spse at secret.org.uk>
- * Copyright (C) 2004,2005	Jörn Engel <joern at wh.fh-wedel.de>
+ * Copyright (C) 2004-2006	Jörn Engel <joern at wh.fh-wedel.de>
  *
  * Licence: GPL
  */
@@ -351,6 +351,12 @@ devinit_err:
 }
 
 
+/* 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)
 {
 	unsigned long result = simple_strtoul(cp, endp, base);
@@ -359,11 +365,16 @@ static int ustrtoul(const char *cp, char
 		result *= 1024;
 	case 'M':
 		result *= 1024;
+	case 'K':
 	case 'k':
 		result *= 1024;
 	/* By dwmw2 editorial decree, "ki", "Mi" or "Gi" are to be used. */
-		if ((*endp)[1] == 'i')
-			(*endp) += 2;
+		if ((*endp)[1] == 'i') {
+			if ((*endp)[2] == 'B')
+				(*endp) += 3;
+			else
+				(*endp) += 2;
+		}
 	}
 	return result;
 }




More information about the linux-mtd-cvs mailing list