diff options
author | Baruch Siach <baruch@tkos.co.il> | 2010-06-16 12:22:58 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-16 12:22:58 +0200 |
commit | 3324c963352392c00bda9eb77b815f0db9f6bdb7 (patch) | |
tree | 0053177f482da723eb211b5d73896bc01e63d606 | |
parent | 4f731ce30ec2a9f5e9b231b47aa68f32b75feb35 (diff) | |
download | busybox-w32-3324c963352392c00bda9eb77b815f0db9f6bdb7.tar.gz busybox-w32-3324c963352392c00bda9eb77b815f0db9f6bdb7.tar.bz2 busybox-w32-3324c963352392c00bda9eb77b815f0db9f6bdb7.zip |
ubiattach,ubidetach: new applets
function old new delta
ubi_attach_detach_main - 175 +175
packed_usage 27056 27136 +80
applet_names 2262 2282 +20
applet_main 1328 1336 +8
applet_nameofs 664 668 +4
applet_install_loc 166 167 +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/0 up/down: 288/0) Total: 288 bytes
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/ubi_attach_detach.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c new file mode 100644 index 000000000..7b92a8afc --- /dev/null +++ b/miscutils/ubi_attach_detach.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* Ported to busybox from mtd-utils. | ||
2 | * | ||
3 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
4 | */ | ||
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 | ||
13 | //config: bool "ubiattach" | ||
14 | //config: default n | ||
15 | //config: help | ||
16 | //config: Attach MTD device to an UBI device. | ||
17 | //config: | ||
18 | //config:config UBIDETACH | ||
19 | //config: bool "ubidetach" | ||
20 | //config: default n | ||
21 | //config: help | ||
22 | //config: Detach MTD device from an UBI device. | ||
23 | |||
24 | #include "libbb.h" | ||
25 | #include <mtd/ubi-user.h> | ||
26 | |||
27 | #define OPTION_M (1 << 0) | ||
28 | #define OPTION_D (1 << 1) | ||
29 | |||
30 | #define do_attach (ENABLE_UBIATTACH && \ | ||
31 | (!ENABLE_UBIDETACH || (applet_name[3] == 'a'))) | ||
32 | |||
33 | //usage:#define ubiattach_trivial_usage | ||
34 | //usage: "-m MTD_NUM [-d UBI_NUM] UBI_CTRL_DEV" | ||
35 | //usage:#define ubiattach_full_usage "\n\n" | ||
36 | //usage: "Attach MTD device to UBI\n" | ||
37 | //usage: "\nOptions:" | ||
38 | //usage: "\n -m MTD_NUM MTD device number to attach" | ||
39 | //usage: "\n -d UBI_NUM UBI device number to assign" | ||
40 | //usage: | ||
41 | //usage:#define ubidetach_trivial_usage | ||
42 | //usage: "-d UBI_NUM UBI_CTRL_DEV" | ||
43 | //usage:#define ubidetach_full_usage "\n\n" | ||
44 | //usage: "Detach MTD device from UBI\n" | ||
45 | //usage: "\nOptions:" | ||
46 | //usage: "\n -d UBI_NUM UBI device number" | ||
47 | |||
48 | int ubi_attach_detach_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
49 | int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv) | ||
50 | { | ||
51 | unsigned opts; | ||
52 | char *ubi_ctrl; | ||
53 | //struct stat st; | ||
54 | struct ubi_attach_req req; | ||
55 | int fd; | ||
56 | int mtd_num; | ||
57 | int dev_num = UBI_DEV_NUM_AUTO; | ||
58 | |||
59 | opt_complementary = "=1:m+:d+"; | ||
60 | opts = getopt32(argv, "m:d:", &mtd_num, &dev_num); | ||
61 | ubi_ctrl = argv[optind]; | ||
62 | |||
63 | fd = xopen(ubi_ctrl, O_RDWR); | ||
64 | //fstat(fd, &st); | ||
65 | //if (!S_ISCHR(st.st_mode)) | ||
66 | // bb_error_msg_and_die("'%s' is not a char device", ubi_ctrl); | ||
67 | |||
68 | if (do_attach) { | ||
69 | if (!(opts & OPTION_M)) | ||
70 | bb_error_msg_and_die("%s device not specified", "MTD"); | ||
71 | |||
72 | memset(&req, 0, sizeof(req)); | ||
73 | req.mtd_num = mtd_num; | ||
74 | req.ubi_num = dev_num; | ||
75 | |||
76 | xioctl(fd, UBI_IOCATT, &req); | ||
77 | } else { /* detach */ | ||
78 | if (!(opts & OPTION_D)) | ||
79 | bb_error_msg_and_die("%s device not specified", "UBI"); | ||
80 | |||
81 | xioctl(fd, UBI_IOCDET, &dev_num); | ||
82 | } | ||
83 | |||
84 | if (ENABLE_FEATURE_CLEAN_UP) | ||
85 | close(fd); | ||
86 | |||
87 | return EXIT_SUCCESS; | ||
88 | } | ||