diff options
author | Sven Eisenberg <sven.eisenberg@novero.com> | 2016-04-03 22:53:12 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-03 23:01:43 +0300 |
commit | b068cf2a7e036da8d0b3533b41886c5605c8139d (patch) | |
tree | 0c29bccfabd054c5cafc5dd68e9d161d70bf1286 /miscutils | |
parent | cb9264099822505dc2930cfea0b1f9027a02dc06 (diff) |
ubirmvol: Implement -N switch for ubirmvol
function old new delta
get_volid_by_name - 125 +125
ubi_devnum_from_devname - 43 +43
ubi_tools_main 1215 1220 +5
packed_usage 30674 30655 -19
ubirename_main 394 221 -173
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 1/2 up/down: 173/-192) Total: -19 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/ubi_tools.c | 29 | ||||
-rw-r--r-- | miscutils/ubirename.c | 25 |
2 files changed, 23 insertions, 31 deletions
diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index dd1bda300..ac0c56d6b 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -195,7 +195,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubimkvol_trivial_usage -//usage: "UBI_DEVICE -N NAME [-s SIZE | -m]" +//usage: "-N NAME [-s SIZE | -m] UBI_DEVICE" //usage:#define ubimkvol_full_usage "\n\n" //usage: "Create UBI volume\n" //usage: "\n -a ALIGNMENT Volume alignment (default 1)" @@ -212,9 +212,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) unsigned num; char *p; - if (sscanf(ubi_ctrl, "/dev/ubi%u", &num) != 1) - bb_error_msg_and_die("wrong format of UBI device name"); - + num = ubi_devnum_from_devname(ubi_ctrl); p = path_sys_class_ubi_ubi + sprintf(path_sys_class_ubi_ubi, "%u/", num); strcpy(p, "avail_eraseblocks"); @@ -248,20 +246,31 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubirmvol_trivial_usage -//usage: "UBI_DEVICE -n VOLID" +//usage: "-n VOLID / -N VOLNAME UBI_DEVICE" //usage:#define ubirmvol_full_usage "\n\n" //usage: "Remove UBI volume\n" //usage: "\n -n VOLID Volume ID" +//usage: "\n -N VOLNAME Volume name" if (do_rmvol) { - if (!(opts & OPTION_n)) + if (!(opts & (OPTION_n|OPTION_N))) bb_error_msg_and_die("volume id not specified"); - /* FIXME? kernel expects int32_t* here: */ - xioctl(fd, UBI_IOCRMVOL, &vol_id); + if (opts & OPTION_N) { + unsigned num = ubi_devnum_from_devname(ubi_ctrl); + vol_id = get_volid_by_name(num, vol_name); + } + + if (sizeof(vol_id) != 4) { + /* kernel expects int32_t* in this ioctl */ + int32_t t = vol_id; + xioctl(fd, UBI_IOCRMVOL, &t); + } else { + xioctl(fd, UBI_IOCRMVOL, &vol_id); + } } else //usage:#define ubirsvol_trivial_usage -//usage: "UBI_DEVICE -n VOLID -s SIZE" +//usage: "-n VOLID -s SIZE UBI_DEVICE" //usage:#define ubirsvol_full_usage "\n\n" //usage: "Resize UBI volume\n" //usage: "\n -n VOLID Volume ID" @@ -279,7 +288,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubiupdatevol_trivial_usage -//usage: "UBI_DEVICE [-t | [-s SIZE] IMG_FILE]" +//usage: "[-t | [-s SIZE] IMG_FILE] UBI_DEVICE" //usage:#define ubiupdatevol_full_usage "\n\n" //usage: "Update UBI volume\n" //usage: "\n -t Truncate to zero size" diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c index 455a49485..d6ccfcb10 100644 --- a/miscutils/ubirename.c +++ b/miscutils/ubirename.c @@ -30,12 +30,10 @@ #endif // from ubi-media.h -#define UBI_VOL_NAME_MAX 127 +#define UBI_MAX_VOLUME_NAME 127 #define UBI_MAX_VOLUMES 128 // end ubi-media.h -#define UBI_MAX_VOLUME_NAME UBI_VOL_NAME_MAX - // from ubi-user.h /* ioctl commands of UBI character devices */ #define UBI_IOC_MAGIC 'o' @@ -64,7 +62,7 @@ int ubirename_main(int argc, char **argv) struct ubi_rnvol_req *rnvol; const char *ubi_devname; unsigned ubi_devnum; - unsigned i, n; + unsigned n; /* argc can be 4, 6, 8, ... */ if ((argc & 1) || (argc >>= 1) < 2) @@ -76,27 +74,12 @@ int ubirename_main(int argc, char **argv) bb_error_msg_and_die("too many renames requested"); ubi_devname = argv[1]; - if (sscanf(ubi_devname, "/dev/ubi%u", &ubi_devnum) != 1) - bb_error_msg_and_die("not a ubi device: '%s'", ubi_devname); + ubi_devnum = ubi_devnum_from_devname(ubi_devname); n = 0; argv += 2; while (argv[0]) { - for (i = 0; i < UBI_MAX_VOLUMES; i++) { - char buf[UBI_VOL_NAME_MAX + 1]; - char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3]; - - sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i); - if (open_read_close(fname, buf, sizeof(buf)) <= 0) - continue; - - strchrnul(buf, '\n')[0] = '\0'; - if (strcmp(buf, argv[0]) == 0) - goto found; - } - bb_error_msg_and_die("no volume '%s' found", argv[0]); - found: - rnvol->ents[n].vol_id = i; + rnvol->ents[n].vol_id = get_volid_by_name(ubi_devnum, argv[0]); rnvol->ents[n].name_len = strlen(argv[1]); if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) bb_error_msg_and_die("new name '%s' is too long", argv[1]); |