mirror of
git://sourceware.org/git/lvm2.git
synced 2024-10-27 10:25:13 +03:00
Error checking: only allow block devices & test for 'nodev'.
This commit is contained in:
parent
8424428faf
commit
7c913930fe
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/list.h>
|
||||
#include <asm/atomic.h>
|
||||
@ -129,20 +130,35 @@ struct block_device *dm_blkdev_get(const char *path)
|
||||
struct nameidata nd;
|
||||
struct inode *inode;
|
||||
struct block_device *bdev;
|
||||
int err = -ENOENT;
|
||||
|
||||
if (!path_init(path, LOOKUP_FOLLOW, &nd))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (path_walk(path, &nd))
|
||||
return ERR_PTR(-EINVAL);
|
||||
if (path_init(path, LOOKUP_FOLLOW, &nd))
|
||||
err = path_walk(path, &nd);
|
||||
|
||||
if (err) {
|
||||
bdev = ERR_PTR(err);
|
||||
goto out;
|
||||
}
|
||||
|
||||
inode = nd.dentry->d_inode;
|
||||
|
||||
if (!inode) {
|
||||
bdev = ERR_PTR(-ENOENT);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!S_ISBLK(inode->i_mode)) {
|
||||
bdev = ERR_PTR(-ENOTBLK);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (nd.mnt->mnt_flags & MNT_NODEV) {
|
||||
bdev = ERR_PTR(-EACCES);
|
||||
goto out;
|
||||
}
|
||||
|
||||
bdev = dm_get_device(inode->i_bdev);
|
||||
|
||||
out:
|
||||
path_release(&nd);
|
||||
return bdev;
|
||||
|
@ -61,10 +61,19 @@ static int linear_ctr(struct dm_table *t, offset_t b, offset_t l,
|
||||
|
||||
dm_txt_copy(path, sizeof(path) - 1, &word);
|
||||
|
||||
|
||||
bdev = dm_blkdev_get(path);
|
||||
if (IS_ERR(bdev)) {
|
||||
fn("no such device", private);
|
||||
switch (PTR_ERR(bdev)) {
|
||||
case -ENOTBLK:
|
||||
fn("not a block device", private);
|
||||
break;
|
||||
case -EACCES:
|
||||
fn("nodev mount option", private);
|
||||
break;
|
||||
case -ENOENT:
|
||||
default:
|
||||
fn("no such device", private);
|
||||
}
|
||||
return PTR_ERR(bdev);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user