mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 10/17] cmdlinepart: add function to parse a cmdline partition string
Date: Thu, 12 Feb 2015 09:54:27 +0100	[thread overview]
Message-ID: <1423731274-9860-11-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1423731274-9860-1-git-send-email-s.hauer@pengutronix.de>

This adds a function to parse a full cmdline partition string. The
addpart command is switched to use this function.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/partition.c  | 25 +------------------------
 include/cmdlinepart.h |  3 +++
 lib/cmdlinepart.c     | 28 ++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index 17ca136..64ccaf0 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -41,8 +41,6 @@
 static int do_addpart(int argc, char *argv[])
 {
 	char *devname;
-	const char *endp;
-	loff_t offset = 0;
 	loff_t devsize;
 	struct stat s;
 	int opt;
@@ -67,28 +65,7 @@ static int do_addpart(int argc, char *argv[])
 
 	devname = basename(argv[optind]);
 
-	endp = argv[optind + 1];
-
-	while (1) {
-		loff_t size = 0;
-
-		if (cmdlinepart_do_parse_one(devname, endp, &endp, &offset,
-					devsize, &size, flags))
-			return 1;
-
-		offset += size;
-
-		if (!*endp)
-			break;
-
-		if (*endp != ',') {
-			printf("parse error\n");
-			return 1;
-		}
-		endp++;
-	}
-
-	return 0;
+	return cmdlinepart_do_parse(devname, argv[optind + 1], devsize, flags);
 }
 
 BAREBOX_CMD_HELP_START(addpart)
diff --git a/include/cmdlinepart.h b/include/cmdlinepart.h
index 3f8e136..bf8cdfa 100644
--- a/include/cmdlinepart.h
+++ b/include/cmdlinepart.h
@@ -8,4 +8,7 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 				 loff_t devsize, loff_t *retsize,
 				 unsigned int partition_flags);
 
+int cmdlinepart_do_parse(const char *devname, const char *parts, loff_t devsize,
+		unsigned partition_flags);
+
 #endif /* __CMD_LINE_PART_H */
diff --git a/lib/cmdlinepart.c b/lib/cmdlinepart.c
index 9351587..df6f17a 100644
--- a/lib/cmdlinepart.c
+++ b/lib/cmdlinepart.c
@@ -93,3 +93,31 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 
 	return ret;
 }
+
+int cmdlinepart_do_parse(const char *devname, const char *parts, loff_t devsize,
+		unsigned partition_flags)
+{
+	loff_t offset = 0;
+	int ret;
+
+	while (1) {
+		loff_t size = 0;
+
+		ret = cmdlinepart_do_parse_one(devname, parts, &parts, &offset,
+				devsize, &size, partition_flags);
+		if (ret)
+			return ret;
+
+		offset += size;
+		if (!*parts)
+			break;
+
+		if (*parts != ',') {
+			printf("parse error\n");
+			return -EINVAL;
+		}
+		parts++;
+	}
+
+	return 0;
+}
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-02-12  8:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12  8:54 mtd partition handling updates Sascha Hauer
2015-02-12  8:54 ` [PATCH 01/17] of: Add for_each_child_of_node_safe Sascha Hauer
2015-02-12  8:54 ` [PATCH 02/17] mtd: core: add error checks Sascha Hauer
2015-02-12  8:54 ` [PATCH 03/17] mtd: partitions: Use xstrdup Sascha Hauer
2015-02-12  8:54 ` [PATCH 04/17] mtd: partitions: Add error check Sascha Hauer
2015-02-12  8:54 ` [PATCH 05/17] mtd: Add partitions to list Sascha Hauer
2015-02-12  8:54 ` [PATCH 06/17] mtd: nand: remove automatically created bb devices Sascha Hauer
2015-02-12  8:54 ` [PATCH 07/17] move cmdline partition parsing code to separate file Sascha Hauer
2015-02-12  8:54 ` [PATCH 08/17] cmdlinepart: Change SIZE_REMAINING to loff_t Sascha Hauer
2015-02-12  8:54 ` [PATCH 09/17] cmdlinepart: make argument types safer Sascha Hauer
2015-02-12  8:54 ` Sascha Hauer [this message]
2015-02-12  8:54 ` [PATCH 11/17] cmndlinepart: skip devname if partstr already contains it Sascha Hauer
2015-02-12  8:54 ` [PATCH 12/17] mtd: forbid conflicting mtd partitions Sascha Hauer
2015-02-12  8:54 ` [PATCH 13/17] mtd: Use flags parameter in mtd_add_partition Sascha Hauer
2015-02-12  8:54 ` [PATCH 14/17] mtd: Add a partitions parameter to mtd devices Sascha Hauer
2015-02-12  8:54 ` [PATCH 15/17] mtd: fixup device tree partitions Sascha Hauer
2015-02-12  8:54 ` [PATCH 16/17] defaultenv-2: mtdparts-add: remove unused variable Sascha Hauer
2015-02-12  8:54 ` [PATCH 17/17] defaultenv-2: mtdparts-add: Use new partition parameter Sascha Hauer
2015-02-13  5:54 ` mtd partition handling updates Bo Shen

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=1423731274-9860-11-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox