aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/kapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/kapi.c')
-rw-r--r--drivers/mtd/ubi/kapi.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 88a72e9c8beb..17f287decc36 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -22,6 +22,9 @@
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/slab.h>
26#include <linux/namei.h>
27#include <linux/fs.h>
25#include <asm/div64.h> 28#include <asm/div64.h>
26#include "ubi.h" 29#include "ubi.h"
27 30
@@ -280,6 +283,43 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
280EXPORT_SYMBOL_GPL(ubi_open_volume_nm); 283EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
281 284
282/** 285/**
286 * ubi_open_volume_path - open UBI volume by its character device node path.
287 * @pathname: volume character device node path
288 * @mode: open mode
289 *
290 * This function is similar to 'ubi_open_volume()', but opens a volume the path
291 * to its character device node.
292 */
293struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
294{
295 int error, ubi_num, vol_id, mod;
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 mod = inode->i_mode;
310 ubi_num = ubi_major2num(imajor(inode));
311 vol_id = iminor(inode) - 1;
312 path_put(&path);
313
314 if (!S_ISCHR(mod))
315 return ERR_PTR(-EINVAL);
316 if (vol_id >= 0 && ubi_num >= 0)
317 return ubi_open_volume(ubi_num, vol_id, mode);
318 return ERR_PTR(-ENODEV);
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 */