aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Dowle <Reuben.Dowle@navico.com>2011-04-26 04:27:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-04-26 04:27:48 +0200
commita6108423228e5dcd5f3feb31f68c6e46a8ee3123 (patch)
tree3b3c94e33af3ef4f0dcdcb95ff1ee8d815198529
parentab940af5c00fdf3fc46f1d073447cc1aed85efe7 (diff)
downloadbusybox-a6108423228e5dcd5f3feb31f68c6e46a8ee3123.tar.gz
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>
-rw-r--r--miscutils/ubi_attach_detach.c69
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 @@
//config: select PLATFORM_LINUX
//config: help
//config: Resize a UBI volume.
+//config:
+//config:config UBIUPDATEVOL
+//config: bool "ubiupdatevol"
+//config: default y
+//config: select PLATFORM_LINUX
+//config: help
+//config: Update a UBI volume.
//applet:IF_UBIATTACH(APPLET_ODDNAME(ubiattach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach))
//applet:IF_UBIDETACH(APPLET_ODDNAME(ubidetach, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach))
//applet:IF_UBIMKVOL(APPLET_ODDNAME(ubimkvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubimkvol))
//applet:IF_UBIRMVOL(APPLET_ODDNAME(ubirmvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirmvol))
//applet:IF_UBIRSVOL(APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol))
+//applet:IF_UBIUPDATEVOL(APPLET_ODDNAME(ubiupdatevol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiupdatevol))
//kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o
//kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o
//kbuild:lib-$(CONFIG_UBIMKVOL) += ubi_attach_detach.o
//kbuild:lib-$(CONFIG_UBIRMVOL) += ubi_attach_detach.o
//kbuild:lib-$(CONFIG_UBIRSVOL) += ubi_attach_detach.o
+//kbuild:lib-$(CONFIG_UBIUPDATEVOL) += ubi_attach_detach.o
#include "libbb.h"
#include <mtd/ubi-user.h>
@@ -66,6 +75,7 @@
#define do_mkvol (ENABLE_UBIMKVOL && applet_name[3] == 'm')
#define do_rmvol (ENABLE_UBIRMVOL && applet_name[4] == 'm')
#define do_rsvol (ENABLE_UBIRSVOL && applet_name[4] == 's')
+#define do_update (ENABLE_UBIUPDATEVOL && applet_name[3] == 'u')
//usage:#define ubiattach_trivial_usage
//usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV"
@@ -85,7 +95,7 @@
//usage:#define ubimkvol_trivial_usage
//usage: "UBI_DEVICE -N NAME -s SIZE"
//usage:#define ubimkvol_full_usage "\n\n"
-//usage: "Create UBI Volume\n"
+//usage: "Create UBI volume\n"
//usage: "\nOptions:"
//usage: "\n -a ALIGNMENT Volume alignment (default 1)"
//usage: "\n -n VOLID Volume ID, if not specified, it"
@@ -124,8 +134,8 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
int alignment = 1;
char *type = NULL;
- opt_complementary = "=1:m+:d+:n+:s+:a+";
- opts = getopt32(argv, "m:d:n:N:s:a:t:",
+ opt_complementary = "-1:m+:d+:n+:s+:a+";
+ opts = getopt32(argv, "m:d:n:N:s:a:t::",
&mtd_num, &dev_num, &vol_id,
&vol_name, &size_bytes, &alignment, &type
);
@@ -166,7 +176,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
memset(&req, 0, sizeof(req));
req.vol_id = vol_id;
- if (opts & OPTION_t) {
+ if ((opts & OPTION_t) && type) {
if (type[0] == 's')
req.vol_type = UBI_STATIC_VOLUME;
else
@@ -199,6 +209,57 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv)
req.vol_id = vol_id;
xioctl(fd, UBI_IOCRSVOL, &req);
+ } else
+ if (do_update) {
+ long long bytes;
+
+ if (opts & OPTION_t) {
+ // truncate the volume by starting an update for size 0
+ bytes = 0;
+ xioctl(fd, UBI_IOCVOLUP, &bytes);
+ }
+ else {
+ struct stat st;
+ char buf[sizeof("/sys/class/ubi/ubi%d_%d/usable_eb_size") + 2 * sizeof(int)*3];
+ int input_fd;
+ unsigned ubinum, volnum;
+ unsigned leb_size;
+ ssize_t len;
+ char *input_data;
+
+ // Make assumption that device not is in normal format.
+ // Removes need for scanning sysfs tree as full libubi does
+ if (sscanf(ubi_ctrl, "/dev/ubi%u_%u", &ubinum, &volnum) != 2)
+ bb_error_msg_and_die("%s volume node not in correct format", "UBI");
+
+ sprintf(buf, "/sys/class/ubi/ubi%u_%u/usable_eb_size", ubinum, volnum);
+ if (open_read_close(buf, buf, sizeof(buf)) <= 0)
+ bb_error_msg_and_die("%s could not get LEB size", "UBI");
+ if (sscanf(buf, "%u", &leb_size) != 1)
+ bb_error_msg_and_die("%s could not get LEB size", "UBI");
+
+ if (opts & OPTION_s) {
+ input_fd = 0;
+ } else {
+ if (!argv[optind+1])
+ bb_show_usage();
+ xstat(argv[optind+1], &st);
+ size_bytes = st.st_size;
+ input_fd = xopen(argv[optind+1], O_RDONLY);
+ }
+
+ bytes = size_bytes;
+ xioctl(fd, UBI_IOCVOLUP, &bytes);
+
+ input_data = xmalloc(leb_size);
+ while ((len = full_read(input_fd, input_data, leb_size)) > 0) {
+ xwrite(fd, input_data, len);
+ }
+ if (len < 0)
+ bb_error_msg_and_die("%s volume update failed", "UBI");
+ if (ENABLE_FEATURE_CLEAN_UP)
+ close(input_fd);
+ }
}
if (ENABLE_FEATURE_CLEAN_UP)