* [PATCH 1/4] ubinfo: document the new -N option
@ 2010-04-08 9:04 Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion Artem Bityutskiy
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2010-04-08 9:04 UTC (permalink / raw)
To: linux-mtd; +Cc: Mika Westerberg, Jon Ringle
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
ubi-utils/src/ubinfo.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/ubi-utils/src/ubinfo.c b/ubi-utils/src/ubinfo.c
index cd011c5..8f84382 100644
--- a/ubi-utils/src/ubinfo.c
+++ b/ubi-utils/src/ubinfo.c
@@ -56,6 +56,7 @@ static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
static const char *optionsstr =
"-d, --devn=<UBI device number> UBI device number to get information about\n"
"-n, --vol_id=<volume ID> ID of UBI volume to print information about\n"
+"-N, --name=<volume name> name of UBI volume to print information about\n"
"-a, --all print information about all devices and volumes,\n"
" or about all volumes if the UBI device was\n"
" specified\n"
@@ -63,8 +64,8 @@ static const char *optionsstr =
"-V, --version print program version";
static const char *usage =
-"Usage 1: " PROGRAM_NAME " [-d <UBI device number>] [-n <volume ID>] [-a] [-h] [-V] [--vol_id=<volume ID>]\n"
-"\t\t[--devn <UBI device number>] [--all] [--help] [--version]\n"
+"Usage 1: " PROGRAM_NAME " [-d <UBI device number>] [-n <volume ID> | -N <volume name>] [-a] [-h] [-V]\n"
+"\t\t[--vol_id=<volume ID> | --name <volume name>] [--devn <UBI device number>] [--all] [--help] [--version]\n"
"Usage 2: " PROGRAM_NAME " <UBI device node file name> [-a] [-h] [-V] [--all] [--help] [--version]\n"
"Usage 3: " PROGRAM_NAME " <UBI volume node file name> [-h] [-V] [--help] [--version]\n\n"
"Example 1: " PROGRAM_NAME " - (no arguments) print general UBI information\n"
@@ -77,6 +78,7 @@ static const char *usage =
static const struct option long_options[] = {
{ .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' },
{ .name = "vol_id", .has_arg = 1, .flag = NULL, .val = 'n' },
+ { .name = "name", .has_arg = 1, .flag = NULL, .val = 'N' },
{ .name = "all", .has_arg = 0, .flag = NULL, .val = 'a' },
{ .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
{ .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
--
1.6.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion
2010-04-08 9:04 [PATCH 1/4] ubinfo: document the new -N option Artem Bityutskiy
@ 2010-04-08 9:04 ` Artem Bityutskiy
2010-04-08 16:05 ` Corentin Chary
2010-04-08 9:04 ` [PATCH 3/4] libubi: add support to attach/detach by MTD device path Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 4/4] ubiattach/ubidetach: add support to attach/detach by path Artem Bityutskiy
2 siblings, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2010-04-08 9:04 UTC (permalink / raw)
To: linux-mtd; +Cc: Mika Westerberg, Jon Ringle
From: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
Signed-off-by: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
include/mtd/ubi-user.h | 28 +++++++++++++++++++++-------
1 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 296efae..4b139a6 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -25,11 +25,12 @@
* UBI device creation (the same as MTD device attachment)
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
- * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
- * control device. The caller has to properly fill and pass
- * &struct ubi_attach_req object - UBI will attach the MTD device specified in
- * the request and return the newly created UBI device number as the ioctl
- * return value.
+ * MTD and block devices may be attached using %UBI_IOCATT ioctl command of the
+ * UBI control device. The caller has to properly fill and pass
+ * &struct ubi_attach_req object. If the @bdev_major and @bdev_minor fields
+ * contain zeroes, UBI will attaches MTD device number @mtd_num. Otherwise it
+ * attaches block device with major/minor numbers @bdev_major and @bdev_minor.
+ * The ioctl returns the newly created UBI device number.
*
* UBI device deletion (the same as MTD device detachment)
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -235,14 +236,25 @@ enum {
* @ubi_num: UBI device number to create
* @mtd_num: MTD device number to attach
* @vid_hdr_offset: VID header offset (use defaults if %0)
+ * @bdev_major: major number of the block device to attach
+ * @bdev_minor: minor number of the block device to attach
* @padding: reserved for future, not used, has to be zeroed
*
- * This data structure is used to specify MTD device UBI has to attach and the
+ * This data structure is used to specify the device UBI has to attach and the
* parameters it has to use. The number which should be assigned to the new UBI
* device is passed in @ubi_num. UBI may automatically assign the number if
* @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
* @ubi_num.
*
+ * UBI can attach block and MTD devices. To attach a block device, @bdev_major
+ * and @bdev_minor have to contain block device major an minor numbers. And
+ * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
+ * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
+ * contain zeroes, while @mtd_num has to contain the MTD device number to
+ * attach.
+ *
+ * The rest of the documentation is specific to the MTD device case.
+ *
* Most applications should pass %0 in @vid_hdr_offset to make UBI use default
* offset of the VID header within physical eraseblocks. The default offset is
* the next min. I/O unit after the EC header. For example, it will be offset
@@ -263,7 +275,9 @@ struct ubi_attach_req {
int32_t ubi_num;
int32_t mtd_num;
int32_t vid_hdr_offset;
- int8_t padding[12];
+ int32_t bdev_major;
+ int32_t bdev_minor;
+ int8_t padding[4];
};
/**
--
1.6.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/4] libubi: add support to attach/detach by MTD device path
2010-04-08 9:04 [PATCH 1/4] ubinfo: document the new -N option Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion Artem Bityutskiy
@ 2010-04-08 9:04 ` Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 4/4] ubiattach/ubidetach: add support to attach/detach by path Artem Bityutskiy
2 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2010-04-08 9:04 UTC (permalink / raw)
To: linux-mtd; +Cc: Mika Westerberg, Jon Ringle
From: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
struct ubi_attach_request now has additional field 'dev' that can contain path
to the MTD device node in the filesystem. Also there are two new functions that
are able to handle path to the MTD device node:
ubi_attach() - attach MTD device by number or by path
ubi_detach() - detach MTD device by path
ubi_attach() works like ubi_attach_mtd() when it is passed empty req->dev,
otherwise it looks up correct MTD device number based on the given device node
path.
Signed-off-by: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
ubi-utils/include/libubi.h | 30 ++++++++++
ubi-utils/src/libubi.c | 127 +++++++++++++++++++++++++++++++++++++++-----
ubi-utils/src/libubi_int.h | 1 +
3 files changed, 145 insertions(+), 13 deletions(-)
diff --git a/ubi-utils/include/libubi.h b/ubi-utils/include/libubi.h
index f52904d..64b5eed 100644
--- a/ubi-utils/include/libubi.h
+++ b/ubi-utils/include/libubi.h
@@ -44,6 +44,7 @@ typedef void * libubi_t;
* (%UBI_DEV_NUM_AUTO should be used to automatically assign the
* number)
* @mtd_num: MTD device number to attach
+ * @dev: path to device node to attach
* @vid_hdr_offset: VID header offset (%0 means default offset and this is what
* most of the users want)
*/
@@ -51,6 +52,7 @@ struct ubi_attach_request
{
int dev_num;
int mtd_num;
+ const char *dev;
int vid_hdr_offset;
};
@@ -219,6 +221,23 @@ int ubi_attach_mtd(libubi_t desc, const char *node,
struct ubi_attach_request *req);
/**
+ * ubi_attach - attach an MTD device by its node path.
+ * @desc: UBI library descriptor
+ * @node: name of the UBI control character device node
+ * @req: MTD attach request
+ *
+ * This function creates new UBI device by attaching an MTD device described by
+ * @req. If @req->dev is given it should contain path to the MTD device node.
+ * Otherwise functionality is similar than in function 'ubi_attach_mtd()' where
+ * @req->mtd_num is used.
+ *
+ * Returns %0 in case of success and %-1 in case of failure (errno is set). The
+ * newly created UBI device number is returned in @req->dev_num.
+ */
+int ubi_attach(libubi_t desc, const char *node,
+ struct ubi_attach_request *req);
+
+/**
* ubi_detach_mtd - detach an MTD device.
* @desc: UBI library descriptor
* @node: name of the UBI control character device node
@@ -231,6 +250,17 @@ int ubi_attach_mtd(libubi_t desc, const char *node,
int ubi_detach_mtd(libubi_t desc, const char *node, int mtd_num);
/**
+ * ubi_detach - detach an MTD device by its node path.
+ * @desc: UBI library descriptor
+ * @node: name of the UBI control character device node
+ * @dev: path to an MTD device node
+ *
+ * This function detaches an MTD device @dev from UBI. Returns zero in case of
+ * success and %-1 in case of failure.
+ */
+int ubi_detach(libubi_t desc, const char *node, const char *dev);
+
+/**
* ubi_remove_dev - remove an UBI device.
* @desc: UBI library descriptor
* @node: name of the UBI control character device node
diff --git a/ubi-utils/src/libubi.c b/ubi-utils/src/libubi.c
index fd97774..2f19bd7 100644
--- a/ubi-utils/src/libubi.c
+++ b/ubi-utils/src/libubi.c
@@ -677,35 +677,120 @@ void libubi_close(libubi_t desc)
free(lib);
}
-int ubi_attach_mtd(libubi_t desc, const char *node,
- struct ubi_attach_request *req)
+/**
+ * do_attach - perform the actual attach operation.
+ * @node: name of the UBI control character device node
+ * @r: attach request
+ *
+ * This function performs the actual UBI attach operation. Returns %0 in case of
+ * success and %-1 in case of failure. @r->ubi_num contains newly created UBI
+ * device number.
+ */
+static int do_attach(const char *node, const struct ubi_attach_req *r)
{
int fd, ret;
- struct ubi_attach_req r;
-
- memset(&r, 0, sizeof(struct ubi_attach_req));
-
- desc = desc;
- r.ubi_num = req->dev_num;
- r.mtd_num = req->mtd_num;
- r.vid_hdr_offset = req->vid_hdr_offset;
fd = open(node, O_RDONLY);
if (fd == -1)
return sys_errmsg("cannot open \"%s\"", node);
- ret = ioctl(fd, UBI_IOCATT, &r);
+ ret = ioctl(fd, UBI_IOCATT, r);
close(fd);
if (ret == -1)
return -1;
- req->dev_num = r.ubi_num;
-
#ifdef UDEV_SETTLE_HACK
// if (system("udevsettle") == -1)
// return -1;
usleep(100000);
#endif
+ return ret;
+}
+
+int ubi_attach_mtd(libubi_t desc, const char *node,
+ struct ubi_attach_request *req)
+{
+ struct ubi_attach_req r;
+ int ret;
+
+ (void)desc;
+
+ memset(&r, 0, sizeof(struct ubi_attach_req));
+ r.ubi_num = req->dev_num;
+ r.mtd_num = req->mtd_num;
+ r.vid_hdr_offset = req->vid_hdr_offset;
+
+ ret = do_attach(node, &r);
+ if (ret == 0)
+ req->dev_num = r.ubi_num;
+
+ return ret;
+}
+
+#ifndef MTD_CHAR_MAJOR
+/*
+ * This is taken from kernel <linux/mtd/mtd.h> and is unlikely to change anytime
+ * soon.
+ */
+#define MTD_CHAR_MAJOR 90
+#endif
+
+/**
+ * dev_to_mtdnum - converts device node to MTD number.
+ * @dev: path to device node to convert
+ *
+ * This function converts given @dev to MTD device number. @dev should contain
+ * path to the MTD device node. Returns MTD device number in case of success and
+ * %-1 in case of failure (errno is set).
+ */
+static int dev_to_mtdnum(const char *dev)
+{
+ int major, minor;
+ struct stat sb;
+
+ if (stat(dev, &sb) < 0)
+ return sys_errmsg("cannot stat \"%s\"", dev);
+
+ if (!S_ISCHR(sb.st_mode)) {
+ errno = EINVAL;
+ return sys_errmsg("\"%s\" is not a character device", dev);
+ }
+
+ major = major(sb.st_rdev);
+ minor = minor(sb.st_rdev);
+
+ if (major != MTD_CHAR_MAJOR) {
+ errno = EINVAL;
+ return sys_errmsg("\"%s\" is not an MTD device", dev);
+ }
+
+ return minor / 2;
+}
+
+int ubi_attach(libubi_t desc, const char *node, struct ubi_attach_request *req)
+{
+ struct ubi_attach_req r;
+ int ret;
+
+ if (!req->dev)
+ /* Fallback to opening by mtd_num */
+ return ubi_attach_mtd(desc, node, req);
+
+ memset(&r, 0, sizeof(struct ubi_attach_req));
+ r.ubi_num = req->dev_num;
+ r.vid_hdr_offset = req->vid_hdr_offset;
+
+ /*
+ * User has passed path to device node. Lets find out MTD device number
+ * of the device and pass it to the kernel.
+ */
+ r.mtd_num = dev_to_mtdnum(req->dev);
+ if (r.mtd_num == -1)
+ return -1;
+
+ ret = do_attach(node, &r);
+ if (ret == 0)
+ req->dev_num = r.ubi_num;
return ret;
}
@@ -723,6 +808,22 @@ int ubi_detach_mtd(libubi_t desc, const char *node, int mtd_num)
return ubi_remove_dev(desc, node, ubi_dev);
}
+int ubi_detach(libubi_t desc, const char *node, const char *dev)
+{
+ int mtd_num;
+
+ if (!dev) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ mtd_num = dev_to_mtdnum(dev);
+ if (mtd_num == -1)
+ return -1;
+
+ return ubi_detach_mtd(desc, node, mtd_num);
+}
+
int ubi_remove_dev(libubi_t desc, const char *node, int ubi_dev)
{
int fd, ret;
diff --git a/ubi-utils/src/libubi_int.h b/ubi-utils/src/libubi_int.h
index 6d17d57..c3aa37a 100644
--- a/ubi-utils/src/libubi_int.h
+++ b/ubi-utils/src/libubi_int.h
@@ -83,6 +83,7 @@ extern "C" {
* handling
* @dev_max_vols: maximum volumes number count sysfs path pattern
* @dev_min_io_size: minimum I/O unit size sysfs path pattern
+ * @dev_mtd_num: MTD device number
* @ubi_vol: UBI volume sysfs directory pattern
* @vol_type: volume type sysfs path pattern
* @vol_dev: volume major/minor numbers file pattern
--
1.6.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/4] ubiattach/ubidetach: add support to attach/detach by path
2010-04-08 9:04 [PATCH 1/4] ubinfo: document the new -N option Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 3/4] libubi: add support to attach/detach by MTD device path Artem Bityutskiy
@ 2010-04-08 9:04 ` Artem Bityutskiy
2 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2010-04-08 9:04 UTC (permalink / raw)
To: linux-mtd; +Cc: Mika Westerberg, Jon Ringle
From: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
Now there is a new option '-p' (or '--dev-path') that can be used to pass path
to a MTD device node.
Signed-off-by: Mika Westerberg <ext-mika.1.westerberg@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
ubi-utils/src/ubiattach.c | 35 +++++++++++++++++++--------
ubi-utils/src/ubidetach.c | 57 ++++++++++++++++++++++++++++++--------------
2 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/ubi-utils/src/ubiattach.c b/ubi-utils/src/ubiattach.c
index a935b42..67f8c85 100644
--- a/ubi-utils/src/ubiattach.c
+++ b/ubi-utils/src/ubiattach.c
@@ -39,6 +39,7 @@ struct args {
int mtdn;
int vidoffs;
const char *node;
+ const char *dev;
};
static struct args args = {
@@ -46,6 +47,7 @@ static struct args args = {
.mtdn = -1,
.vidoffs = 0,
.node = NULL,
+ .dev = NULL,
};
static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
@@ -55,7 +57,9 @@ static const char *optionsstr =
"-d, --devn=<UBI device number> the number to assign to the newly created UBI device\n"
" (the number is assigned automatically if this is not\n"
" specified\n"
-"-m, --mtdn=<MTD device number> MTD device number to attach\n"
+"-p, --dev-path=<path to device> path to MTD device node to attach\n"
+"-m, --mtdn=<MTD device number> MTD device number to attach (alternative method, e.g\n"
+" if the character device node does not exist)\n"
"-O, --vid-hdr-offset VID header offset (do not specify this unless you\n"
" really know what you do and the optimal defaults will\n"
" be used)\n"
@@ -63,14 +67,18 @@ static const char *optionsstr =
"-V, --version print program version";
static const char *usage =
-"Usage: " PROGRAM_NAME " <UBI control device node file name> [-m <MTD device number>] [-d <UBI device number>]\n"
-"\t\t[--mtdn=<MTD device number>] [--devn <UBI device number>]\n"
-"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - attach MTD device 0 (mtd0) to UBI\n"
-"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and\n"
+"Usage: " PROGRAM_NAME " <UBI control device node file name>\n"
+"\t[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]\n"
+"\t[--mtdn=<MTD device number>] [--devn=<UBI device number>]\n"
+"\t[--dev-path=<path to device>]\n"
+"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -p /dev/mtd0 - attach /dev/mtd0 to UBI\n"
+"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - attach MTD device 0 (mtd0) to UBI\n"
+"Example 3: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and\n"
" and create UBI device number 3 (ubi3)";
static const struct option long_options[] = {
{ .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' },
+ { .name = "dev-path", .has_arg = 1, .flag = NULL, .val = 'p' },
{ .name = "mtdn", .has_arg = 1, .flag = NULL, .val = 'm' },
{ .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' },
{ .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
@@ -84,11 +92,14 @@ static int parse_opt(int argc, char * const argv[])
int key;
char *endp;
- key = getopt_long(argc, argv, "m:d:O:hV", long_options, NULL);
+ key = getopt_long(argc, argv, "p:m:d:O:hV", long_options, NULL);
if (key == -1)
break;
switch (key) {
+ case 'p':
+ args.dev = optarg;
+ break;
case 'd':
args.devn = strtoul(optarg, &endp, 0);
if (*endp != '\0' || endp == optarg || args.devn < 0)
@@ -134,8 +145,8 @@ static int parse_opt(int argc, char * const argv[])
else if (optind != argc - 1)
return errmsg("more then one UBI control device specified (use -h for help)");
- if (args.mtdn == -1)
- return errmsg("MTD device number was not specified (use -h for help)");
+ if (args.mtdn == -1 && args.dev == NULL)
+ return errmsg("MTD device to attach was not specified (use -h for help)");
args.node = argv[optind];
return 0;
@@ -177,10 +188,14 @@ int main(int argc, char * const argv[])
req.dev_num = args.devn;
req.mtd_num = args.mtdn;
req.vid_hdr_offset = args.vidoffs;
+ req.dev = args.dev;
- err = ubi_attach_mtd(libubi, args.node, &req);
+ err = ubi_attach(libubi, args.node, &req);
if (err) {
- sys_errmsg("cannot attach mtd%d", args.mtdn);
+ if (args.dev)
+ sys_errmsg("cannot attach \"%s\"", args.dev);
+ else
+ sys_errmsg("cannot attach mtd%d", args.mtdn);
goto out_libubi;
}
diff --git a/ubi-utils/src/ubidetach.c b/ubi-utils/src/ubidetach.c
index 83584cd..335486d 100644
--- a/ubi-utils/src/ubidetach.c
+++ b/ubi-utils/src/ubidetach.c
@@ -38,12 +38,14 @@ struct args {
int devn;
int mtdn;
const char *node;
+ const char *dev;
};
static struct args args = {
.devn = UBI_DEV_NUM_AUTO,
.mtdn = -1,
.node = NULL,
+ .dev = NULL,
};
static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
@@ -51,22 +53,26 @@ static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
static const char *optionsstr =
"-d, --devn=<UBI device number> UBI device number to delete\n"
-"-m, --mtdn=<MTD device number> or altrnatively, MTD device number to detach -\n"
-" this will delete corresponding UBI device\n"
+"-p, --dev-path=<path to device> or alternatively, MTD device node path to detach\n"
+"-m, --mtdn=<MTD device number> or alternatively, MTD device number to detach\n"
"-h, --help print help message\n"
"-V, --version print program version";
static const char *usage =
-"Usage: " PROGRAM_NAME "<UBI control device node file name> [-d <UBI device number>] [-m <MTD device number>]\n"
-"\t\t[--devn <UBI device number>] [--mtdn=<MTD device number>]\n"
-"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -d 2 - delete UBI device 2 (ubi2)\n"
-"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - detach MTD device 0 (mtd0)";
+"Usage: " PROGRAM_NAME " <UBI control device node file name>\n"
+"\t[-d <UBI device number>] [-m <MTD device number>] [-p <path to device>]\n"
+"\t[--devn=<UBI device number>] [--mtdn=<MTD device number>]\n"
+"\t[--dev-path=<path to device>]\n"
+"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -p /dev/mtd0 - detach MTD device /dev/mtd0\n"
+"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -d 2 - delete UBI device 2 (ubi2)\n"
+"Example 3: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - detach MTD device 0 (mtd0)";
static const struct option long_options[] = {
- { .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' },
- { .name = "mtdn", .has_arg = 1, .flag = NULL, .val = 'm' },
- { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
- { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
+ { .name = "devn", .has_arg = 1, .flag = NULL, .val = 'd' },
+ { .name = "dev-path", .has_arg = 1, .flag = NULL, .val = 'p' },
+ { .name = "mtdn", .has_arg = 1, .flag = NULL, .val = 'm' },
+ { .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
+ { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
{ NULL, 0, NULL, 0},
};
@@ -76,11 +82,14 @@ static int parse_opt(int argc, char * const argv[])
int key;
char *endp;
- key = getopt_long(argc, argv, "m:d:hV", long_options, NULL);
+ key = getopt_long(argc, argv, "p:m:d:hV", long_options, NULL);
if (key == -1)
break;
switch (key) {
+ case 'p':
+ args.dev = optarg;
+ break;
case 'd':
args.devn = strtoul(optarg, &endp, 0);
if (*endp != '\0' || endp == optarg || args.devn < 0)
@@ -119,11 +128,15 @@ static int parse_opt(int argc, char * const argv[])
else if (optind != argc - 1)
return errmsg("more then one UBI control device specified (use -h for help)");
- if (args.mtdn == -1 && args.devn == -1)
+ if (args.mtdn == -1 && args.devn == -1 && args.dev == NULL)
return errmsg("neither MTD nor UBI devices were specified (use -h for help)");
- if (args.mtdn != -1 && args.devn != -1)
- return errmsg("specify either MTD or UBI device (use -h for help)");
+ if (args.devn != -1) {
+ if (args.mtdn != -1 || args.dev != NULL)
+ return errmsg("specify either MTD or UBI device (use -h for help)");
+
+ } else if (args.mtdn != -1 && args.dev != NULL)
+ return errmsg("specify either MTD number or device node (use -h for help)");
args.node = argv[optind];
return 0;
@@ -167,10 +180,18 @@ int main(int argc, char * const argv[])
goto out_libubi;
}
} else {
- err = ubi_detach_mtd(libubi, args.node, args.mtdn);
- if (err) {
- sys_errmsg("cannot detach mtd%d", args.mtdn);
- goto out_libubi;
+ if (args.dev != NULL) {
+ err = ubi_detach(libubi, args.node, args.dev);
+ if (err) {
+ sys_errmsg("cannot detach \"%s\"", args.dev);
+ goto out_libubi;
+ }
+ } else {
+ err = ubi_detach_mtd(libubi, args.node, args.mtdn);
+ if (err) {
+ sys_errmsg("cannot detach mtd%d", args.mtdn);
+ goto out_libubi;
+ }
}
}
--
1.6.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion
2010-04-08 9:04 ` [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion Artem Bityutskiy
@ 2010-04-08 16:05 ` Corentin Chary
2010-04-08 16:36 ` Artem Bityutskiy
0 siblings, 1 reply; 6+ messages in thread
From: Corentin Chary @ 2010-04-08 16:05 UTC (permalink / raw)
To: Artem Bityutskiy; +Cc: linux-mtd, Mika Westerberg, Jon Ringle
> + * UBI can attach block and MTD devices. To attach a block device, @bdev_major
> + * and @bdev_minor have to contain block device major an minor numbers. And
> + * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
> + * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
> + * contain zeroes, while @mtd_num has to contain the MTD device number to
> + * attach.
I can't find anything about UBI being able to attach block devices in
http://git.infradead.org/ubi-2.6.git,
did I miss something ?
Thanks
--
Corentin Chary
http://xf.iksaif.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion
2010-04-08 16:05 ` Corentin Chary
@ 2010-04-08 16:36 ` Artem Bityutskiy
0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2010-04-08 16:36 UTC (permalink / raw)
To: Corentin Chary; +Cc: linux-mtd, Mika Westerberg, Jon Ringle
On Thu, 2010-04-08 at 18:05 +0200, Corentin Chary wrote:
> > + * UBI can attach block and MTD devices. To attach a block device, @bdev_major
> > + * and @bdev_minor have to contain block device major an minor numbers. And
> > + * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
> > + * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
> > + * contain zeroes, while @mtd_num has to contain the MTD device number to
> > + * attach.
>
> I can't find anything about UBI being able to attach block devices in
> http://git.infradead.org/ubi-2.6.git,
> did I miss something ?
Oh, right. This is wrong patch, sorry, it is not needed. The other are
fine.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-04-08 16:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-08 9:04 [PATCH 1/4] ubinfo: document the new -N option Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion Artem Bityutskiy
2010-04-08 16:05 ` Corentin Chary
2010-04-08 16:36 ` Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 3/4] libubi: add support to attach/detach by MTD device path Artem Bityutskiy
2010-04-08 9:04 ` [PATCH 4/4] ubiattach/ubidetach: add support to attach/detach by path Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).