[PATCH] mkfs.jffs2: Add support for entering the page size in KiB

Semih Hazar semih.hazar at indefia.com
Tue May 8 09:09:35 EDT 2007


mkfs.jffs2 doesn't understand page size when given in KiB. This patch 
fixes that so short forms are supported both in erase size and page size.

Signed-off-by: Semih Hazar <semih.hazar at indefia.com>
---
mkfs.jffs2.c |   56 +++++++++++++++++++++++++++++++++++---------------------
1 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/mkfs.jffs2.c b/mkfs.jffs2.c
index bc9901e..0011817 100644
--- a/mkfs.jffs2.c
+++ b/mkfs.jffs2.c
@@ -168,6 +168,34 @@ static void perror_msg_and_die(const char *s, ...)
	exit(EXIT_FAILURE);
}

+int tobytes(const char* str)
+{
+	char *unit;
+	int mul;
+	int val = strtol(str, &unit, 0);
+
+	if (!val)
+		return val;
+
+	if (*unit) {
+		if (!strcmp(unit, "KiB")) {
+			mul = 1024;
+		} else if (!strcmp(unit, "MiB")) {
+			mul = 1024 * 1024;
+		} else {
+			return -1;
+		}
+	} else {
+		if (val < 0x1000) {
+			mul = 1024;
+		} else {
+			mul = 1;
+		}
+	}
+	
+	return val * mul;
+}
+
#ifndef DMALLOC
extern void *xmalloc(size_t size)
{
@@ -1641,7 +1669,10 @@ int main(int argc, char **argv)
				break;

			case 's':
-				page_size = strtol(optarg, NULL, 0);
+				page_size = tobytes(optarg);
+				if (page_size<0) {
+					error_msg_and_die("Unrecognisable page size\n");
+				}		  
				break;

			case 'o':
@@ -1684,28 +1715,11 @@ int main(int argc, char **argv)
						(int) strlen(revtext) - 13, revtext + 11);

			case 'e': {
-						  char *next;
-						  unsigned units = 0;
-						  erase_block_size = strtol(optarg, &next, 0);
-						  if (!erase_block_size)
+						  erase_block_size = tobytes(optarg);
+						  
+						  if (erase_block_size<0)
							  error_msg_and_die("Unrecognisable erase size\n");

-						  if (*next) {
-							  if (!strcmp(next, "KiB")) {
-								  units = 1024;
-							  } else if (!strcmp(next, "MiB")) {
-								  units = 1024 * 1024;
-							  } else {
-								  error_msg_and_die("Unknown units in erasesize\n");
-							  }
-						  } else {
-							  if (erase_block_size < 0x1000)
-								  units = 1024;
-							  else
-								  units = 1;
-						  }
-						  erase_block_size *= units;
-
						  /* If it's less than 8KiB, they're not allowed */
						  if (erase_block_size < 0x2000) {
							  fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
-- 
1.4.4.2






More information about the linux-mtd mailing list