diff options
| author | Reuben Dowle <Reuben.Dowle@navico.com> | 2011-04-26 04:27:48 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-04-26 04:27:48 +0200 |
| commit | a6108423228e5dcd5f3feb31f68c6e46a8ee3123 (patch) | |
| tree | 3b3c94e33af3ef4f0dcdcb95ff1ee8d815198529 /miscutils | |
| parent | ab940af5c00fdf3fc46f1d073447cc1aed85efe7 (diff) | |
| download | busybox-w32-a6108423228e5dcd5f3feb31f68c6e46a8ee3123.tar.gz busybox-w32-a6108423228e5dcd5f3feb31f68c6e46a8ee3123.tar.bz2 busybox-w32-a6108423228e5dcd5f3feb31f68c6e46a8ee3123.zip | |
ubiupdatevol: new applet
ubi_tools_main 658 1046 +388
packed_usage 28274 28304 +30
applet_names 2396 2409 +13
applet_main 1396 1400 +4
applet_nameofs 698 700 +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 437/0) Total: 437 bytes
Signed-off-by: Reuben Dowle <Reuben.Dowle@navico.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/ubi_attach_detach.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c index e82dc3848..3f7f56e04 100644 --- a/miscutils/ubi_attach_detach.c +++ b/miscutils/ubi_attach_detach.c | |||
| @@ -37,18 +37,27 @@ | |||
| 37 | //config: select PLATFORM_LINUX | 37 | //config: select PLATFORM_LINUX |
| 38 | //config: help | 38 | //config: help |
| 39 | //config: Resize a UBI volume. | 39 | //config: Resize a UBI volume. |
| 40 | //config: | ||
| 41 | //config:config UBIUPDATEVOL | ||
| 42 | //config: bool "ubiupdatevol" | ||
| 43 | //config: default y | ||
| 44 | //config: select PLATFORM_LINUX | ||
| 45 | //config: help | ||
| 46 | //config: Update a UBI volume. | ||
| 40 | 47 | ||
| 41 | //applet:IF_UBIATTACH(APPLET_ODDNAME(ubiattach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach)) | 48 | //applet:IF_UBIATTACH(APPLET_ODDNAME(ubiattach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach)) |
| 42 | //applet:IF_UBIDETACH(APPLET_ODDNAME(ubidetach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach)) | 49 | //applet:IF_UBIDETACH(APPLET_ODDNAME(ubidetach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach)) |
| 43 | //applet:IF_UBIMKVOL(APPLET_ODDNAME(ubimkvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubimkvol)) | 50 | //applet:IF_UBIMKVOL(APPLET_ODDNAME(ubimkvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubimkvol)) |
| 44 | //applet:IF_UBIRMVOL(APPLET_ODDNAME(ubirmvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirmvol)) | 51 | //applet:IF_UBIRMVOL(APPLET_ODDNAME(ubirmvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirmvol)) |
| 45 | //applet:IF_UBIRSVOL(APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol)) | 52 | //applet:IF_UBIRSVOL(APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol)) |
| 53 | //applet:IF_UBIUPDATEVOL(APPLET_ODDNAME(ubiupdatevol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiupdatevol)) | ||
| 46 | 54 | ||
| 47 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o | 55 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o |
| 48 | //kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o | 56 | //kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o |
| 49 | //kbuild:lib-$(CONFIG_UBIMKVOL) += ubi_attach_detach.o | 57 | //kbuild:lib-$(CONFIG_UBIMKVOL) += ubi_attach_detach.o |
| 50 | //kbuild:lib-$(CONFIG_UBIRMVOL) += ubi_attach_detach.o | 58 | //kbuild:lib-$(CONFIG_UBIRMVOL) += ubi_attach_detach.o |
| 51 | //kbuild:lib-$(CONFIG_UBIRSVOL) += ubi_attach_detach.o | 59 | //kbuild:lib-$(CONFIG_UBIRSVOL) += ubi_attach_detach.o |
| 60 | //kbuild:lib-$(CONFIG_UBIUPDATEVOL) += ubi_attach_detach.o | ||
| 52 | 61 | ||
| 53 | #include "libbb.h" | 62 | #include "libbb.h" |
| 54 | #include <mtd/ubi-user.h> | 63 | #include <mtd/ubi-user.h> |
| @@ -66,6 +75,7 @@ | |||
| 66 | #define do_mkvol (ENABLE_UBIMKVOL && applet_name[3] == 'm') | 75 | #define do_mkvol (ENABLE_UBIMKVOL && applet_name[3] == 'm') |
| 67 | #define do_rmvol (ENABLE_UBIRMVOL && applet_name[4] == 'm') | 76 | #define do_rmvol (ENABLE_UBIRMVOL && applet_name[4] == 'm') |
| 68 | #define do_rsvol (ENABLE_UBIRSVOL && applet_name[4] == 's') | 77 | #define do_rsvol (ENABLE_UBIRSVOL && applet_name[4] == 's') |
| 78 | #define do_update (ENABLE_UBIUPDATEVOL && applet_name[3] == 'u') | ||
| 69 | 79 | ||
| 70 | //usage:#define ubiattach_trivial_usage | 80 | //usage:#define ubiattach_trivial_usage |
| 71 | //usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV" | 81 | //usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV" |
| @@ -85,7 +95,7 @@ | |||
| 85 | //usage:#define ubimkvol_trivial_usage | 95 | //usage:#define ubimkvol_trivial_usage |
| 86 | //usage: "UBI_DEVICE -N NAME -s SIZE" | 96 | //usage: "UBI_DEVICE -N NAME -s SIZE" |
| 87 | //usage:#define ubimkvol_full_usage "\n\n" | 97 | //usage:#define ubimkvol_full_usage "\n\n" |
| 88 | //usage: "Create UBI Volume\n" | 98 | //usage: "Create UBI volume\n" |
| 89 | //usage: "\nOptions:" | 99 | //usage: "\nOptions:" |
| 90 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" | 100 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" |
| 91 | //usage: "\n -n VOLID Volume ID, if not specified, it" | 101 | //usage: "\n -n VOLID Volume ID, if not specified, it" |
| @@ -124,8 +134,8 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 124 | int alignment = 1; | 134 | int alignment = 1; |
| 125 | char *type = NULL; | 135 | char *type = NULL; |
| 126 | 136 | ||
| 127 | opt_complementary = "=1:m+:d+:n+:s+:a+"; | 137 | opt_complementary = "-1:m+:d+:n+:s+:a+"; |
| 128 | opts = getopt32(argv, "m:d:n:N:s:a:t:", | 138 | opts = getopt32(argv, "m:d:n:N:s:a:t::", |
| 129 | &mtd_num, &dev_num, &vol_id, | 139 | &mtd_num, &dev_num, &vol_id, |
| 130 | &vol_name, &size_bytes, &alignment, &type | 140 | &vol_name, &size_bytes, &alignment, &type |
| 131 | ); | 141 | ); |
| @@ -166,7 +176,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 166 | 176 | ||
| 167 | memset(&req, 0, sizeof(req)); | 177 | memset(&req, 0, sizeof(req)); |
| 168 | req.vol_id = vol_id; | 178 | req.vol_id = vol_id; |
| 169 | if (opts & OPTION_t) { | 179 | if ((opts & OPTION_t) && type) { |
| 170 | if (type[0] == 's') | 180 | if (type[0] == 's') |
| 171 | req.vol_type = UBI_STATIC_VOLUME; | 181 | req.vol_type = UBI_STATIC_VOLUME; |
| 172 | else | 182 | else |
| @@ -199,6 +209,57 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) | |||
| 199 | req.vol_id = vol_id; | 209 | req.vol_id = vol_id; |
| 200 | 210 | ||
| 201 | xioctl(fd, UBI_IOCRSVOL, &req); | 211 | xioctl(fd, UBI_IOCRSVOL, &req); |
| 212 | } else | ||
| 213 | if (do_update) { | ||
| 214 | long long bytes; | ||
| 215 | |||
| 216 | if (opts & OPTION_t) { | ||
| 217 | // truncate the volume by starting an update for size 0 | ||
| 218 | bytes = 0; | ||
| 219 | xioctl(fd, UBI_IOCVOLUP, &bytes); | ||
| 220 | } | ||
| 221 | else { | ||
| 222 | struct stat st; | ||
| 223 | char buf[sizeof("/sys/class/ubi/ubi%d_%d/usable_eb_size") + 2 * sizeof(int)*3]; | ||
| 224 | int input_fd; | ||
| 225 | unsigned ubinum, volnum; | ||
| 226 | unsigned leb_size; | ||
| 227 | ssize_t len; | ||
| 228 | char *input_data; | ||
| 229 | |||
| 230 | // Make assumption that device not is in normal format. | ||
| 231 | // Removes need for scanning sysfs tree as full libubi does | ||
| 232 | if (sscanf(ubi_ctrl, "/dev/ubi%u_%u", &ubinum, &volnum) != 2) | ||
| 233 | bb_error_msg_and_die("%s volume node not in correct format", "UBI"); | ||
| 234 | |||
| 235 | sprintf(buf, "/sys/class/ubi/ubi%u_%u/usable_eb_size", ubinum, volnum); | ||
| 236 | if (open_read_close(buf, buf, sizeof(buf)) <= 0) | ||
| 237 | bb_error_msg_and_die("%s could not get LEB size", "UBI"); | ||
| 238 | if (sscanf(buf, "%u", &leb_size) != 1) | ||
| 239 | bb_error_msg_and_die("%s could not get LEB size", "UBI"); | ||
| 240 | |||
| 241 | if (opts & OPTION_s) { | ||
| 242 | input_fd = 0; | ||
| 243 | } else { | ||
| 244 | if (!argv[optind+1]) | ||
| 245 | bb_show_usage(); | ||
| 246 | xstat(argv[optind+1], &st); | ||
| 247 | size_bytes = st.st_size; | ||
| 248 | input_fd = xopen(argv[optind+1], O_RDONLY); | ||
| 249 | } | ||
| 250 | |||
| 251 | bytes = size_bytes; | ||
| 252 | xioctl(fd, UBI_IOCVOLUP, &bytes); | ||
| 253 | |||
| 254 | input_data = xmalloc(leb_size); | ||
| 255 | while ((len = full_read(input_fd, input_data, leb_size)) > 0) { | ||
| 256 | xwrite(fd, input_data, len); | ||
| 257 | } | ||
| 258 | if (len < 0) | ||
| 259 | bb_error_msg_and_die("%s volume update failed", "UBI"); | ||
| 260 | if (ENABLE_FEATURE_CLEAN_UP) | ||
| 261 | close(input_fd); | ||
| 262 | } | ||
| 202 | } | 263 | } |
| 203 | 264 | ||
| 204 | if (ENABLE_FEATURE_CLEAN_UP) | 265 | if (ENABLE_FEATURE_CLEAN_UP) |
