mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Peter Korsgaard <jacmet@sunsite.dk>
To: barebox@lists.infradead.org
Subject: [PATCH] addpart: support @<offset>
Date: Fri, 15 Jan 2010 14:26:51 +0100	[thread overview]
Message-ID: <1263562011-20130-1-git-send-email-jacmet@sunsite.dk> (raw)

We claim to be compatible with the kernel's cmdlinepart parser, so
support <size>@<offset> like the kernel does.

Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
 commands/partition.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index 3cb7b61..b7e2031 100755
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -41,8 +41,10 @@
 #include <linux/stat.h>
 #include <libgen.h>
 
+#define SIZE_REMAINING ((ulong)-1)
+
 static int mtd_part_do_parse_one(char *devname, const char *partstr,
-				 char **endp, unsigned long offset,
+				 char **endp, unsigned long *offset,
 				 off_t devsize, size_t *retsize)
 {
 	ulong size;
@@ -54,12 +56,18 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 	memset(buf, 0, PATH_MAX);
 
 	if (*partstr == '-') {
-		size = devsize - offset;
+		size = SIZE_REMAINING;
 		end = (char *)partstr + 1;
 	} else {
 		size = strtoul_suffix(partstr, &end, 0);
 	}
 
+	if (*end == '@')
+		*offset = strtoul_suffix(end+1, &end, 0);
+
+	if (size == SIZE_REMAINING)
+		size = devsize - *offset;
+
 	partstr = end;
 
 	if (*partstr == '(') {
@@ -76,7 +84,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 		end++;
 	}
 
-	if (size + offset > devsize) {
+	if (size + *offset > devsize) {
 		printf("%s: partition end is beyond device\n", buf);
 		return -EINVAL;
 	}
@@ -93,7 +101,7 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 
 	*retsize = size;
 
-	ret = devfs_add_partition(devname, offset, size, flags, buf);
+	ret = devfs_add_partition(devname, *offset, size, flags, buf);
 	if (ret)
 		printf("cannot create %s: %s\n", buf, strerror(-ret));
 	return ret;
@@ -123,7 +131,7 @@ static int do_addpart(cmd_tbl_t * cmdtp, int argc, char *argv[])
 	while (1) {
 		size_t size = 0;
 
-		if (mtd_part_do_parse_one(devname, endp, &endp, offset, devsize, &size))
+		if (mtd_part_do_parse_one(devname, endp, &endp, &offset, devsize, &size))
 			return 1;
 
 		offset += size;
-- 
1.6.5


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

                 reply	other threads:[~2010-01-15 13:27 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=1263562011-20130-1-git-send-email-jacmet@sunsite.dk \
    --to=jacmet@sunsite.dk \
    --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