This patch enhances the -s option in the ubi_tools applets to allow a size multiplier of KiB, MiB, or GiB to match the functionality in the ubi tools in the mtd-utils package.
It's based on top of the -m patch I submitted earlier today. Please consider this for inclusion, and let me know if there are any fixes or changes required. Thanks...
>From 23e92bdffda2dacf774b061593aa300501b5f8b3 Mon Sep 17 00:00:00 2001 From: "Paul B. Henson" <[email protected]> Date: Tue, 28 May 2013 18:17:42 -0700 Subject: [PATCH] ubi_tools: enhance -s option to allow size multiplier to match mtd-utils Signed-off-by: Paul B. Henson <[email protected]> --- miscutils/ubi_tools.c | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 48 insertions(+), 9 deletions(-) diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index 6cb7cd5..87dfab0 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,45 @@ //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 int get_bytes(const char *str) +{ + int found; + int size = 0; + char multiplier[4]; + + found = sscanf(str, "%d%3s", &size, multiplier); + + if (found == 2) { + if (!strcmp(multiplier, "KiB")) { + size *= 1024; + } else + if (!strcmp(multiplier, "MiB")) { + size *= 1024*1024; + } else + if (!strcmp(multiplier, "GiB")) { + size *= 1024*1024*1024; + } else { + bb_error_msg_and_die("%s invalid size specifier - should be KiB, MiB or GiB", "UBI"); + } + } + + if (found == 0 || size <= 0) { + bb_error_msg_and_die("%s invalid size", "UBI"); + } + + return size; +} int ubi_tools_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ubi_tools_main(int argc UNUSED_PARAM, char **argv) @@ -138,21 +169,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]; @@ -206,8 +238,11 @@ 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 = get_bytes(size_str); + } 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"); vol_name_len = strlen(vol_name); @@ -239,8 +274,11 @@ 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 = get_bytes(size_str); + } 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"); @@ -279,6 +317,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die("%s could not get LEB size", "UBI"); if (opts & OPTION_s) { + size_bytes = get_bytes(size_str); input_fd = 0; } else { if (!argv[optind+1]) -- 1.7.8.6
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
