From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
Oleksij Rempel <linux@rempel-privat.de>
Subject: [PATCH v1] mtd: ubi: add ubi_attach_mtd_path function
Date: Wed, 5 Apr 2017 09:11:35 +0200 [thread overview]
Message-ID: <20170405071135.27974-1-o.rempel@pengutronix.de> (raw)
From: Oleksij Rempel <linux@rempel-privat.de>
Add funktion to attach mtd device by path. This will
reduce some code duplications.
Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
commands/ubi.c | 23 ++---------------------
drivers/mtd/ubi/build.c | 34 ++++++++++++++++++++++++++++++++++
include/mtd/ubi-user.h | 1 +
3 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/commands/ubi.c b/commands/ubi.c
index 5e2758400..795ac3a53 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -174,8 +174,7 @@ BAREBOX_CMD_END
static int do_ubiattach(int argc, char *argv[])
{
int opt;
- struct mtd_info_user user;
- int fd, ret;
+ int ret;
int vid_hdr_offset = 0;
int devnum = UBI_DEV_NUM_AUTO;
@@ -195,25 +194,7 @@ static int do_ubiattach(int argc, char *argv[])
if (optind == argc)
return COMMAND_ERROR_USAGE;
- fd = open(argv[optind], O_RDWR);
- if (fd < 0) {
- perror("open");
- return 1;
- }
-
- ret = ioctl(fd, MEMGETINFO, &user);
- if (ret) {
- printf("MEMGETINFO failed: %s\n", strerror(-ret));
- goto err;
- }
-
- ret = ubi_attach_mtd_dev(user.mtd, devnum, vid_hdr_offset, 20);
- if (ret < 0)
- printf("failed to attach: %s\n", strerror(-ret));
- else
- ret = 0;
-err:
- close(fd);
+ ret = ubi_attach_mtd_path(argv[optind]);
return ret ? 1 : 0;
}
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 2ea66ed06..de8aae729 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -25,6 +25,8 @@
* later using the "UBI control device".
*/
+#include <fs.h>
+#include <ioctl.h>
#include <linux/err.h>
#include <linux/stringify.h>
#include <linux/stat.h>
@@ -684,6 +686,38 @@ out_free:
}
/**
+ * ubi_attach_mtd_path - attach an MTD device by path.
+ * @path: path to MTD device.
+ */
+int ubi_attach_mtd_path(const char *path)
+{
+ struct mtd_info_user user;
+ int fd, ret;
+
+ fd = open(path, O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ return fd;
+ }
+
+ ret = ioctl(fd, MEMGETINFO, &user);
+ if (ret) {
+ pr_err("MEMGETINFO failed: %s\n", strerror(-ret));
+ goto err;
+ }
+
+ ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0, 20);
+ if (ret < 0)
+ pr_err("failed to attach: %s\n", strerror(-ret));
+ else
+ ret = 0;
+err:
+ close(fd);
+
+ return ret;
+}
+
+/**
* ubi_detach_mtd_dev - detach an MTD device.
* @ubi_num: UBI device number to detach from
* @anyway: detach MTD even if device reference count is not zero
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
index 9425533d1..1a1dbb04a 100644
--- a/include/mtd/ubi-user.h
+++ b/include/mtd/ubi-user.h
@@ -408,6 +408,7 @@ struct ubi_set_vol_prop_req {
int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
int vid_hdr_offset, int max_beb_per1024);
+int ubi_attach_mtd_path(const char *path);
int ubi_detach(int ubi_num);
int ubi_num_get_by_mtd(struct mtd_info *mtd);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2017-04-05 7:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20170405071135.27974-1-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=linux@rempel-privat.de \
/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