1 /* Ported to busybox from mtd-utils.
3 * Licensed under GPLv2, see file LICENSE in this tarball for details.
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))
9 //kbuild:lib-$(CONFIG_UBIATTACH) += ubi_attach_detach.o
10 //kbuild:lib-$(CONFIG_UBIDETACH) += ubi_attach_detach.o
12 //config:config UBIATTACH
13 //config: bool "ubiattach"
16 //config: Attach MTD device to an UBI device.
18 //config:config UBIDETACH
19 //config: bool "ubidetach"
22 //config: Detach MTD device from an UBI device.
25 #include <mtd/ubi-user.h>
27 #define OPTION_M (1 << 0)
28 #define OPTION_D (1 << 1)
30 #define do_attach (ENABLE_UBIATTACH && \
31 (!ENABLE_UBIDETACH || (applet_name[3] == 'a')))
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"
38 //usage: "\n -m MTD_NUM MTD device number to attach"
39 //usage: "\n -d UBI_NUM UBI device number to assign"
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"
46 //usage: "\n -d UBI_NUM UBI device number"
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)
54 struct ubi_attach_req req;
57 int dev_num = UBI_DEV_NUM_AUTO;
59 opt_complementary = "=1:m+:d+";
60 opts = getopt32(argv, "m:d:", &mtd_num, &dev_num);
61 ubi_ctrl = argv[optind];
63 fd = xopen(ubi_ctrl, O_RDWR);
65 //if (!S_ISCHR(st.st_mode))
66 // bb_error_msg_and_die("'%s' is not a char device", ubi_ctrl);
69 if (!(opts & OPTION_M))
70 bb_error_msg_and_die("%s device not specified", "MTD");
72 memset(&req, 0, sizeof(req));
73 req.mtd_num = mtd_num;
74 req.ubi_num = dev_num;
76 xioctl(fd, UBI_IOCATT, &req);
78 if (!(opts & OPTION_D))
79 bb_error_msg_and_die("%s device not specified", "UBI");
81 xioctl(fd, UBI_IOCDET, &dev_num);
84 if (ENABLE_FEATURE_CLEAN_UP)