diff mbox

[1/2] UBI: Add ubi_open_volume_path()

Message ID 1254165012-10798-1-git-send-email-corentincj@iksaif.net
State New, archived
Headers show

Commit Message

Corentin Chary Sept. 28, 2009, 7:10 p.m. UTC
Add an ubi_open_volume_path(path, mode) function which works like
open_bdev_exclusive(path, mode, ...) where path is the special file
representing the UBI volume, typically /dev/ubi0_0.

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 drivers/mtd/ubi/kapi.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/ubi.h |    2 ++
 2 files changed, 42 insertions(+), 0 deletions(-)

Comments

Artem Bityutskiy Sept. 29, 2009, 2:27 p.m. UTC | #1
On Mon, 2009-09-28 at 21:10 +0200, Corentin Chary wrote:
> Add an ubi_open_volume_path(path, mode) function which works like
> open_bdev_exclusive(path, mode, ...) where path is the special file
> representing the UBI volume, typically /dev/ubi0_0.
> 
> Signed-off-by: Corentin Chary <corentincj@iksaif.net>

Looks good, and actually works. And I like that I can now do:

mount -t ubifs /dev/ubi_whatever_name /mnt/ubifs

And when your user-space changes hit distros, I will not have to
even specify -t ubifs.

I'm not entirely sure vs the 'kern_path()' usage though. Could you
please post your patch to these lists as well:

linux-fsdevel@vger.kernel.org
linux-kernel@vger.kernel.org

I'll push your patches to the ubi-2.6.git now, but I would not want to
make these changes sneak into mainline without being sent to lkml, just
because I'm not entirely sure about the 'kern_path()'. But for me this
looks ok.

Thanks!
diff mbox

Patch

diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 88a72e9..d711aa7 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -22,6 +22,8 @@ 
 
 #include <linux/module.h>
 #include <linux/err.h>
+#include <linux/namei.h>
+#include <linux/fs.h>
 #include <asm/div64.h>
 #include "ubi.h"
 
@@ -280,6 +282,44 @@  struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
 EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
 
 /**
+ * ubi_open_volume_path - open UBI volume by path.
+ * @ubi_num: UBI device number
+ * @pathname: volume path
+ * @mode: open mode
+ *
+ * This function is similar to 'ubi_open_volume()', but opens a volume by name.
+ */
+struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
+{
+	int error, ubi_num, vol_id;
+	struct ubi_volume_desc *ret;
+	struct inode *inode;
+	struct path path;
+
+	dbg_gen("open volume %s, mode %d", pathname, mode);
+
+	if (!pathname || !*pathname)
+		return ERR_PTR(-EINVAL);
+
+	error = kern_path(pathname, LOOKUP_FOLLOW, &path);
+	if (error)
+		return ERR_PTR(error);
+
+	inode = path.dentry->d_inode;
+	ubi_num = ubi_major2num(imajor(inode));
+	vol_id = iminor(inode) - 1;
+
+	if (vol_id >= 0 && ubi_num >= 0)
+		ret = ubi_open_volume(ubi_num, vol_id, mode);
+	else
+		ret = ERR_PTR(-ENODEV);
+
+	path_put(&path);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(ubi_open_volume_path);
+
+/**
  * ubi_close_volume - close UBI volume.
  * @desc: volume descriptor
  */
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index 6913b71..b31bd9e 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -174,6 +174,8 @@  void ubi_get_volume_info(struct ubi_volume_desc *desc,
 struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
 struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
 					   int mode);
+struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode);
+
 int ubi_register_volume_notifier(struct notifier_block *nb,
 				 int ignore_existing);
 int ubi_unregister_volume_notifier(struct notifier_block *nb);