Commit f9f4d809a0897317a0235661e934b69040e93e14

Authored by Heiko Schocher
Committed by Tom Rini
1 parent 2dd285f571

common, ubi: add ubi check volumename command

check with this ubi command, if a UBI volume with "volumename"
exists in current ubi device.

Signed-off-by: Heiko Schocher <hs@denx.de>

Showing 1 changed file with 31 additions and 0 deletions Side-by-side Diff

... ... @@ -123,6 +123,27 @@
123 123 return 0;
124 124 }
125 125  
  126 +static int ubi_check_volumename(const struct ubi_volume *vol, char *name)
  127 +{
  128 + return strcmp(vol->name, name);
  129 +}
  130 +
  131 +static int ubi_check(char *name)
  132 +{
  133 + int i;
  134 +
  135 + for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
  136 + if (!ubi->volumes[i])
  137 + continue; /* Empty record */
  138 +
  139 + if (!ubi_check_volumename(ubi->volumes[i], name))
  140 + return 0;
  141 + }
  142 +
  143 + return -EEXIST;
  144 +}
  145 +
  146 +
126 147 static int verify_mkvol_req(const struct ubi_device *ubi,
127 148 const struct ubi_mkvol_req *req)
128 149 {
... ... @@ -558,6 +579,14 @@
558 579 return ubi_info(layout);
559 580 }
560 581  
  582 + if (strcmp(argv[1], "check") == 0) {
  583 + if (argc > 2)
  584 + return ubi_check(argv[2]);
  585 +
  586 + printf("Error, no volume name passed\n");
  587 + return 1;
  588 + }
  589 +
561 590 if (strncmp(argv[1], "create", 6) == 0) {
562 591 int dynamic = 1; /* default: dynamic volume */
563 592  
... ... @@ -663,6 +692,8 @@
663 692 " header offset)\n"
664 693 "ubi info [l[ayout]]"
665 694 " - Display volume and ubi layout information\n"
  695 + "ubi check volumename"
  696 + " - check if volumename exists\n"
666 697 "ubi create[vol] volume [size] [type]"
667 698 " - create volume name with size\n"
668 699 "ubi write[vol] address volume size"