aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2007-10-09 07:23:51 -0400
committerJens Axboe <axboe@carl.home.kernel.dk>2007-10-10 03:26:00 -0400
commitf58c4c0a17e500e767473598b3deafaa1d64051d (patch)
treef8fbf3a2ce10a9fccf41f2f96bca1ca71b3dd77e /block
parentd2bbf3da3759d04cd5836955cc59c8ae96092831 (diff)
compat_ioctl: move common block ioctls to compat_blkdev_ioctl
Make compat_blkdev_ioctl and blkdev_ioctl reflect the respective native versions. This is somewhat more efficient and makes it easier to keep the two in sync. Also get rid of the bogus handling for broken_blkgetsize and the duplicate entry for BLKRASET. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block')
-rw-r--r--block/Makefile1
-rw-r--r--block/compat_ioctl.c121
-rw-r--r--block/ioctl.c21
3 files changed, 126 insertions, 17 deletions
diff --git a/block/Makefile b/block/Makefile
index 959feeb253be..3cfe7cebaa6a 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o
11obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o 11obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
12 12
13obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o 13obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
14obj-$(CONFIG_COMPAT) += compat_ioctl.o
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
new file mode 100644
index 000000000000..d20fdb436f68
--- /dev/null
+++ b/block/compat_ioctl.c
@@ -0,0 +1,121 @@
1#include <linux/blkdev.h>
2#include <linux/blkpg.h>
3#include <linux/blktrace_api.h>
4#include <linux/cdrom.h>
5#include <linux/compat.h>
6#include <linux/elevator.h>
7#include <linux/fd.h>
8#include <linux/hdreg.h>
9#include <linux/syscalls.h>
10#include <linux/smp_lock.h>
11#include <linux/types.h>
12#include <linux/uaccess.h>
13
14static int compat_put_ushort(unsigned long arg, unsigned short val)
15{
16 return put_user(val, (unsigned short __user *)compat_ptr(arg));
17}
18
19static int compat_put_int(unsigned long arg, int val)
20{
21 return put_user(val, (compat_int_t __user *)compat_ptr(arg));
22}
23
24static int compat_put_long(unsigned long arg, long val)
25{
26 return put_user(val, (compat_long_t __user *)compat_ptr(arg));
27}
28
29static int compat_put_ulong(unsigned long arg, compat_ulong_t val)
30{
31 return put_user(val, (compat_ulong_t __user *)compat_ptr(arg));
32}
33
34static int compat_put_u64(unsigned long arg, u64 val)
35{
36 return put_user(val, (compat_u64 __user *)compat_ptr(arg));
37}
38
39#define BLKBSZGET_32 _IOR(0x12, 112, int)
40#define BLKBSZSET_32 _IOW(0x12, 113, int)
41#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
42
43static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
44 struct block_device *bdev,
45 unsigned cmd, unsigned long arg)
46{
47 struct backing_dev_info *bdi;
48
49 switch (cmd) {
50 case BLKRAGET:
51 case BLKFRAGET:
52 if (!arg)
53 return -EINVAL;
54 bdi = blk_get_backing_dev_info(bdev);
55 if (bdi == NULL)
56 return -ENOTTY;
57 return compat_put_long(arg,
58 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
59 case BLKROGET: /* compatible */
60 return compat_put_int(arg, bdev_read_only(bdev) != 0);
61 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
62 return compat_put_int(arg, block_size(bdev));
63 case BLKSSZGET: /* get block device hardware sector size */
64 return compat_put_int(arg, bdev_hardsect_size(bdev));
65 case BLKSECTGET:
66 return compat_put_ushort(arg,
67 bdev_get_queue(bdev)->max_sectors);
68 case BLKRASET: /* compatible, but no compat_ptr (!) */
69 case BLKFRASET:
70 if (!capable(CAP_SYS_ADMIN))
71 return -EACCES;
72 bdi = blk_get_backing_dev_info(bdev);
73 if (bdi == NULL)
74 return -ENOTTY;
75 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
76 return 0;
77 case BLKGETSIZE:
78 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
79 return -EFBIG;
80 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9);
81
82 case BLKGETSIZE64_32:
83 return compat_put_u64(arg, bdev->bd_inode->i_size);
84 }
85 return -ENOIOCTLCMD;
86}
87
88/* Most of the generic ioctls are handled in the normal fallback path.
89 This assumes the blkdev's low level compat_ioctl always returns
90 ENOIOCTLCMD for unknown ioctls. */
91long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
92{
93 int ret = -ENOIOCTLCMD;
94 struct inode *inode = file->f_mapping->host;
95 struct block_device *bdev = inode->i_bdev;
96 struct gendisk *disk = bdev->bd_disk;
97
98 switch (cmd) {
99 case BLKFLSBUF:
100 case BLKROSET:
101 /*
102 * the ones below are implemented in blkdev_locked_ioctl,
103 * but we call blkdev_ioctl, which gets the lock for us
104 */
105 case BLKRRPART:
106 return blkdev_ioctl(inode, file, cmd,
107 (unsigned long)compat_ptr(arg));
108 case BLKBSZSET_32:
109 return blkdev_ioctl(inode, file, BLKBSZSET,
110 (unsigned long)compat_ptr(arg));
111 }
112
113 lock_kernel();
114 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
115 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */
116 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
117 ret = disk->fops->compat_ioctl(file, cmd, arg);
118 unlock_kernel();
119
120 return ret;
121}
diff --git a/block/ioctl.c b/block/ioctl.c
index f7e3e8abf887..52d6385216ad 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -217,6 +217,10 @@ int blkdev_driver_ioctl(struct inode *inode, struct file *file,
217} 217}
218EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); 218EXPORT_SYMBOL_GPL(blkdev_driver_ioctl);
219 219
220/*
221 * always keep this in sync with compat_blkdev_ioctl() and
222 * compat_blkdev_locked_ioctl()
223 */
220int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, 224int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
221 unsigned long arg) 225 unsigned long arg)
222{ 226{
@@ -284,21 +288,4 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
284 288
285 return blkdev_driver_ioctl(inode, file, disk, cmd, arg); 289 return blkdev_driver_ioctl(inode, file, disk, cmd, arg);
286} 290}
287
288/* Most of the generic ioctls are handled in the normal fallback path.
289 This assumes the blkdev's low level compat_ioctl always returns
290 ENOIOCTLCMD for unknown ioctls. */
291long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
292{
293 struct block_device *bdev = file->f_path.dentry->d_inode->i_bdev;
294 struct gendisk *disk = bdev->bd_disk;
295 int ret = -ENOIOCTLCMD;
296 if (disk->fops->compat_ioctl) {
297 lock_kernel();
298 ret = disk->fops->compat_ioctl(file, cmd, arg);
299 unlock_kernel();
300 }
301 return ret;
302}
303
304EXPORT_SYMBOL_GPL(blkdev_ioctl); 291EXPORT_SYMBOL_GPL(blkdev_ioctl);