aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2007-10-09 07:23:55 -0400
committerJens Axboe <axboe@carl.home.kernel.dk>2007-10-10 03:26:00 -0400
commit9617db085c119879cd371e3212806a15596e121a (patch)
tree17db98cd2d195105124f1d8a96f249ca073918cd
parent171044d449611c6e5040b37210ff6aba47f33ee4 (diff)
compat_ioctl: move hdio calls to block/compat_ioctl.c
These are common to multiple block drivers, so they should be handled by the block layer. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--block/compat_ioctl.c70
-rw-r--r--fs/compat_ioctl.c60
2 files changed, 70 insertions, 60 deletions
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 219b7e76e8ad..5c6dafaad938 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -36,6 +36,62 @@ static int compat_put_u64(unsigned long arg, u64 val)
36 return put_user(val, (compat_u64 __user *)compat_ptr(arg)); 36 return put_user(val, (compat_u64 __user *)compat_ptr(arg));
37} 37}
38 38
39struct compat_hd_geometry {
40 unsigned char heads;
41 unsigned char sectors;
42 unsigned short cylinders;
43 u32 start;
44};
45
46static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
47 struct compat_hd_geometry __user *ugeo)
48{
49 struct hd_geometry geo;
50 int ret;
51
52 if (!ugeo)
53 return -EINVAL;
54 if (!disk->fops->getgeo)
55 return -ENOTTY;
56
57 /*
58 * We need to set the startsect first, the driver may
59 * want to override it.
60 */
61 geo.start = get_start_sect(bdev);
62 ret = disk->fops->getgeo(bdev, &geo);
63 if (ret)
64 return ret;
65
66 ret = copy_to_user(ugeo, &geo, 4);
67 ret |= __put_user(geo.start, &ugeo->start);
68 if (ret)
69 ret = -EFAULT;
70
71 return ret;
72}
73
74static int compat_hdio_ioctl(struct inode *inode, struct file *file,
75 struct gendisk *disk, unsigned int cmd, unsigned long arg)
76{
77 mm_segment_t old_fs = get_fs();
78 unsigned long kval;
79 unsigned int __user *uvp;
80 int error;
81
82 set_fs(KERNEL_DS);
83 error = blkdev_driver_ioctl(inode, file, disk,
84 cmd, (unsigned long)(&kval));
85 set_fs(old_fs);
86
87 if (error == 0) {
88 uvp = compat_ptr(arg);
89 if (put_user(kval, uvp))
90 error = -EFAULT;
91 }
92 return error;
93}
94
39#define BLKBSZGET_32 _IOR(0x12, 112, int) 95#define BLKBSZGET_32 _IOR(0x12, 112, int)
40#define BLKBSZSET_32 _IOW(0x12, 113, int) 96#define BLKBSZSET_32 _IOW(0x12, 113, int)
41#define BLKGETSIZE64_32 _IOR(0x12, 114, int) 97#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
@@ -93,6 +149,18 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
93 int ret; 149 int ret;
94 150
95 switch (arg) { 151 switch (arg) {
152 case HDIO_GET_UNMASKINTR:
153 case HDIO_GET_MULTCOUNT:
154 case HDIO_GET_KEEPSETTINGS:
155 case HDIO_GET_32BIT:
156 case HDIO_GET_NOWERR:
157 case HDIO_GET_DMA:
158 case HDIO_GET_NICE:
159 case HDIO_GET_WCACHE:
160 case HDIO_GET_ACOUSTIC:
161 case HDIO_GET_ADDRESS:
162 case HDIO_GET_BUSSTATE:
163 return compat_hdio_ioctl(inode, file, disk, cmd, arg);
96 /* 164 /*
97 * No handler required for the ones below, we just need to 165 * No handler required for the ones below, we just need to
98 * convert arg to a 64 bit pointer. 166 * convert arg to a 64 bit pointer.
@@ -266,6 +334,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
266 struct gendisk *disk = bdev->bd_disk; 334 struct gendisk *disk = bdev->bd_disk;
267 335
268 switch (cmd) { 336 switch (cmd) {
337 case HDIO_GETGEO:
338 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
269 case BLKFLSBUF: 339 case BLKFLSBUF:
270 case BLKROSET: 340 case BLKROSET:
271 /* 341 /*
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 71065603a581..e6a94714b1b0 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -21,7 +21,6 @@
21#include <linux/if.h> 21#include <linux/if.h>
22#include <linux/if_bridge.h> 22#include <linux/if_bridge.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/hdreg.h>
25#include <linux/raid/md.h> 24#include <linux/raid/md.h>
26#include <linux/kd.h> 25#include <linux/kd.h>
27#include <linux/dirent.h> 26#include <linux/dirent.h>
@@ -667,53 +666,6 @@ out:
667#endif 666#endif
668 667
669#ifdef CONFIG_BLOCK 668#ifdef CONFIG_BLOCK
670struct hd_geometry32 {
671 unsigned char heads;
672 unsigned char sectors;
673 unsigned short cylinders;
674 u32 start;
675};
676
677static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
678{
679 mm_segment_t old_fs = get_fs();
680 struct hd_geometry geo;
681 struct hd_geometry32 __user *ugeo;
682 int err;
683
684 set_fs (KERNEL_DS);
685 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
686 set_fs (old_fs);
687 ugeo = compat_ptr(arg);
688 if (!err) {
689 err = copy_to_user (ugeo, &geo, 4);
690 err |= __put_user (geo.start, &ugeo->start);
691 if (err)
692 err = -EFAULT;
693 }
694 return err;
695}
696
697static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
698{
699 mm_segment_t old_fs = get_fs();
700 unsigned long kval;
701 unsigned int __user *uvp;
702 int error;
703
704 set_fs(KERNEL_DS);
705 error = sys_ioctl(fd, cmd, (long)&kval);
706 set_fs(old_fs);
707
708 if(error == 0) {
709 uvp = compat_ptr(arg);
710 if(put_user(kval, uvp))
711 error = -EFAULT;
712 }
713 return error;
714}
715
716
717typedef struct sg_io_hdr32 { 669typedef struct sg_io_hdr32 {
718 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ 670 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
719 compat_int_t dxfer_direction; /* [i] data transfer direction */ 671 compat_int_t dxfer_direction; /* [i] data transfer direction */
@@ -3208,19 +3160,7 @@ HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
3208HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns) 3160HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
3209#endif 3161#endif
3210#ifdef CONFIG_BLOCK 3162#ifdef CONFIG_BLOCK
3211HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
3212HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans) 3163HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
3213HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
3214HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
3215HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
3216HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
3217HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
3218HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
3219HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
3220HANDLE_IOCTL(HDIO_GET_WCACHE, hdio_ioctl_trans)
3221HANDLE_IOCTL(HDIO_GET_ACOUSTIC, hdio_ioctl_trans)
3222HANDLE_IOCTL(HDIO_GET_ADDRESS, hdio_ioctl_trans)
3223HANDLE_IOCTL(HDIO_GET_BUSSTATE, hdio_ioctl_trans)
3224HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans) 3164HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
3225HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans) 3165HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
3226HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans) 3166HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)