From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] mtd: ubi: commands: use function API to access ubi volumes
Date: Thu, 22 Sep 2016 09:49:25 +0200 [thread overview]
Message-ID: <1474530566-23625-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1474530566-23625-1-git-send-email-s.hauer@pengutronix.de>
We have a function API to manipulate ubi volumes, use it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/ubi.c | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
diff --git a/commands/ubi.c b/commands/ubi.c
index 26b521f..7c55195 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,39 @@ 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 err1;
+ }
+
+ 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));
+
+err1:
+ ubi_close_volume(desc);
+err:
close(fd);
return ret ? 1 : 0;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-09-22 7:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-22 7:49 Add and use function API for UBI Sascha Hauer
2016-09-22 7:49 ` [PATCH 1/4] mtd: ubi: Add API calls to create/remove volumes Sascha Hauer
2016-09-22 7:49 ` [PATCH 2/4] mtd: ubi: introduce barebox specific ioctl to get ubi_num Sascha Hauer
2016-09-22 7:49 ` Sascha Hauer [this message]
2016-09-22 7:49 ` [PATCH 4/4] mtd: ubi: remove now unused ioctls Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1474530566-23625-4-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox