summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-09-22 09:39:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-09-27 08:15:29 +0200
commit520226a0149b59de3fa1cb5013bf458ee66d16c8 (patch)
tree050d268e479bd1ad48ac364244a64c4ca140652d
parent0f5b72a110b1267e7b101a60b7df7f2ff2985cf6 (diff)
downloadbarebox-520226a0149b59de3fa1cb5013bf458ee66d16c8.tar.gz
barebox-520226a0149b59de3fa1cb5013bf458ee66d16c8.tar.xz
mtd: ubi: commands: use function API to access ubi volumes
We have a function API to manipulate ubi volumes, use it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/ubi.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/commands/ubi.c b/commands/ubi.c
index 26b521f37..2c8fe6ff5 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -9,6 +9,7 @@
#include <linux/kernel.h>
#include <linux/stat.h>
#include <linux/mtd/mtd-abi.h>
+#include <linux/mtd/ubi.h>
#include <mtd/ubi-user.h>
#include <mtd/ubi-media.h>
@@ -104,6 +105,7 @@ static int do_ubimkvol(int argc, char *argv[])
struct ubi_mkvol_req req;
int fd, ret;
uint64_t size;
+ uint32_t ubinum;
req.vol_type = UBI_DYNAMIC_VOLUME;
@@ -140,9 +142,14 @@ static int do_ubimkvol(int argc, char *argv[])
return 1;
}
- ret = ioctl(fd, UBI_IOCMKVOL, &req);
- if (ret)
- printf("failed to create: %s\n", strerror(-ret));
+ ret = ioctl(fd, UBI_IOCGETUBINUM, &ubinum);
+ if (ret) {
+ printf("failed to get ubinum: %s\n", strerror(-ret));
+ goto err;
+ }
+
+ ret = ubi_api_create_volume(ubinum, &req);
+err:
close(fd);
return ret ? 1 : 0;
@@ -272,24 +279,38 @@ BAREBOX_CMD_END
static int do_ubirmvol(int argc, char *argv[])
{
- struct ubi_mkvol_req req;
+ struct ubi_volume_desc *desc;
+ uint32_t ubinum;
int fd, ret;
if (argc != 3)
return COMMAND_ERROR_USAGE;
- strncpy(req.name, argv[2], UBI_VOL_NAME_MAX);
- req.name[UBI_VOL_NAME_MAX] = 0;
-
fd = open(argv[1], O_WRONLY);
if (fd < 0) {
perror("open");
return 1;
}
- ret = ioctl(fd, UBI_IOCRMVOL, &req);
+ ret = ioctl(fd, UBI_IOCGETUBINUM, &ubinum);
+ if (ret) {
+ printf("failed to get ubinum: %s\n", strerror(-ret));
+ goto err;
+ }
+
+ desc = ubi_open_volume_nm(ubinum, argv[2], UBI_EXCLUSIVE);
+ if (IS_ERR(desc)) {
+ ret = PTR_ERR(desc);
+ printf("failed to open volume %s: %s\n", argv[2], strerror(-ret));
+ goto err;
+ }
+
+ ret = ubi_api_remove_volume(desc, 0);
if (ret)
- printf("failed to delete: %s\n", strerror(-ret));
+ printf("failed to remove volume %s: %s\n", argv[2], strerror(-ret));
+
+ ubi_close_volume(desc);
+err:
close(fd);
return ret ? 1 : 0;