[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Patch -- add -m option to ubimkvol applet
From:       "Paul B. Henson" <henson () acm ! org>
Date:       2013-05-28 21:44:51
Message-ID: 20130528214451.GP30773 () bender ! unx ! csupomona ! edu
[Download RAW message or body]

The attached patch adds the -m option to the ubimkvol applet to match
the -m option in the full utility in the mtd-utils package, allowing
creation of a volume using whatever space is left free in the partition.

Would you consider incorporating this? Please let me know if anything
needs to be changed or fixed before you might accept it.

Thanks...


["0001-ubimkvol-add-m-option-to-create-volume-of-maximum-si.patch" (text/x-diff)]

From 3a8a7ed7a581333a460af545aa79a903122d65d9 Mon Sep 17 00:00:00 2001
From: "Paul B. Henson" <henson@acm.org>
Date: Tue, 28 May 2013 14:35:29 -0700
Subject: [PATCH] ubimkvol: add -m option to create volume of maximum size

Signed-off-by: Paul B. Henson <henson@acm.org>
---
 miscutils/ubi_tools.c |   45 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index dd99a44..6cb7cd5 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -95,10 +95,11 @@
 //usage:     "\n	-d UBI_NUM	UBI device number"
 //usage:
 //usage:#define ubimkvol_trivial_usage
-//usage:       "UBI_DEVICE -N NAME -s SIZE"
+//usage:       "UBI_DEVICE -N NAME [-s SIZE | -m]"
 //usage:#define ubimkvol_full_usage "\n\n"
 //usage:       "Create UBI volume\n"
 //usage:     "\n	-a ALIGNMENT	Volume alignment (default 1)"
+//usage:     "\n	-m		Set volume size to maximum available"
 //usage:     "\n	-n VOLID	Volume ID, if not specified, it"
 //usage:     "\n			will be assigned automatically"
 //usage:     "\n	-N NAME		Volume name"
@@ -141,11 +142,19 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
 	int alignment = 1;
 	char *type = NULL;
 
-	opt_complementary = "-1:m+:d+:n+:s+:a+";
-	opts = getopt32(argv, "m:d:n:N:s:a:t::",
-			&mtd_num, &dev_num, &vol_id,
-			&vol_name, &size_bytes, &alignment, &type
-	);
+	if (do_mkvol) {
+		opt_complementary = "-1:d+:n+:s+:a+";
+		opts = getopt32(argv, "md:n:N:s:a:t::",
+				&dev_num, &vol_id,
+				&vol_name, &size_bytes, &alignment, &type
+		);
+	} else {
+		opt_complementary = "-1:m+:d+:n+:s+:a+";
+		opts = getopt32(argv, "m:d:n:N:s:a:t::",
+				&mtd_num, &dev_num, &vol_id,
+				&vol_name, &size_bytes, &alignment, &type
+		);
+	}
 	ubi_ctrl = argv[optind];
 
 	fd = xopen(ubi_ctrl, O_RDWR);
@@ -173,6 +182,30 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
 	if (do_mkvol) {
 		struct ubi_mkvol_req req;
 		int vol_name_len;
+		if (opts & OPTION_M) {
+			unsigned leb_avail;
+			unsigned leb_size;
+			unsigned ubinum;
+			char buf[sizeof("/sys/class/ubi/ubi%d/avail_eraseblocks") + sizeof(int)*3];
+
+			if (sscanf(ubi_ctrl, "/dev/ubi%u", &ubinum) != 1)
+				bb_error_msg_and_die("%s device node not in correct format", "UBI");
+
+			sprintf(buf, "/sys/class/ubi/ubi%d/avail_eraseblocks", ubinum);
+			if (open_read_close(buf, buf, sizeof(buf)) <= 0)
+				bb_error_msg_and_die("%s could not get LEB available", "UBI");
+			if (sscanf(buf, "%u", &leb_avail) != 1)
+				bb_error_msg_and_die("%s could not get LEB available", "UBI");
+			sprintf(buf, "/sys/class/ubi/ubi%d/eraseblock_size", ubinum);
+			if (open_read_close(buf, buf, sizeof(buf)) <= 0)
+				bb_error_msg_and_die("%s could not get LEB size", "UBI");
+			if (sscanf(buf, "%u", &leb_size) != 1)
+				bb_error_msg_and_die("%s could not get LEB size", "UBI");
+			size_bytes = leb_avail * leb_size;
+
+			if (size_bytes <= 0)
+				bb_error_msg_and_die("%s invalid maximum size calculated", "UBI");
+		} else
 		if (!(opts & OPTION_s))
 			bb_error_msg_and_die("%s size not specified", "UBI");
 		if (!(opts & OPTION_N))
-- 
1.7.8.6



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic