diff options
author | Sven Eisenberg <sven.eisenberg@novero.com> | 2016-04-03 21:53:12 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-04-03 22:01:43 +0200 |
commit | b068cf2a7e036da8d0b3533b41886c5605c8139d (patch) | |
tree | 0c29bccfabd054c5cafc5dd68e9d161d70bf1286 /miscutils/ubirename.c | |
parent | cb9264099822505dc2930cfea0b1f9027a02dc06 (diff) | |
download | busybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.tar.gz busybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.tar.bz2 busybox-w32-b068cf2a7e036da8d0b3533b41886c5605c8139d.zip |
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 '')
-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 455a49485..d6ccfcb10 100644 --- a/miscutils/ubirename.c +++ b/miscutils/ubirename.c | |||
@@ -30,12 +30,10 @@ | |||
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | // from ubi-media.h | 32 | // from ubi-media.h |
33 | #define UBI_VOL_NAME_MAX 127 | 33 | #define UBI_MAX_VOLUME_NAME 127 |
34 | #define UBI_MAX_VOLUMES 128 | 34 | #define UBI_MAX_VOLUMES 128 |
35 | // end ubi-media.h | 35 | // end ubi-media.h |
36 | 36 | ||
37 | #define UBI_MAX_VOLUME_NAME UBI_VOL_NAME_MAX | ||
38 | |||
39 | // from ubi-user.h | 37 | // from ubi-user.h |
40 | /* ioctl commands of UBI character devices */ | 38 | /* ioctl commands of UBI character devices */ |
41 | #define UBI_IOC_MAGIC 'o' | 39 | #define UBI_IOC_MAGIC 'o' |
@@ -64,7 +62,7 @@ int ubirename_main(int argc, char **argv) | |||
64 | struct ubi_rnvol_req *rnvol; | 62 | struct ubi_rnvol_req *rnvol; |
65 | const char *ubi_devname; | 63 | const char *ubi_devname; |
66 | unsigned ubi_devnum; | 64 | unsigned ubi_devnum; |
67 | unsigned i, n; | 65 | unsigned n; |
68 | 66 | ||
69 | /* argc can be 4, 6, 8, ... */ | 67 | /* argc can be 4, 6, 8, ... */ |
70 | if ((argc & 1) || (argc >>= 1) < 2) | 68 | if ((argc & 1) || (argc >>= 1) < 2) |
@@ -76,27 +74,12 @@ int ubirename_main(int argc, char **argv) | |||
76 | bb_error_msg_and_die("too many renames requested"); | 74 | bb_error_msg_and_die("too many renames requested"); |
77 | 75 | ||
78 | ubi_devname = argv[1]; | 76 | ubi_devname = argv[1]; |
79 | if (sscanf(ubi_devname, "/dev/ubi%u", &ubi_devnum) != 1) | 77 | ubi_devnum = ubi_devnum_from_devname(ubi_devname); |
80 | bb_error_msg_and_die("not a ubi device: '%s'", ubi_devname); | ||
81 | 78 | ||
82 | n = 0; | 79 | n = 0; |
83 | argv += 2; | 80 | argv += 2; |
84 | while (argv[0]) { | 81 | while (argv[0]) { |
85 | for (i = 0; i < UBI_MAX_VOLUMES; i++) { | 82 | rnvol->ents[n].vol_id = get_volid_by_name(ubi_devnum, argv[0]); |
86 | char buf[UBI_VOL_NAME_MAX + 1]; | ||
87 | char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3]; | ||
88 | |||
89 | sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i); | ||
90 | if (open_read_close(fname, buf, sizeof(buf)) <= 0) | ||
91 | continue; | ||
92 | |||
93 | strchrnul(buf, '\n')[0] = '\0'; | ||
94 | if (strcmp(buf, argv[0]) == 0) | ||
95 | goto found; | ||
96 | } | ||
97 | bb_error_msg_and_die("no volume '%s' found", argv[0]); | ||
98 | found: | ||
99 | rnvol->ents[n].vol_id = i; | ||
100 | rnvol->ents[n].name_len = strlen(argv[1]); | 83 | rnvol->ents[n].name_len = strlen(argv[1]); |
101 | if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) | 84 | if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) |
102 | bb_error_msg_and_die("new name '%s' is too long", argv[1]); | 85 | bb_error_msg_and_die("new name '%s' is too long", argv[1]); |