diff mbox

ubinfo: allow passing MTD device number

Message ID 1418482828-21290-1-git-send-email-zajec5@gmail.com
State Rejected
Headers show

Commit Message

Rafał Miłecki Dec. 13, 2014, 3 p.m. UTC
This provides a nice way to find if and which UBI device is attached to
the MTD.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
 ubi-utils/ubinfo.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Richard Weinberger Dec. 13, 2014, 7:05 p.m. UTC | #1
On Sat, Dec 13, 2014 at 4:00 PM, Rafał Miłecki <zajec5@gmail.com> wrote:
> This provides a nice way to find if and which UBI device is attached to
> the MTD.

Is it really worth adding this functionality to ubinfo?
One can check /sys/class/ubi/ubiX/mtd_num.

The design behind UBI tools is to work only on UBI device nodes
and not on MTD numbers.
i.e. to keep the layers separated.
Rafał Miłecki Dec. 14, 2014, 12:37 p.m. UTC | #2
On 13 December 2014 at 20:05, Richard Weinberger
<richard.weinberger@gmail.com> wrote:
> On Sat, Dec 13, 2014 at 4:00 PM, Rafał Miłecki <zajec5@gmail.com> wrote:
>> This provides a nice way to find if and which UBI device is attached to
>> the MTD.
>
> Is it really worth adding this functionality to ubinfo?
> One can check /sys/class/ubi/ubiX/mtd_num.

I didn't know about it when asking the questions, should be enough for
me, thanks.
diff mbox

Patch

diff --git a/ubi-utils/ubinfo.c b/ubi-utils/ubinfo.c
index cb88f53..1499d0a 100644
--- a/ubi-utils/ubinfo.c
+++ b/ubi-utils/ubinfo.c
@@ -36,6 +36,7 @@ 
 /* The variables below are set by command line arguments */
 struct args {
 	int devn;
+	int mtdn;
 	int vol_id;
 	int all;
 	const char *node;
@@ -45,6 +46,7 @@  struct args {
 static struct args args = {
 	.vol_id = -1,
 	.devn = -1,
+	.mtdn = -1,
 	.all = 0,
 	.node = NULL,
 	.vol_name = NULL,
@@ -55,6 +57,7 @@  static const char doc[] = PROGRAM_NAME " version " VERSION
 
 static const char optionsstr[] =
 "-d, --devn=<UBI device number>  UBI device number to get information about\n"
+"-m, --mtdn=<MTD device number>  or alternatively, MTD device number\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"
@@ -77,6 +80,7 @@  static const char usage[] =
 
 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 = "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' },
@@ -90,7 +94,7 @@  static int parse_opt(int argc, char * const argv[])
 	while (1) {
 		int key, error = 0;
 
-		key = getopt_long(argc, argv, "an:N:d:hV", long_options, NULL);
+		key = getopt_long(argc, argv, "an:N:d:m:hV", long_options, NULL);
 		if (key == -1)
 			break;
 
@@ -116,6 +120,13 @@  static int parse_opt(int argc, char * const argv[])
 
 			break;
 
+		case 'm':
+			args.mtdn = simple_strtoul(optarg, &error);
+			if (error || args.mtdn < 0)
+				return errmsg("bad MTD device number: \"%s\"", optarg);
+
+			break;
+
 		case 'h':
 			printf("%s\n\n", doc);
 			printf("%s\n\n", usage);
@@ -390,6 +401,15 @@  int main(int argc, char * const argv[])
 		return sys_errmsg("cannot open libubi");
 	}
 
+	if (args.mtdn >= 0) {
+		err = mtd_num2ubi_dev(libubi, args.mtdn, &args.devn);
+		if (err) {
+			sys_errmsg("cannot find UBI device attached to the MTD %d",
+				   args.mtdn);
+			goto out_libubi;
+		}
+	}
+
 	if (args.node) {
 		/*
 		 * A character device was specified, translate this into UBI