[PATCH 4/8] mtd: ubi: Add support for opening a volume by cdev

Sascha Hauer s.hauer at pengutronix.de
Tue Aug 6 09:07:04 EDT 2013


Needed by ubifs support.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/ubi/cdev.c  |  6 ++++++
 drivers/mtd/ubi/kapi.c  | 17 +++++++++++++++++
 drivers/mtd/ubi/ubi.h   |  2 ++
 include/linux/mtd/ubi.h |  1 +
 4 files changed, 26 insertions(+)

diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 3907673..129f2e2 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -5,6 +5,8 @@
 #include "ubi-barebox.h"
 #include "ubi.h"
 
+LIST_HEAD(ubi_volumes_list);
+
 struct ubi_volume_cdev_priv {
 	struct ubi_device *ubi;
 	struct ubi_volume *vol;
@@ -184,6 +186,8 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
 		free(cdev->name);
 	}
 
+	list_add_tail(&vol->list, &ubi_volumes_list);
+
 	return 0;
 }
 
@@ -192,6 +196,8 @@ void ubi_volume_cdev_remove(struct ubi_volume *vol)
 	struct cdev *cdev = &vol->cdev;
 	struct ubi_volume_cdev_priv *priv = cdev->priv;
 
+	list_del(&vol->list);
+
 	devfs_remove(cdev);
 	kfree(cdev->name);
 	kfree(priv);
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 23ac234..31571ad 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -265,6 +265,23 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
 }
 EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
 
+extern struct list_head ubi_volumes_list;
+
+struct ubi_volume_desc *ubi_open_volume_cdev(struct cdev *cdev, int mode)
+{
+	struct ubi_volume *vol;
+
+	list_for_each_entry(vol, &ubi_volumes_list, list) {
+		if (cdev == &vol->cdev)
+			goto found;
+	}
+
+	return ERR_PTR(-ENOENT);
+
+found:
+	return ubi_open_volume(vol->ubi->ubi_num, vol->vol_id, mode);
+}
+
 /**
  * ubi_close_volume - close UBI volume.
  * @desc: volume descriptor
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 11877a3..aa2cf02 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -322,6 +322,8 @@ struct ubi_volume {
 	unsigned int updating:1;
 	unsigned int changing_leb:1;
 	unsigned int direct_writes:1;
+
+	struct list_head list;
 };
 
 /**
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index b3288d1..274ec4e 100644
--- a/include/linux/mtd/ubi.h
+++ b/include/linux/mtd/ubi.h
@@ -200,6 +200,7 @@ 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_cdev(struct cdev *cdev, int mode);
 struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode);
 
 void ubi_close_volume(struct ubi_volume_desc *desc);
-- 
1.8.4.rc1




More information about the barebox mailing list