aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorentin Chary <corentincj@iksaif.net>2009-09-28 15:10:11 -0400
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-11-24 01:18:54 -0500
commitb57102841846d9840dcb1b8b308f6d7369b8e5c5 (patch)
tree5792c36c373eef0be91714e5a7a3b83d8cf62960
parent648f4e3e50c4793d9dbf9a09afa193631f76fa26 (diff)
UBI: Add ubi_open_volume_path
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. This is needed to teach UBIFS being able to mount UBI character devices. [Comments and the patch were amended a bit by Artem] Signed-off-by: Corentin Chary <corentincj@iksaif.net> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
-rw-r--r--drivers/mtd/ubi/kapi.c40
-rw-r--r--include/linux/mtd/ubi.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 88a72e9c8beb..277786ebaa2c 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -22,6 +22,8 @@
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/namei.h>
26#include <linux/fs.h>
25#include <asm/div64.h> 27#include <asm/div64.h>
26#include "ubi.h" 28#include "ubi.h"
27 29
@@ -280,6 +282,44 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
280EXPORT_SYMBOL_GPL(ubi_open_volume_nm); 282EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
281 283
282/** 284/**
285 * ubi_open_volume_path - open UBI volume by its character device node path.
286 * @pathname: volume character device node path
287 * @mode: open mode
288 *
289 * This function is similar to 'ubi_open_volume()', but opens a volume the path
290 * to its character device node.
291 */
292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
293{
294 int error, ubi_num, vol_id;
295 struct ubi_volume_desc *ret;
296 struct inode *inode;
297 struct path path;
298
299 dbg_gen("open volume %s, mode %d", pathname, mode);
300
301 if (!pathname || !*pathname)
302 return ERR_PTR(-EINVAL);
303
304 error = kern_path(pathname, LOOKUP_FOLLOW, &path);
305 if (error)
306 return ERR_PTR(error);
307
308 inode = path.dentry->d_inode;
309 ubi_num = ubi_major2num(imajor(inode));
310 vol_id = iminor(inode) - 1;
311
312 if (vol_id >= 0 && ubi_num >= 0)
313 ret = ubi_open_volume(ubi_num, vol_id, mode);
314 else
315 ret = ERR_PTR(-ENODEV);
316
317 path_put(&path);
318 return ret;
319}
320EXPORT_SYMBOL_GPL(ubi_open_volume_path);
321
322/**
283 * ubi_close_volume - close UBI volume. 323 * ubi_close_volume - close UBI volume.
284 * @desc: volume descriptor 324 * @desc: volume descriptor
285 */ 325 */
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h
index 6913b71d9ab2..b31bd9e9bca3 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,
174struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode); 174struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
175struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, 175struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
176 int mode); 176 int mode);
177struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode);
178
177int ubi_register_volume_notifier(struct notifier_block *nb, 179int ubi_register_volume_notifier(struct notifier_block *nb,
178 int ignore_existing); 180 int ignore_existing);
179int ubi_unregister_volume_notifier(struct notifier_block *nb); 181int ubi_unregister_volume_notifier(struct notifier_block *nb);