Signed-off-by: Paul B. Henson <hen...@acm.org>
---
 miscutils/ubi_tools.c |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c
index f09be8c..6b5d384 100644
--- a/miscutils/ubi_tools.c
+++ b/miscutils/ubi_tools.c
@@ -103,7 +103,8 @@
 //usage:     "\n       -n VOLID        Volume ID, if not specified, it"
 //usage:     "\n                       will be assigned automatically"
 //usage:     "\n       -N NAME         Volume name"
-//usage:     "\n       -s SIZE         Size in bytes"
+//usage:     "\n       -s SIZE         Size in bytes, kilobytes (KiB),"
+//usage:     "\n                       megabytes (MiB), or gigabytes (GiB)"
 //usage:     "\n       -t TYPE         Volume type (static|dynamic)"
 //usage:
 //usage:#define ubirmvol_trivial_usage
@@ -117,15 +118,23 @@
 //usage:#define ubirsvol_full_usage "\n\n"
 //usage:       "Resize UBI volume\n"
 //usage:     "\n       -n VOLID        Volume ID to resize"
-//usage:     "\n       -s SIZE         Size in bytes"
+//usage:     "\n       -s SIZE         Size in bytes, kilobytes (KiB),"
+//usage:     "\n                       megabytes (MiB), or gigabytes (GiB)"
 //usage:
 //usage:#define ubiupdatevol_trivial_usage
 //usage:       "UBI_DEVICE [IMG_FILE]"
 //usage:#define ubiupdatevol_full_usage "\n\n"
 //usage:       "Update UBI volume\n"
 //usage:     "\n       -t      Truncate UBI volume"
-//usage:     "\n       -s SIZE Bytes in input (if reading stdin)"
+//usage:     "\n       -s SIZE Bytes, kilobytes (KiB), megabytes (MiB),"
+//usage:     "\n               or gigabytes (GiB) in input (if reading stdin)"
 
+static const struct suffix_mult size_suffixes[] = {
+{ "KiB", 1024 },
+{ "MiB", 1024*1024 },
+{ "GiB", 1024*1024*1024 },
+{ "", 0 }
+};
 
 int ubi_tools_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
@@ -138,21 +147,22 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
        int dev_num = UBI_DEV_NUM_AUTO;
        int vol_id = UBI_VOL_NUM_AUTO;
        char *vol_name = NULL;
+       char *size_str = NULL;
        int size_bytes;
        int alignment = 1;
        char *type = NULL;
 
        if (do_mkvol) {
-               opt_complementary = "-1:d+:n+:s+:a+";
+               opt_complementary = "-1:d+:n+:a+";
                opts = getopt32(argv, "md:n:N:s:a:t::",
                                &dev_num, &vol_id,
-                               &vol_name, &size_bytes, &alignment, &type
+                               &vol_name, &size_str, &alignment, &type
                        );
        } else {
-               opt_complementary = "-1:m+:d+:n+:s+:a+";
+               opt_complementary = "-1:m+:d+:n+:a+";
                opts = getopt32(argv, "m:d:n:N:s:a:t::",
                                &mtd_num, &dev_num, &vol_id,
-                               &vol_name, &size_bytes, &alignment, &type
+                               &vol_name, &size_str, &alignment, &type
                );
        }
        ubi_ctrl = argv[optind];
@@ -212,7 +222,9 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
                        if (size_bytes <= 0)
                                bb_error_msg_and_die("%s invalid maximum size 
calculated", "UBI");
                } else
-               if (!(opts & OPTION_s))
+               if (opts & OPTION_s)
+                       size_bytes = xstrtou_sfx(size_str, 10, size_suffixes);
+               else
                        bb_error_msg_and_die("%s size not specified", "UBI");
                if (!(opts & OPTION_N))
                        bb_error_msg_and_die("%s name not specified", "UBI");
@@ -245,7 +257,9 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
        } else
        if (do_rsvol) {
                struct ubi_rsvol_req req;
-               if (!(opts & OPTION_s))
+               if (opts & OPTION_s)
+                       size_bytes = xstrtou_sfx(size_str, 10, size_suffixes);
+               else
                        bb_error_msg_and_die("%s size not specified", "UBI");
                if (!(opts & OPTION_n))
                        bb_error_msg_and_die("%s volume id not specified", 
"UBI");
@@ -293,6 +307,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
                        leb_size = xstrtou(buf, 10);
 
                        if (opts & OPTION_s) {
+                               size_bytes = xstrtou_sfx(size_str, 10, 
size_suffixes);
                                input_fd = 0;
                        } else {
                                if (!argv[optind+1])
-- 
1.7.8.6

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

Reply via email to