From: Semih Hazar <semih.hazar@indefia.com>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] mkfs.jffs2: Add support for entering the page size in KiB
Date: Tue, 08 May 2007 16:09:35 +0300 [thread overview]
Message-ID: <4640768F.7060703@indefia.com> (raw)
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@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
reply other threads:[~2007-05-08 13:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4640768F.7060703@indefia.com \
--to=semih.hazar@indefia.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.