diff options
author | Reuben Dowle <reuben.dowle at navico.com> | 2011-02-05 03:18:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-05 03:18:08 +0100 |
commit | 3e2834fe72b023155904e118c4f71a8ff73a90ec (patch) | |
tree | c4ed77745acfdf1fd7608f2e143f52c71db6a21c /miscutils | |
parent | 046341e8bd91a2a2c0d44b40217fa1c5ce1dd949 (diff) | |
download | busybox-w32-3e2834fe72b023155904e118c4f71a8ff73a90ec.tar.gz busybox-w32-3e2834fe72b023155904e118c4f71a8ff73a90ec.tar.bz2 busybox-w32-3e2834fe72b023155904e118c4f71a8ff73a90ec.zip |
ubimkvol,ubirmvol,ubirsvol: new applets
function old new delta
ubi_tools_main - 658 +658
packed_usage 28269 28376 +107
bbconfig_config_bz2 4968 5007 +39
applet_names 2407 2434 +27
applet_main 1396 1408 +12
applet_nameofs 698 704 +6
applet_install_loc 175 176 +1
ubi_attach_detach_main 175 - -175
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 6/0 up/down: 850/-175) Total: 675 bytes
Signed-off-by: Reuben Dowle <reuben.dowle at navico.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/ubi_attach_detach.c | 154 |
1 files changed, 136 insertions, 18 deletions
diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c index aa8a5171a..fef9250ee 100644 --- a/miscutils/ubi_attach_detach.c +++ b/miscutils/ubi_attach_detach.c | |||
@@ -3,34 +3,69 @@ | |||
3 | * Licensed under GPLv2, see file LICENSE in this source tree. | 3 | * Licensed under GPLv2, see file LICENSE in this source tree. |
4 | */ | 4 | */ |
5 | 5 | ||
6 | //applet:IF_UBIATTACH(APPLET_ODDNAME(ubiattach, ubi_attach_detach, BB_DIR_USR_SBIN, BB_SUID_DROP, ubiattach)) | ||
7 | //applet:IF_UBIDETACH(APPLET_ODDNAME(ubidetach, ubi_attach_detach, BB_DIR_USR_SBIN, BB_SUID_DROP, ubidetach)) | ||
8 | |||
9 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o | ||
10 | //kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o | ||
11 | |||
12 | //config:config UBIATTACH | 6 | //config:config UBIATTACH |
13 | //config: bool "ubiattach" | 7 | //config: bool "ubiattach" |
14 | //config: default n | 8 | //config: default y |
15 | //config: depends on PLATFORM_LINUX | 9 | //config: depends on PLATFORM_LINUX |
16 | //config: help | 10 | //config: help |
17 | //config: Attach MTD device to an UBI device. | 11 | //config: Attach MTD device to an UBI device. |
18 | //config: | 12 | //config: |
19 | //config:config UBIDETACH | 13 | //config:config UBIDETACH |
20 | //config: bool "ubidetach" | 14 | //config: bool "ubidetach" |
21 | //config: default n | 15 | //config: default y |
22 | //config: depends on PLATFORM_LINUX | 16 | //config: depends on PLATFORM_LINUX |
23 | //config: help | 17 | //config: help |
24 | //config: Detach MTD device from an UBI device. | 18 | //config: Detach MTD device from an UBI device. |
19 | //config: | ||
20 | //config:config UBIMKVOL | ||
21 | //config: bool "ubimkvol" | ||
22 | //config: default y | ||
23 | //config: depends on PLATFORM_LINUX | ||
24 | //config: help | ||
25 | //config: Create a UBI volume. | ||
26 | //config: | ||
27 | //config:config UBIRMVOL | ||
28 | //config: bool "ubirmvol" | ||
29 | //config: default y | ||
30 | //config: depends on PLATFORM_LINUX | ||
31 | //config: help | ||
32 | //config: Delete a UBI volume. | ||
33 | //config: | ||
34 | //config:config UBIRSVOL | ||
35 | //config: bool "ubirsvol" | ||
36 | //config: default y | ||
37 | //config: depends on PLATFORM_LINUX | ||
38 | //config: help | ||
39 | //config: Resize a UBI volume. | ||
40 | |||
41 | //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)) | ||
43 | //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)) | ||
45 | //applet:IF_UBIRSVOL(APPLET_ODDNAME(ubirsvol, ubi_tools, BB_DIR_USR_SBIN, BB_SUID_DROP, ubirsvol)) | ||
46 | |||
47 | //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o | ||
48 | //kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o | ||
49 | //kbuild:lib-$(CONFIG_UBIMKVOL) += ubi_attach_detach.o | ||
50 | //kbuild:lib-$(CONFIG_UBIRMVOL) += ubi_attach_detach.o | ||
51 | //kbuild:lib-$(CONFIG_UBIRSVOL) += ubi_attach_detach.o | ||
25 | 52 | ||
26 | #include "libbb.h" | 53 | #include "libbb.h" |
27 | #include <mtd/ubi-user.h> | 54 | #include <mtd/ubi-user.h> |
28 | 55 | ||
29 | #define OPTION_M (1 << 0) | 56 | #define OPTION_M (1 << 0) |
30 | #define OPTION_D (1 << 1) | 57 | #define OPTION_D (1 << 1) |
31 | 58 | #define OPTION_n (1 << 2) | |
32 | #define do_attach (ENABLE_UBIATTACH && \ | 59 | #define OPTION_N (1 << 3) |
33 | (!ENABLE_UBIDETACH || (applet_name[3] == 'a'))) | 60 | #define OPTION_s (1 << 4) |
61 | #define OPTION_a (1 << 5) | ||
62 | #define OPTION_t (1 << 6) | ||
63 | |||
64 | #define do_attach (ENABLE_UBIATTACH && applet_name[3] == 'a') | ||
65 | #define do_detach (ENABLE_UBIDETACH && applet_name[3] == 'd') | ||
66 | #define do_mkvol (ENABLE_UBIMKVOL && applet_name[3] == 'm') | ||
67 | #define do_rmvol (ENABLE_UBIRMVOL && applet_name[4] == 'm') | ||
68 | #define do_rsvol (ENABLE_UBIRSVOL && applet_name[4] == 's') | ||
34 | 69 | ||
35 | //usage:#define ubiattach_trivial_usage | 70 | //usage:#define ubiattach_trivial_usage |
36 | //usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV" | 71 | //usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV" |
@@ -46,20 +81,54 @@ | |||
46 | //usage: "Detach MTD device from UBI\n" | 81 | //usage: "Detach MTD device from UBI\n" |
47 | //usage: "\nOptions:" | 82 | //usage: "\nOptions:" |
48 | //usage: "\n -d UBI_NUM UBI device number" | 83 | //usage: "\n -d UBI_NUM UBI device number" |
84 | //usage: | ||
85 | //usage:#define ubimkvol_trivial_usage | ||
86 | //usage: "UBI_DEVICE -N NAME -s SIZE" | ||
87 | //usage:#define ubimkvol_full_usage "\n\n" | ||
88 | //usage: "Create UBI Volume\n" | ||
89 | //usage: "\nOptions:" | ||
90 | //usage: "\n -a ALIGNMENT Volume alignment (default 1)" | ||
91 | //usage: "\n -n VOLID Volume ID, if not specified, it" | ||
92 | //usage: "\n will be assigned automatically" | ||
93 | //usage: "\n -N NAME Volume name" | ||
94 | //usage: "\n -s SIZE Size in bytes" | ||
95 | //usage: "\n -t TYPE Volume type (static|dynamic)" | ||
96 | //usage: | ||
97 | //usage:#define ubirmvol_trivial_usage | ||
98 | //usage: "UBI_DEVICE -n VOLID" | ||
99 | //usage:#define ubirmvol_full_usage "\n\n" | ||
100 | //usage: "Remove UBI Volume\n" | ||
101 | //usage: "\nOptions:" | ||
102 | //usage: "\n -n VOLID Volume ID" | ||
103 | //usage: | ||
104 | //usage:#define ubirsvol_trivial_usage | ||
105 | //usage: "UBI_DEVICE -N NAME -s SIZE" | ||
106 | //usage:#define ubirsvol_full_usage "\n\n" | ||
107 | //usage: "Resize UBI Volume\n" | ||
108 | //usage: "\nOptions:" | ||
109 | //usage: "\n -N NAME Volume name" | ||
110 | //usage: "\n -s SIZE Size in bytes" | ||
49 | 111 | ||
50 | int ubi_attach_detach_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 112 | int ubi_tools_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
51 | int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv) | 113 | int ubi_tools_main(int argc UNUSED_PARAM, char **argv) |
52 | { | 114 | { |
53 | unsigned opts; | 115 | unsigned opts; |
54 | char *ubi_ctrl; | 116 | char *ubi_ctrl; |
55 | //struct stat st; | 117 | //struct stat st; |
56 | struct ubi_attach_req req; | ||
57 | int fd; | 118 | int fd; |
58 | int mtd_num; | 119 | int mtd_num; |
59 | int dev_num = UBI_DEV_NUM_AUTO; | 120 | int dev_num = UBI_DEV_NUM_AUTO; |
60 | 121 | int vol_id = UBI_VOL_NUM_AUTO; | |
61 | opt_complementary = "=1:m+:d+"; | 122 | char *vol_name = NULL; |
62 | opts = getopt32(argv, "m:d:", &mtd_num, &dev_num); | 123 | int size_bytes; |
124 | int alignment = 1; | ||
125 | char *type = NULL; | ||
126 | |||
127 | opt_complementary = "=1:m+:d+:n+:s+:a+"; | ||
128 | opts = getopt32(argv, "m:d:n:N:s:a:t:", | ||
129 | &mtd_num, &dev_num, &vol_id, | ||
130 | &vol_name, &size_bytes, &alignment, &type | ||
131 | ); | ||
63 | ubi_ctrl = argv[optind]; | 132 | ubi_ctrl = argv[optind]; |
64 | 133 | ||
65 | fd = xopen(ubi_ctrl, O_RDWR); | 134 | fd = xopen(ubi_ctrl, O_RDWR); |
@@ -68,6 +137,7 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv) | |||
68 | // bb_error_msg_and_die("%s: not a char device", ubi_ctrl); | 137 | // bb_error_msg_and_die("%s: not a char device", ubi_ctrl); |
69 | 138 | ||
70 | if (do_attach) { | 139 | if (do_attach) { |
140 | struct ubi_attach_req req; | ||
71 | if (!(opts & OPTION_M)) | 141 | if (!(opts & OPTION_M)) |
72 | bb_error_msg_and_die("%s device not specified", "MTD"); | 142 | bb_error_msg_and_die("%s device not specified", "MTD"); |
73 | 143 | ||
@@ -76,11 +146,59 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv) | |||
76 | req.ubi_num = dev_num; | 146 | req.ubi_num = dev_num; |
77 | 147 | ||
78 | xioctl(fd, UBI_IOCATT, &req); | 148 | xioctl(fd, UBI_IOCATT, &req); |
79 | } else { /* detach */ | 149 | } else |
150 | if (do_detach) { | ||
80 | if (!(opts & OPTION_D)) | 151 | if (!(opts & OPTION_D)) |
81 | bb_error_msg_and_die("%s device not specified", "UBI"); | 152 | bb_error_msg_and_die("%s device not specified", "UBI"); |
82 | 153 | ||
83 | xioctl(fd, UBI_IOCDET, &dev_num); | 154 | xioctl(fd, UBI_IOCDET, &dev_num); |
155 | } else | ||
156 | if (do_mkvol) { | ||
157 | struct ubi_mkvol_req req; | ||
158 | int vol_name_len; | ||
159 | if (!(opts & OPTION_s)) | ||
160 | bb_error_msg_and_die("%s size not specified", "UBI"); | ||
161 | if (!(opts & OPTION_N)) | ||
162 | bb_error_msg_and_die("%s name not specified", "UBI"); | ||
163 | vol_name_len = strlen(vol_name); | ||
164 | if (vol_name_len > UBI_MAX_VOLUME_NAME) | ||
165 | bb_error_msg_and_die("%s volume name too long", "UBI"); | ||
166 | |||
167 | memset(&req, 0, sizeof(req)); | ||
168 | req.vol_id = vol_id; | ||
169 | if (opts & OPTION_t) { | ||
170 | if (type[0] == 's') | ||
171 | req.vol_type = UBI_STATIC_VOLUME; | ||
172 | else | ||
173 | req.vol_type = UBI_DYNAMIC_VOLUME; | ||
174 | } else { | ||
175 | req.vol_type = UBI_DYNAMIC_VOLUME; | ||
176 | } | ||
177 | req.alignment = alignment; | ||
178 | req.bytes = size_bytes; | ||
179 | strncpy(req.name, vol_name, UBI_MAX_VOLUME_NAME); | ||
180 | req.name_len = vol_name_len; | ||
181 | |||
182 | xioctl(fd, UBI_IOCMKVOL, &req); | ||
183 | } else | ||
184 | if (do_rmvol) { | ||
185 | if (!(opts & OPTION_n)) | ||
186 | bb_error_msg_and_die("%s volume id not specified", "UBI"); | ||
187 | |||
188 | xioctl(fd, UBI_IOCRMVOL, &vol_id); | ||
189 | } else | ||
190 | if (do_rsvol) { | ||
191 | struct ubi_rsvol_req req; | ||
192 | if (!(opts & OPTION_s)) | ||
193 | bb_error_msg_and_die("%s size not specified", "UBI"); | ||
194 | if (!(opts & OPTION_n)) | ||
195 | bb_error_msg_and_die("%s volume id not specified", "UBI"); | ||
196 | |||
197 | memset(&req, 0, sizeof(req)); | ||
198 | req.bytes = size_bytes; | ||
199 | req.vol_id = vol_id; | ||
200 | |||
201 | xioctl(fd, UBI_IOCRSVOL, &req); | ||
84 | } | 202 | } |
85 | 203 | ||
86 | if (ENABLE_FEATURE_CLEAN_UP) | 204 | if (ENABLE_FEATURE_CLEAN_UP) |