[PATCH] switch mtd and dm-table to lookup_bdev()
No need to open-code it... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
@@ -316,29 +316,12 @@ static inline int check_space(struct dm_table *t)
|
|||||||
*/
|
*/
|
||||||
static int lookup_device(const char *path, dev_t *dev)
|
static int lookup_device(const char *path, dev_t *dev)
|
||||||
{
|
{
|
||||||
int r;
|
struct block_device *bdev = lookup_bdev(path);
|
||||||
struct nameidata nd;
|
if (IS_ERR(bdev))
|
||||||
struct inode *inode;
|
return PTR_ERR(bdev);
|
||||||
|
*dev = bdev->bd_dev;
|
||||||
if ((r = path_lookup(path, LOOKUP_FOLLOW, &nd)))
|
bdput(bdev);
|
||||||
return r;
|
return 0;
|
||||||
|
|
||||||
inode = nd.path.dentry->d_inode;
|
|
||||||
if (!inode) {
|
|
||||||
r = -ENOENT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!S_ISBLK(inode->i_mode)) {
|
|
||||||
r = -ENOTBLK;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
*dev = inode->i_rdev;
|
|
||||||
|
|
||||||
out:
|
|
||||||
path_put(&nd.path);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -125,7 +125,7 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
|
|||||||
int (*fill_super)(struct super_block *, void *, int),
|
int (*fill_super)(struct super_block *, void *, int),
|
||||||
struct vfsmount *mnt)
|
struct vfsmount *mnt)
|
||||||
{
|
{
|
||||||
struct nameidata nd;
|
struct block_device *bdev;
|
||||||
int mtdnr, ret;
|
int mtdnr, ret;
|
||||||
|
|
||||||
if (!dev_name)
|
if (!dev_name)
|
||||||
@@ -181,29 +181,20 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
|
|||||||
/* try the old way - the hack where we allowed users to mount
|
/* try the old way - the hack where we allowed users to mount
|
||||||
* /dev/mtdblock$(n) but didn't actually _use_ the blockdev
|
* /dev/mtdblock$(n) but didn't actually _use_ the blockdev
|
||||||
*/
|
*/
|
||||||
ret = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
|
bdev = lookup_bdev(dev_name);
|
||||||
|
if (IS_ERR(bdev)) {
|
||||||
DEBUG(1, "MTDSB: path_lookup() returned %d, inode %p\n",
|
ret = PTR_ERR(bdev);
|
||||||
ret, nd.path.dentry ? nd.path.dentry->d_inode : NULL);
|
DEBUG(1, "MTDSB: lookup_bdev() returned %d\n", ret);
|
||||||
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
DEBUG(1, "MTDSB: lookup_bdev() returned 0\n");
|
||||||
|
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
if (MAJOR(bdev->bd_dev) != MTD_BLOCK_MAJOR)
|
||||||
if (!S_ISBLK(nd.path.dentry->d_inode->i_mode))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (nd.path.mnt->mnt_flags & MNT_NODEV) {
|
|
||||||
ret = -EACCES;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imajor(nd.path.dentry->d_inode) != MTD_BLOCK_MAJOR)
|
|
||||||
goto not_an_MTD_device;
|
goto not_an_MTD_device;
|
||||||
|
|
||||||
mtdnr = iminor(nd.path.dentry->d_inode);
|
mtdnr = MINOR(bdev->bd_dev);
|
||||||
path_put(&nd.path);
|
bdput(bdev);
|
||||||
|
|
||||||
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
|
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
|
||||||
mnt);
|
mnt);
|
||||||
@@ -213,10 +204,8 @@ not_an_MTD_device:
|
|||||||
printk(KERN_NOTICE
|
printk(KERN_NOTICE
|
||||||
"MTD: Attempt to mount non-MTD device \"%s\"\n",
|
"MTD: Attempt to mount non-MTD device \"%s\"\n",
|
||||||
dev_name);
|
dev_name);
|
||||||
out:
|
bdput(bdev);
|
||||||
path_put(&nd.path);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL_GPL(get_sb_mtd);
|
EXPORT_SYMBOL_GPL(get_sb_mtd);
|
||||||
|
@@ -1236,6 +1236,7 @@ fail:
|
|||||||
bdev = ERR_PTR(error);
|
bdev = ERR_PTR(error);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(lookup_bdev);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* open_bdev_excl - open a block device by name and set it up for use
|
* open_bdev_excl - open a block device by name and set it up for use
|
||||||
|
Reference in New Issue
Block a user