aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block/ioctl.c29
-rw-r--r--include/linux/fs.h3
2 files changed, 10 insertions, 22 deletions
diff --git a/block/ioctl.c b/block/ioctl.c
index 0db89f95b15f..b4e0abed1b4b 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -265,21 +265,6 @@ static int blkdev_locked_ioctl(struct file *file, struct block_device *bdev,
265 return -ENOIOCTLCMD; 265 return -ENOIOCTLCMD;
266} 266}
267 267
268int blkdev_driver_ioctl(struct inode *inode, struct file *file,
269 struct gendisk *disk, unsigned cmd, unsigned long arg)
270{
271 int ret;
272 fmode_t mode = 0;
273 if (file) {
274 mode = file->f_mode;
275 if (file->f_flags & O_NDELAY)
276 mode |= FMODE_NDELAY_NOW;
277 }
278
279 return __blkdev_driver_ioctl(inode->i_bdev, mode, cmd, arg);
280}
281EXPORT_SYMBOL_GPL(blkdev_driver_ioctl);
282
283int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, 268int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
284 unsigned cmd, unsigned long arg) 269 unsigned cmd, unsigned long arg)
285{ 270{
@@ -315,13 +300,19 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
315 struct block_device *bdev = inode->i_bdev; 300 struct block_device *bdev = inode->i_bdev;
316 struct gendisk *disk = bdev->bd_disk; 301 struct gendisk *disk = bdev->bd_disk;
317 int ret, n; 302 int ret, n;
303 fmode_t mode = 0;
304 if (file) {
305 mode = file->f_mode;
306 if (file->f_flags & O_NDELAY)
307 mode |= FMODE_NDELAY_NOW;
308 }
318 309
319 switch(cmd) { 310 switch(cmd) {
320 case BLKFLSBUF: 311 case BLKFLSBUF:
321 if (!capable(CAP_SYS_ADMIN)) 312 if (!capable(CAP_SYS_ADMIN))
322 return -EACCES; 313 return -EACCES;
323 314
324 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 315 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
325 /* -EINVAL to handle old uncorrected drivers */ 316 /* -EINVAL to handle old uncorrected drivers */
326 if (ret != -EINVAL && ret != -ENOTTY) 317 if (ret != -EINVAL && ret != -ENOTTY)
327 return ret; 318 return ret;
@@ -333,7 +324,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
333 return 0; 324 return 0;
334 325
335 case BLKROSET: 326 case BLKROSET:
336 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 327 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
337 /* -EINVAL to handle old uncorrected drivers */ 328 /* -EINVAL to handle old uncorrected drivers */
338 if (ret != -EINVAL && ret != -ENOTTY) 329 if (ret != -EINVAL && ret != -ENOTTY)
339 return ret; 330 return ret;
@@ -349,7 +340,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
349 case BLKDISCARD: { 340 case BLKDISCARD: {
350 uint64_t range[2]; 341 uint64_t range[2];
351 342
352 if (!(file->f_mode & FMODE_WRITE)) 343 if (!(mode & FMODE_WRITE))
353 return -EBADF; 344 return -EBADF;
354 345
355 if (copy_from_user(range, (void __user *)arg, sizeof(range))) 346 if (copy_from_user(range, (void __user *)arg, sizeof(range)))
@@ -387,6 +378,6 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
387 if (ret != -ENOIOCTLCMD) 378 if (ret != -ENOIOCTLCMD)
388 return ret; 379 return ret;
389 380
390 return blkdev_driver_ioctl(inode, file, disk, cmd, arg); 381 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
391} 382}
392EXPORT_SYMBOL_GPL(blkdev_ioctl); 383EXPORT_SYMBOL_GPL(blkdev_ioctl);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index cb78e389699b..11de682c65a1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1718,9 +1718,6 @@ extern const struct file_operations def_fifo_fops;
1718#ifdef CONFIG_BLOCK 1718#ifdef CONFIG_BLOCK
1719extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); 1719extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1720extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); 1720extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
1721extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1722 struct gendisk *disk, unsigned cmd,
1723 unsigned long arg);
1724extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1721extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1725extern int blkdev_get(struct block_device *, fmode_t); 1722extern int blkdev_get(struct block_device *, fmode_t);
1726extern int blkdev_put(struct block_device *, fmode_t); 1723extern int blkdev_put(struct block_device *, fmode_t);