12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "libbb.h"
- #include <mtd/mtd-user.h>
- #ifndef __packed
- # define __packed __attribute__((packed))
- #endif
- #define UBI_MAX_VOLUME_NAME 127
- #define UBI_MAX_VOLUMES 128
- #define UBI_IOC_MAGIC 'o'
- #define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)
- #define UBI_MAX_RNVOL 32
- struct ubi_rnvol_req {
- int32_t count;
- int8_t padding1[12];
- struct {
- int32_t vol_id;
- int16_t name_len;
- int8_t padding2[2];
- char name[UBI_MAX_VOLUME_NAME + 1];
- } ents[UBI_MAX_RNVOL];
- } __packed;
- int ubirename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int ubirename_main(int argc, char **argv)
- {
- struct ubi_rnvol_req *rnvol;
- const char *ubi_devname;
- unsigned ubi_devnum;
- unsigned n;
-
- if ((argc & 1) || (argc >>= 1) < 2)
- bb_show_usage();
- rnvol = xzalloc(sizeof(*rnvol));
- rnvol->count = --argc;
- if (argc > ARRAY_SIZE(rnvol->ents))
- bb_simple_error_msg_and_die("too many renames requested");
- ubi_devname = argv[1];
- ubi_devnum = ubi_devnum_from_devname(ubi_devname);
- n = 0;
- argv += 2;
- while (argv[0]) {
- rnvol->ents[n].vol_id = ubi_get_volid_by_name(ubi_devnum, argv[0]);
-
- rnvol->ents[n].name_len = strnlen(argv[1], sizeof(rnvol->ents[n].name));
- if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name))
- bb_error_msg_and_die("new name '%s' is too long", argv[1]);
- strcpy(rnvol->ents[n].name, argv[1]);
- n++;
- argv += 2;
- }
- xioctl(xopen(ubi_devname, O_RDONLY), UBI_IOCRNVOL, rnvol);
- return 0;
- }
|