diff options
author | Sven Eisenberg | 2016-04-03 21:53:12 +0200 |
---|---|---|
committer | Denys Vlasenko | 2016-04-03 22:01:43 +0200 |
commit | b068cf2a7e036da8d0b3533b41886c5605c8139d (patch) | |
tree | 0c29bccfabd054c5cafc5dd68e9d161d70bf1286 /miscutils/ubirename.c | |
parent | cb9264099822505dc2930cfea0b1f9027a02dc06 (diff) | |
download | busybox-b068cf2a7e036da8d0b3533b41886c5605c8139d.zip busybox-b068cf2a7e036da8d0b3533b41886c5605c8139d.tar.gz |
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/ubirename.c')
-rw-r--r-- | miscutils/ubirename.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c index 455a494..d6ccfcb 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]); |