/* This function is similar to 'ubi_open_volume()', but opens a volume the path to its character device node.  */
struct ubi_volume_desc* ubi_open_volume_path(const char *pathname, int mode)
/* This function is similar to 'ubi_open_volume()', but opens a volume the path to its character device node.  */
struct ubi_volume_desc* ubi_open_volume_path(const char *pathname, int mode)
{
	int error, ubi_num, vol_id, mod;
	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;
	mod = inode->i_mode;
	ubi_num = ubi_major2num(imajor(inode));
	vol_id = iminor(inode) - 1;
	path_put(&path);
	if (!S_ISCHR(mod))
		return ERR_PTR(-EINVAL);
	if (vol_id >= 0 && ubi_num >= 0)
		return ubi_open_volume(ubi_num, vol_id, mode);
	return ERR_PTR(-ENODEV);
}