summaryrefslogtreecommitdiff
path: root/ubi-utils/new-utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'ubi-utils/new-utils/src')
-rw-r--r--ubi-utils/new-utils/src/libubi.c33
-rw-r--r--ubi-utils/new-utils/src/ubimkvol.c2
-rw-r--r--ubi-utils/new-utils/src/ubirmvol.c47
3 files changed, 74 insertions, 8 deletions
diff --git a/ubi-utils/new-utils/src/libubi.c b/ubi-utils/new-utils/src/libubi.c
index 0fca822..461a402 100644
--- a/ubi-utils/new-utils/src/libubi.c
+++ b/ubi-utils/new-utils/src/libubi.c
@@ -1147,3 +1147,36 @@ int ubi_get_vol_info(libubi_t desc, const char *node, struct ubi_vol_info *info)
return ubi_get_vol_info1(desc, dev_num, vol_id, info);
}
+
+int ubi_get_vol_info1_nm(libubi_t desc, int dev_num, const char *name,
+ struct ubi_vol_info *info)
+{
+ int i, err, nlen = strlen(name);
+ struct ubi_dev_info dev_info;
+
+ if (nlen == 0) {
+ errmsg("bad \"name\" input parameter");
+ errno = EINVAL;
+ return -1;
+ }
+
+ err = ubi_get_dev_info1(desc, dev_num, &dev_info);
+ if (err)
+ return err;
+
+ for (i = dev_info.lowest_vol_id;
+ i <= dev_info.highest_vol_id; i++) {
+ err = ubi_get_vol_info1(desc, dev_num, i, info);
+ if (err == -1) {
+ if (errno == ENOENT)
+ continue;
+ return -1;
+ }
+
+ if (nlen == strlen(info->name) && !strcmp(name, info->name))
+ return 0;
+ }
+
+ errno = ENOENT;
+ return -1;
+}
diff --git a/ubi-utils/new-utils/src/ubimkvol.c b/ubi-utils/new-utils/src/ubimkvol.c
index ad072c4..26ddda2 100644
--- a/ubi-utils/new-utils/src/ubimkvol.c
+++ b/ubi-utils/new-utils/src/ubimkvol.c
@@ -43,7 +43,6 @@ struct args {
int lebs;
int alignment;
const char *name;
- int nlen;
const char *node;
int maxavs;
/* For deprecated -d option handling */
@@ -182,7 +181,6 @@ static int parse_opt(int argc, char * const argv[])
case 'N':
args.name = optarg;
- args.nlen = strlen(args.name);
break;
case 'h':
diff --git a/ubi-utils/new-utils/src/ubirmvol.c b/ubi-utils/new-utils/src/ubirmvol.c
index 10be975..a4cf1df 100644
--- a/ubi-utils/new-utils/src/ubirmvol.c
+++ b/ubi-utils/new-utils/src/ubirmvol.c
@@ -39,6 +39,7 @@
struct args {
int vol_id;
const char *node;
+ const char *name;
/* For deprecated -d option handling */
int devn;
char dev_name[256];
@@ -54,6 +55,7 @@ static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
static const char *optionsstr =
"-n, --vol_id=<volume id> volume ID to remove\n"
+"-N, --name=<volume name> volume name to remove\n"
"-h, -?, --help print help message\n"
"-V, --version print program version\n\n"
"The following is a compatibility option which is deprecated, do not use it\n"
@@ -62,12 +64,16 @@ static const char *optionsstr =
" that the device node is \"/dev/ubi<devn>\"";
static const char *usage =
-"Usage: " PROGRAM_NAME " <UBI device node file name> [-n <volume id>] [--vol_id=<volume id>] [-h] [--help]\n\n"
+"Usage: " PROGRAM_NAME " <UBI device node file name> [-n <volume id>] [--vol_id=<volume id>]\n\n"
+" [-N <volume name>] [--name=<volume name>] [-h] [--help]\n\n"
"Example: " PROGRAM_NAME "/dev/ubi0 -n 1 - remove UBI volume 1 from UBI device corresponding\n"
-" to the node file /dev/ubi0.";
+" to /dev/ubi0\n"
+" " PROGRAM_NAME "/dev/ubi0 -N my_vol - remove UBI named \"my_vol\" from UBI device\n"
+" corresponding to /dev/ubi0";
static const struct option long_options[] = {
{ .name = "vol_id", .has_arg = 1, .flag = NULL, .val = 'n' },
+ { .name = "name", .has_arg = 1, .flag = NULL, .val = 'N' },
{ .name = "help", .has_arg = 0, .flag = NULL, .val = 'h' },
{ .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' },
/* Deprecated -d option */
@@ -77,8 +83,13 @@ static const struct option long_options[] = {
static int param_sanity_check(void)
{
- if (args.vol_id == -1) {
- errmsg("volume ID is was not specified");
+ if (args.vol_id == -1 && !args.name) {
+ errmsg("please, specify either volume ID or volume name");
+ return -1;
+ }
+
+ if (args.vol_id != -1 && args.name) {
+ errmsg("please, specify either volume ID or volume name, not both");
return -1;
}
@@ -91,7 +102,7 @@ static int parse_opt(int argc, char * const argv[])
int key;
char *endp;
- key = getopt_long(argc, argv, "n:h?Vd:", long_options, NULL);
+ key = getopt_long(argc, argv, "n:N:h?Vd:", long_options, NULL);
if (key == -1)
break;
@@ -105,6 +116,10 @@ static int parse_opt(int argc, char * const argv[])
}
break;
+ case 'N':
+ args.name = optarg;
+ break;
+
case 'h':
case '?':
fprintf(stderr, "%s\n\n", doc);
@@ -150,7 +165,6 @@ static int parse_opt(int argc, char * const argv[])
args.node = argv[optind];
}
-
if (param_sanity_check())
return -1;
@@ -180,6 +194,27 @@ int main(int argc, char * const argv[])
goto out_libubi;
}
+ if (args.name) {
+ struct ubi_dev_info dev_info;
+ struct ubi_vol_info vol_info;
+
+ err = ubi_get_dev_info(libubi, args.node, &dev_info);
+ if (err) {
+ sys_errmsg("cannot get information about UBI device \"%s\"",
+ args.node);
+ goto out_libubi;
+ }
+
+ err = ubi_get_vol_info1_nm(libubi, dev_info.dev_num,
+ args.name, &vol_info);
+ if (err) {
+ sys_errmsg("cannot find UBI volume \"%s\"", args.name);
+ goto out_libubi;
+ }
+
+ args.vol_id = vol_info.vol_id;
+ }
+
err = ubi_rmvol(libubi, args.node, args.vol_id);
if (err) {
sys_errmsg("cannot UBI remove volume");