Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ioctl32.c: Conversion between 32bit and 64bit native ioctls. |
| 3 | * |
| 4 | * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com) |
| 5 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) |
| 6 | * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs |
| 7 | * Copyright (C) 2003 Pavel Machek (pavel@suse.cz) |
| 8 | * |
| 9 | * These routines maintain argument size conversion between 32bit and 64bit |
| 10 | * ioctls. |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/config.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/compat.h> |
| 16 | #include <linux/kernel.h> |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 17 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/compiler.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/smp.h> |
| 21 | #include <linux/smp_lock.h> |
| 22 | #include <linux/ioctl.h> |
| 23 | #include <linux/if.h> |
| 24 | #include <linux/if_bridge.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/hdreg.h> |
| 27 | #include <linux/raid/md.h> |
| 28 | #include <linux/kd.h> |
| 29 | #include <linux/dirent.h> |
| 30 | #include <linux/route.h> |
| 31 | #include <linux/in6.h> |
| 32 | #include <linux/ipv6_route.h> |
| 33 | #include <linux/skbuff.h> |
| 34 | #include <linux/netlink.h> |
| 35 | #include <linux/vt.h> |
| 36 | #include <linux/fs.h> |
| 37 | #include <linux/file.h> |
| 38 | #include <linux/fd.h> |
| 39 | #include <linux/ppp_defs.h> |
| 40 | #include <linux/if_ppp.h> |
| 41 | #include <linux/if_pppox.h> |
| 42 | #include <linux/mtio.h> |
| 43 | #include <linux/cdrom.h> |
| 44 | #include <linux/loop.h> |
| 45 | #include <linux/auto_fs.h> |
| 46 | #include <linux/auto_fs4.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/tty.h> |
| 48 | #include <linux/vt_kern.h> |
| 49 | #include <linux/fb.h> |
| 50 | #include <linux/ext2_fs.h> |
David S. Miller | d5ea655 | 2005-11-17 15:04:34 -0800 | [diff] [blame] | 51 | #include <linux/ext3_jbd.h> |
| 52 | #include <linux/ext3_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <linux/videodev.h> |
| 54 | #include <linux/netdevice.h> |
| 55 | #include <linux/raw.h> |
| 56 | #include <linux/smb_fs.h> |
| 57 | #include <linux/blkpg.h> |
| 58 | #include <linux/blkdev.h> |
| 59 | #include <linux/elevator.h> |
| 60 | #include <linux/rtc.h> |
| 61 | #include <linux/pci.h> |
| 62 | #include <linux/module.h> |
| 63 | #include <linux/serial.h> |
| 64 | #include <linux/reiserfs_fs.h> |
| 65 | #include <linux/if_tun.h> |
| 66 | #include <linux/ctype.h> |
| 67 | #include <linux/ioctl32.h> |
| 68 | #include <linux/syscalls.h> |
| 69 | #include <linux/ncp_fs.h> |
| 70 | #include <linux/i2c.h> |
| 71 | #include <linux/i2c-dev.h> |
| 72 | #include <linux/wireless.h> |
| 73 | #include <linux/atalk.h> |
Jens Axboe | 2056a78 | 2006-03-23 20:00:26 +0100 | [diff] [blame] | 74 | #include <linux/blktrace_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | #include <net/sock.h> /* siocdevprivate_ioctl */ |
| 77 | #include <net/bluetooth/bluetooth.h> |
| 78 | #include <net/bluetooth/hci.h> |
| 79 | #include <net/bluetooth/rfcomm.h> |
| 80 | |
| 81 | #include <linux/capi.h> |
Hansjoerg Lipp | 5024ad4 | 2006-06-26 00:25:35 -0700 | [diff] [blame] | 82 | #include <linux/gigaset_dev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | #include <scsi/scsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #include <scsi/scsi_ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #include <scsi/sg.h> |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #include <asm/uaccess.h> |
| 89 | #include <linux/ethtool.h> |
| 90 | #include <linux/mii.h> |
| 91 | #include <linux/if_bonding.h> |
| 92 | #include <linux/watchdog.h> |
| 93 | #include <linux/dm-ioctl.h> |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #include <linux/soundcard.h> |
| 96 | #include <linux/lp.h> |
| 97 | #include <linux/ppdev.h> |
| 98 | |
| 99 | #include <linux/atm.h> |
| 100 | #include <linux/atmarp.h> |
| 101 | #include <linux/atmclip.h> |
| 102 | #include <linux/atmdev.h> |
| 103 | #include <linux/atmioc.h> |
| 104 | #include <linux/atmlec.h> |
| 105 | #include <linux/atmmpc.h> |
| 106 | #include <linux/atmsvc.h> |
| 107 | #include <linux/atm_tcp.h> |
| 108 | #include <linux/sonet.h> |
| 109 | #include <linux/atm_suni.h> |
| 110 | #include <linux/mtd/mtd.h> |
| 111 | |
| 112 | #include <linux/usb.h> |
| 113 | #include <linux/usbdevice_fs.h> |
| 114 | #include <linux/nbd.h> |
| 115 | #include <linux/random.h> |
| 116 | #include <linux/filter.h> |
| 117 | #include <linux/msdos_fs.h> |
| 118 | #include <linux/pktcdvd.h> |
| 119 | |
| 120 | #include <linux/hiddev.h> |
| 121 | |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 122 | #include <linux/dvb/audio.h> |
| 123 | #include <linux/dvb/dmx.h> |
| 124 | #include <linux/dvb/frontend.h> |
| 125 | #include <linux/dvb/video.h> |
Andi Kleen | c6b44d1 | 2006-01-12 01:05:26 -0800 | [diff] [blame] | 126 | #include <linux/lp.h> |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* Aiee. Someone does not find a difference between int and long */ |
| 129 | #define EXT2_IOC32_GETFLAGS _IOR('f', 1, int) |
| 130 | #define EXT2_IOC32_SETFLAGS _IOW('f', 2, int) |
David S. Miller | d5ea655 | 2005-11-17 15:04:34 -0800 | [diff] [blame] | 131 | #define EXT3_IOC32_GETVERSION _IOR('f', 3, int) |
David S. Miller | bcb6ad1 | 2005-11-18 14:50:20 -0800 | [diff] [blame] | 132 | #define EXT3_IOC32_SETVERSION _IOW('f', 4, int) |
David S. Miller | d5ea655 | 2005-11-17 15:04:34 -0800 | [diff] [blame] | 133 | #define EXT3_IOC32_GETRSVSZ _IOR('f', 5, int) |
| 134 | #define EXT3_IOC32_SETRSVSZ _IOW('f', 6, int) |
| 135 | #define EXT3_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int) |
| 136 | #ifdef CONFIG_JBD_DEBUG |
| 137 | #define EXT3_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int) |
| 138 | #endif |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | #define EXT2_IOC32_GETVERSION _IOR('v', 1, int) |
| 141 | #define EXT2_IOC32_SETVERSION _IOW('v', 2, int) |
| 142 | |
Christoph Hellwig | e6a6d2e | 2006-01-09 20:52:14 -0800 | [diff] [blame] | 143 | static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, |
| 144 | unsigned long arg, struct file *f) |
| 145 | { |
| 146 | return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg)); |
| 147 | } |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 150 | { |
| 151 | mm_segment_t old_fs = get_fs(); |
| 152 | int err; |
| 153 | unsigned long val; |
| 154 | |
| 155 | set_fs (KERNEL_DS); |
| 156 | err = sys_ioctl(fd, cmd, (unsigned long)&val); |
| 157 | set_fs (old_fs); |
| 158 | if (!err && put_user(val, (u32 __user *)compat_ptr(arg))) |
| 159 | return -EFAULT; |
| 160 | return err; |
| 161 | } |
| 162 | |
| 163 | static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 164 | { |
| 165 | mm_segment_t old_fs = get_fs(); |
| 166 | u32 __user *argptr = compat_ptr(arg); |
| 167 | int err; |
| 168 | unsigned long val; |
| 169 | |
| 170 | if(get_user(val, argptr)) |
| 171 | return -EFAULT; |
| 172 | set_fs (KERNEL_DS); |
| 173 | err = sys_ioctl(fd, cmd, (unsigned long)&val); |
| 174 | set_fs (old_fs); |
| 175 | if (!err && put_user(val, argptr)) |
| 176 | return -EFAULT; |
| 177 | return err; |
| 178 | } |
| 179 | |
| 180 | static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 181 | { |
| 182 | /* These are just misnamed, they actually get/put from/to user an int */ |
| 183 | switch (cmd) { |
| 184 | case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break; |
| 185 | case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break; |
| 186 | case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break; |
| 187 | case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break; |
| 188 | } |
| 189 | return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg)); |
| 190 | } |
| 191 | |
David S. Miller | d5ea655 | 2005-11-17 15:04:34 -0800 | [diff] [blame] | 192 | static int do_ext3_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 193 | { |
| 194 | /* These are just misnamed, they actually get/put from/to user an int */ |
| 195 | switch (cmd) { |
| 196 | case EXT3_IOC32_GETVERSION: cmd = EXT3_IOC_GETVERSION; break; |
| 197 | case EXT3_IOC32_SETVERSION: cmd = EXT3_IOC_SETVERSION; break; |
| 198 | case EXT3_IOC32_GETRSVSZ: cmd = EXT3_IOC_GETRSVSZ; break; |
| 199 | case EXT3_IOC32_SETRSVSZ: cmd = EXT3_IOC_SETRSVSZ; break; |
| 200 | case EXT3_IOC32_GROUP_EXTEND: cmd = EXT3_IOC_GROUP_EXTEND; break; |
| 201 | #ifdef CONFIG_JBD_DEBUG |
| 202 | case EXT3_IOC32_WAIT_FOR_READONLY: cmd = EXT3_IOC_WAIT_FOR_READONLY; break; |
| 203 | #endif |
| 204 | } |
| 205 | return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg)); |
| 206 | } |
| 207 | |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 208 | struct compat_video_event { |
| 209 | int32_t type; |
| 210 | compat_time_t timestamp; |
| 211 | union { |
| 212 | video_size_t size; |
| 213 | unsigned int frame_rate; |
| 214 | } u; |
| 215 | }; |
| 216 | |
| 217 | static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 218 | { |
| 219 | struct video_event kevent; |
| 220 | mm_segment_t old_fs = get_fs(); |
| 221 | int err; |
| 222 | |
| 223 | set_fs(KERNEL_DS); |
| 224 | err = sys_ioctl(fd, cmd, (unsigned long) &kevent); |
| 225 | set_fs(old_fs); |
| 226 | |
| 227 | if (!err) { |
| 228 | struct compat_video_event __user *up = compat_ptr(arg); |
| 229 | |
| 230 | err = put_user(kevent.type, &up->type); |
| 231 | err |= put_user(kevent.timestamp, &up->timestamp); |
| 232 | err |= put_user(kevent.u.size.w, &up->u.size.w); |
| 233 | err |= put_user(kevent.u.size.h, &up->u.size.h); |
| 234 | err |= put_user(kevent.u.size.aspect_ratio, |
| 235 | &up->u.size.aspect_ratio); |
| 236 | if (err) |
| 237 | err = -EFAULT; |
| 238 | } |
| 239 | |
| 240 | return err; |
| 241 | } |
| 242 | |
| 243 | struct compat_video_still_picture { |
| 244 | compat_uptr_t iFrame; |
| 245 | int32_t size; |
| 246 | }; |
| 247 | |
| 248 | static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 249 | { |
| 250 | struct compat_video_still_picture __user *up; |
| 251 | struct video_still_picture __user *up_native; |
| 252 | compat_uptr_t fp; |
| 253 | int32_t size; |
| 254 | int err; |
| 255 | |
| 256 | up = (struct compat_video_still_picture __user *) arg; |
| 257 | err = get_user(fp, &up->iFrame); |
| 258 | err |= get_user(size, &up->size); |
| 259 | if (err) |
| 260 | return -EFAULT; |
| 261 | |
| 262 | up_native = |
| 263 | compat_alloc_user_space(sizeof(struct video_still_picture)); |
| 264 | |
| 265 | put_user(compat_ptr(fp), &up_native->iFrame); |
| 266 | put_user(size, &up_native->size); |
| 267 | |
| 268 | err = sys_ioctl(fd, cmd, (unsigned long) up_native); |
| 269 | |
| 270 | return err; |
| 271 | } |
| 272 | |
| 273 | struct compat_video_spu_palette { |
| 274 | int length; |
| 275 | compat_uptr_t palette; |
| 276 | }; |
| 277 | |
| 278 | static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 279 | { |
| 280 | struct compat_video_spu_palette __user *up; |
| 281 | struct video_spu_palette __user *up_native; |
| 282 | compat_uptr_t palp; |
| 283 | int length, err; |
| 284 | |
| 285 | up = (struct compat_video_spu_palette __user *) arg; |
| 286 | err = get_user(palp, &up->palette); |
| 287 | err |= get_user(length, &up->length); |
| 288 | |
| 289 | up_native = compat_alloc_user_space(sizeof(struct video_spu_palette)); |
| 290 | put_user(compat_ptr(palp), &up_native->palette); |
| 291 | put_user(length, &up_native->length); |
| 292 | |
| 293 | err = sys_ioctl(fd, cmd, (unsigned long) up_native); |
| 294 | |
| 295 | return err; |
| 296 | } |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | #ifdef CONFIG_NET |
| 299 | static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 300 | { |
| 301 | struct compat_timeval __user *up = compat_ptr(arg); |
| 302 | struct timeval ktv; |
| 303 | mm_segment_t old_fs = get_fs(); |
| 304 | int err; |
| 305 | |
| 306 | set_fs(KERNEL_DS); |
| 307 | err = sys_ioctl(fd, cmd, (unsigned long)&ktv); |
| 308 | set_fs(old_fs); |
| 309 | if(!err) { |
| 310 | err = put_user(ktv.tv_sec, &up->tv_sec); |
| 311 | err |= __put_user(ktv.tv_usec, &up->tv_usec); |
| 312 | } |
| 313 | return err; |
| 314 | } |
| 315 | |
| 316 | struct ifmap32 { |
| 317 | compat_ulong_t mem_start; |
| 318 | compat_ulong_t mem_end; |
| 319 | unsigned short base_addr; |
| 320 | unsigned char irq; |
| 321 | unsigned char dma; |
| 322 | unsigned char port; |
| 323 | }; |
| 324 | |
| 325 | struct ifreq32 { |
| 326 | #define IFHWADDRLEN 6 |
| 327 | #define IFNAMSIZ 16 |
| 328 | union { |
| 329 | char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */ |
| 330 | } ifr_ifrn; |
| 331 | union { |
| 332 | struct sockaddr ifru_addr; |
| 333 | struct sockaddr ifru_dstaddr; |
| 334 | struct sockaddr ifru_broadaddr; |
| 335 | struct sockaddr ifru_netmask; |
| 336 | struct sockaddr ifru_hwaddr; |
| 337 | short ifru_flags; |
| 338 | compat_int_t ifru_ivalue; |
| 339 | compat_int_t ifru_mtu; |
| 340 | struct ifmap32 ifru_map; |
| 341 | char ifru_slave[IFNAMSIZ]; /* Just fits the size */ |
| 342 | char ifru_newname[IFNAMSIZ]; |
| 343 | compat_caddr_t ifru_data; |
| 344 | /* XXXX? ifru_settings should be here */ |
| 345 | } ifr_ifru; |
| 346 | }; |
| 347 | |
| 348 | struct ifconf32 { |
| 349 | compat_int_t ifc_len; /* size of buffer */ |
| 350 | compat_caddr_t ifcbuf; |
| 351 | }; |
| 352 | |
| 353 | static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 354 | { |
| 355 | struct net_device *dev; |
| 356 | struct ifreq32 ifr32; |
| 357 | int err; |
| 358 | |
| 359 | if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32))) |
| 360 | return -EFAULT; |
| 361 | |
| 362 | dev = dev_get_by_index(ifr32.ifr_ifindex); |
| 363 | if (!dev) |
| 364 | return -ENODEV; |
| 365 | |
| 366 | strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name)); |
| 367 | dev_put(dev); |
| 368 | |
| 369 | err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32)); |
| 370 | return (err ? -EFAULT : 0); |
| 371 | } |
| 372 | |
| 373 | static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 374 | { |
| 375 | struct ifconf32 ifc32; |
| 376 | struct ifconf ifc; |
| 377 | struct ifconf __user *uifc; |
| 378 | struct ifreq32 __user *ifr32; |
| 379 | struct ifreq __user *ifr; |
| 380 | unsigned int i, j; |
| 381 | int err; |
| 382 | |
| 383 | if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32))) |
| 384 | return -EFAULT; |
| 385 | |
| 386 | if (ifc32.ifcbuf == 0) { |
| 387 | ifc32.ifc_len = 0; |
| 388 | ifc.ifc_len = 0; |
| 389 | ifc.ifc_req = NULL; |
| 390 | uifc = compat_alloc_user_space(sizeof(struct ifconf)); |
| 391 | } else { |
| 392 | size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) * |
| 393 | sizeof (struct ifreq); |
| 394 | uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); |
| 395 | ifc.ifc_len = len; |
| 396 | ifr = ifc.ifc_req = (void __user *)(uifc + 1); |
| 397 | ifr32 = compat_ptr(ifc32.ifcbuf); |
| 398 | for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) { |
| 399 | if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32))) |
| 400 | return -EFAULT; |
| 401 | ifr++; |
| 402 | ifr32++; |
| 403 | } |
| 404 | } |
| 405 | if (copy_to_user(uifc, &ifc, sizeof(struct ifconf))) |
| 406 | return -EFAULT; |
| 407 | |
| 408 | err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc); |
| 409 | if (err) |
| 410 | return err; |
| 411 | |
| 412 | if (copy_from_user(&ifc, uifc, sizeof(struct ifconf))) |
| 413 | return -EFAULT; |
| 414 | |
| 415 | ifr = ifc.ifc_req; |
| 416 | ifr32 = compat_ptr(ifc32.ifcbuf); |
Alexandra Kossovsky | 4909724 | 2005-11-20 13:41:59 -0800 | [diff] [blame] | 417 | for (i = 0, j = 0; |
Randy Dunlap | 1efa3c0 | 2006-03-08 16:46:08 -0800 | [diff] [blame] | 418 | i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) { |
| 420 | if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32))) |
| 421 | return -EFAULT; |
| 422 | ifr32++; |
| 423 | ifr++; |
| 424 | } |
| 425 | |
| 426 | if (ifc32.ifcbuf == 0) { |
| 427 | /* Translate from 64-bit structure multiple to |
| 428 | * a 32-bit one. |
| 429 | */ |
| 430 | i = ifc.ifc_len; |
| 431 | i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32)); |
| 432 | ifc32.ifc_len = i; |
| 433 | } else { |
Alexandra Kossovsky | 4909724 | 2005-11-20 13:41:59 -0800 | [diff] [blame] | 434 | ifc32.ifc_len = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32))) |
| 437 | return -EFAULT; |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 443 | { |
| 444 | struct ifreq __user *ifr; |
| 445 | struct ifreq32 __user *ifr32; |
| 446 | u32 data; |
| 447 | void __user *datap; |
| 448 | |
| 449 | ifr = compat_alloc_user_space(sizeof(*ifr)); |
| 450 | ifr32 = compat_ptr(arg); |
| 451 | |
| 452 | if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) |
| 453 | return -EFAULT; |
| 454 | |
| 455 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) |
| 456 | return -EFAULT; |
| 457 | |
| 458 | datap = compat_ptr(data); |
| 459 | if (put_user(datap, &ifr->ifr_ifru.ifru_data)) |
| 460 | return -EFAULT; |
| 461 | |
| 462 | return sys_ioctl(fd, cmd, (unsigned long) ifr); |
| 463 | } |
| 464 | |
| 465 | static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 466 | { |
| 467 | struct ifreq kifr; |
| 468 | struct ifreq __user *uifr; |
| 469 | struct ifreq32 __user *ifr32 = compat_ptr(arg); |
| 470 | mm_segment_t old_fs; |
| 471 | int err; |
| 472 | u32 data; |
| 473 | void __user *datap; |
| 474 | |
| 475 | switch (cmd) { |
| 476 | case SIOCBONDENSLAVE: |
| 477 | case SIOCBONDRELEASE: |
| 478 | case SIOCBONDSETHWADDR: |
| 479 | case SIOCBONDCHANGEACTIVE: |
| 480 | if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32))) |
| 481 | return -EFAULT; |
| 482 | |
| 483 | old_fs = get_fs(); |
| 484 | set_fs (KERNEL_DS); |
| 485 | err = sys_ioctl (fd, cmd, (unsigned long)&kifr); |
| 486 | set_fs (old_fs); |
| 487 | |
| 488 | return err; |
| 489 | case SIOCBONDSLAVEINFOQUERY: |
| 490 | case SIOCBONDINFOQUERY: |
| 491 | uifr = compat_alloc_user_space(sizeof(*uifr)); |
| 492 | if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) |
| 493 | return -EFAULT; |
| 494 | |
| 495 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) |
| 496 | return -EFAULT; |
| 497 | |
| 498 | datap = compat_ptr(data); |
| 499 | if (put_user(datap, &uifr->ifr_ifru.ifru_data)) |
| 500 | return -EFAULT; |
| 501 | |
| 502 | return sys_ioctl (fd, cmd, (unsigned long)uifr); |
| 503 | default: |
| 504 | return -EINVAL; |
| 505 | }; |
| 506 | } |
| 507 | |
| 508 | int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 509 | { |
| 510 | struct ifreq __user *u_ifreq64; |
| 511 | struct ifreq32 __user *u_ifreq32 = compat_ptr(arg); |
| 512 | char tmp_buf[IFNAMSIZ]; |
| 513 | void __user *data64; |
| 514 | u32 data32; |
| 515 | |
| 516 | if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]), |
| 517 | IFNAMSIZ)) |
| 518 | return -EFAULT; |
| 519 | if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data)) |
| 520 | return -EFAULT; |
| 521 | data64 = compat_ptr(data32); |
| 522 | |
| 523 | u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64)); |
| 524 | |
| 525 | /* Don't check these user accesses, just let that get trapped |
| 526 | * in the ioctl handler instead. |
| 527 | */ |
| 528 | if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], |
| 529 | IFNAMSIZ)) |
| 530 | return -EFAULT; |
| 531 | if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data)) |
| 532 | return -EFAULT; |
| 533 | |
| 534 | return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64); |
| 535 | } |
| 536 | |
| 537 | static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 538 | { |
| 539 | struct ifreq ifr; |
| 540 | struct ifreq32 __user *uifr32; |
| 541 | struct ifmap32 __user *uifmap32; |
| 542 | mm_segment_t old_fs; |
| 543 | int err; |
| 544 | |
| 545 | uifr32 = compat_ptr(arg); |
| 546 | uifmap32 = &uifr32->ifr_ifru.ifru_map; |
| 547 | switch (cmd) { |
| 548 | case SIOCSIFMAP: |
| 549 | err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name)); |
| 550 | err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); |
| 551 | err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); |
| 552 | err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); |
| 553 | err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq); |
| 554 | err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma); |
| 555 | err |= __get_user(ifr.ifr_map.port, &uifmap32->port); |
| 556 | if (err) |
| 557 | return -EFAULT; |
| 558 | break; |
| 559 | default: |
| 560 | if (copy_from_user(&ifr, uifr32, sizeof(*uifr32))) |
| 561 | return -EFAULT; |
| 562 | break; |
| 563 | } |
| 564 | old_fs = get_fs(); |
| 565 | set_fs (KERNEL_DS); |
| 566 | err = sys_ioctl (fd, cmd, (unsigned long)&ifr); |
| 567 | set_fs (old_fs); |
| 568 | if (!err) { |
| 569 | switch (cmd) { |
| 570 | /* TUNSETIFF is defined as _IOW, it should be _IORW |
| 571 | * as the data is copied back to user space, but that |
| 572 | * cannot be fixed without breaking all existing apps. |
| 573 | */ |
| 574 | case TUNSETIFF: |
| 575 | case SIOCGIFFLAGS: |
| 576 | case SIOCGIFMETRIC: |
| 577 | case SIOCGIFMTU: |
| 578 | case SIOCGIFMEM: |
| 579 | case SIOCGIFHWADDR: |
| 580 | case SIOCGIFINDEX: |
| 581 | case SIOCGIFADDR: |
| 582 | case SIOCGIFBRDADDR: |
| 583 | case SIOCGIFDSTADDR: |
| 584 | case SIOCGIFNETMASK: |
| 585 | case SIOCGIFTXQLEN: |
| 586 | if (copy_to_user(uifr32, &ifr, sizeof(*uifr32))) |
| 587 | return -EFAULT; |
| 588 | break; |
| 589 | case SIOCGIFMAP: |
| 590 | err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); |
| 591 | err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); |
| 592 | err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); |
| 593 | err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); |
| 594 | err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq); |
| 595 | err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma); |
| 596 | err |= __put_user(ifr.ifr_map.port, &uifmap32->port); |
| 597 | if (err) |
| 598 | err = -EFAULT; |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | return err; |
| 603 | } |
| 604 | |
| 605 | struct rtentry32 { |
| 606 | u32 rt_pad1; |
| 607 | struct sockaddr rt_dst; /* target address */ |
| 608 | struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ |
| 609 | struct sockaddr rt_genmask; /* target network mask (IP) */ |
| 610 | unsigned short rt_flags; |
| 611 | short rt_pad2; |
| 612 | u32 rt_pad3; |
| 613 | unsigned char rt_tos; |
| 614 | unsigned char rt_class; |
| 615 | short rt_pad4; |
| 616 | short rt_metric; /* +1 for binary compatibility! */ |
| 617 | /* char * */ u32 rt_dev; /* forcing the device at add */ |
| 618 | u32 rt_mtu; /* per route MTU/Window */ |
| 619 | u32 rt_window; /* Window clamping */ |
| 620 | unsigned short rt_irtt; /* Initial RTT */ |
| 621 | |
| 622 | }; |
| 623 | |
| 624 | struct in6_rtmsg32 { |
| 625 | struct in6_addr rtmsg_dst; |
| 626 | struct in6_addr rtmsg_src; |
| 627 | struct in6_addr rtmsg_gateway; |
| 628 | u32 rtmsg_type; |
| 629 | u16 rtmsg_dst_len; |
| 630 | u16 rtmsg_src_len; |
| 631 | u32 rtmsg_metric; |
| 632 | u32 rtmsg_info; |
| 633 | u32 rtmsg_flags; |
| 634 | s32 rtmsg_ifindex; |
| 635 | }; |
| 636 | |
| 637 | static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 638 | { |
| 639 | int ret; |
| 640 | void *r = NULL; |
| 641 | struct in6_rtmsg r6; |
| 642 | struct rtentry r4; |
| 643 | char devname[16]; |
| 644 | u32 rtdev; |
| 645 | mm_segment_t old_fs = get_fs(); |
| 646 | |
| 647 | struct socket *mysock = sockfd_lookup(fd, &ret); |
| 648 | |
| 649 | if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */ |
| 650 | struct in6_rtmsg32 __user *ur6 = compat_ptr(arg); |
| 651 | ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), |
| 652 | 3 * sizeof(struct in6_addr)); |
| 653 | ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); |
| 654 | ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); |
| 655 | ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); |
| 656 | ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); |
| 657 | ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); |
| 658 | ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); |
| 659 | ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); |
| 660 | |
| 661 | r = (void *) &r6; |
| 662 | } else { /* ipv4 */ |
| 663 | struct rtentry32 __user *ur4 = compat_ptr(arg); |
| 664 | ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), |
| 665 | 3 * sizeof(struct sockaddr)); |
| 666 | ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); |
| 667 | ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); |
| 668 | ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); |
| 669 | ret |= __get_user (r4.rt_window, &(ur4->rt_window)); |
| 670 | ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); |
| 671 | ret |= __get_user (rtdev, &(ur4->rt_dev)); |
| 672 | if (rtdev) { |
| 673 | ret |= copy_from_user (devname, compat_ptr(rtdev), 15); |
| 674 | r4.rt_dev = devname; devname[15] = 0; |
| 675 | } else |
| 676 | r4.rt_dev = NULL; |
| 677 | |
| 678 | r = (void *) &r4; |
| 679 | } |
| 680 | |
Kirill Korotaev | d99901d | 2005-09-09 13:59:48 +0400 | [diff] [blame] | 681 | if (ret) { |
| 682 | ret = -EFAULT; |
| 683 | goto out; |
| 684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | set_fs (KERNEL_DS); |
| 687 | ret = sys_ioctl (fd, cmd, (unsigned long) r); |
| 688 | set_fs (old_fs); |
| 689 | |
Kirill Korotaev | d99901d | 2005-09-09 13:59:48 +0400 | [diff] [blame] | 690 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (mysock) |
| 692 | sockfd_put(mysock); |
| 693 | |
| 694 | return ret; |
| 695 | } |
| 696 | #endif |
| 697 | |
| 698 | struct hd_geometry32 { |
| 699 | unsigned char heads; |
| 700 | unsigned char sectors; |
| 701 | unsigned short cylinders; |
| 702 | u32 start; |
| 703 | }; |
| 704 | |
| 705 | static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 706 | { |
| 707 | mm_segment_t old_fs = get_fs(); |
| 708 | struct hd_geometry geo; |
| 709 | struct hd_geometry32 __user *ugeo; |
| 710 | int err; |
| 711 | |
| 712 | set_fs (KERNEL_DS); |
| 713 | err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo); |
| 714 | set_fs (old_fs); |
| 715 | ugeo = compat_ptr(arg); |
| 716 | if (!err) { |
| 717 | err = copy_to_user (ugeo, &geo, 4); |
| 718 | err |= __put_user (geo.start, &ugeo->start); |
| 719 | } |
| 720 | return err ? -EFAULT : 0; |
| 721 | } |
| 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 724 | { |
| 725 | mm_segment_t old_fs = get_fs(); |
| 726 | unsigned long kval; |
| 727 | unsigned int __user *uvp; |
| 728 | int error; |
| 729 | |
| 730 | set_fs(KERNEL_DS); |
| 731 | error = sys_ioctl(fd, cmd, (long)&kval); |
| 732 | set_fs(old_fs); |
| 733 | |
| 734 | if(error == 0) { |
| 735 | uvp = compat_ptr(arg); |
| 736 | if(put_user(kval, uvp)) |
| 737 | error = -EFAULT; |
| 738 | } |
| 739 | return error; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | typedef struct sg_io_hdr32 { |
| 744 | compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ |
| 745 | compat_int_t dxfer_direction; /* [i] data transfer direction */ |
| 746 | unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ |
| 747 | unsigned char mx_sb_len; /* [i] max length to write to sbp */ |
| 748 | unsigned short iovec_count; /* [i] 0 implies no scatter gather */ |
| 749 | compat_uint_t dxfer_len; /* [i] byte count of data transfer */ |
| 750 | compat_uint_t dxferp; /* [i], [*io] points to data transfer memory |
| 751 | or scatter gather list */ |
| 752 | compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ |
| 753 | compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ |
| 754 | compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ |
| 755 | compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ |
| 756 | compat_int_t pack_id; /* [i->o] unused internally (normally) */ |
| 757 | compat_uptr_t usr_ptr; /* [i->o] unused internally */ |
| 758 | unsigned char status; /* [o] scsi status */ |
| 759 | unsigned char masked_status; /* [o] shifted, masked scsi status */ |
| 760 | unsigned char msg_status; /* [o] messaging level data (optional) */ |
| 761 | unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ |
| 762 | unsigned short host_status; /* [o] errors from host adapter */ |
| 763 | unsigned short driver_status; /* [o] errors from software driver */ |
| 764 | compat_int_t resid; /* [o] dxfer_len - actual_transferred */ |
| 765 | compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ |
| 766 | compat_uint_t info; /* [o] auxiliary information */ |
| 767 | } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */ |
| 768 | |
| 769 | typedef struct sg_iovec32 { |
| 770 | compat_uint_t iov_base; |
| 771 | compat_uint_t iov_len; |
| 772 | } sg_iovec32_t; |
| 773 | |
| 774 | static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count) |
| 775 | { |
| 776 | sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1); |
| 777 | sg_iovec32_t __user *iov32 = dxferp; |
| 778 | int i; |
| 779 | |
| 780 | for (i = 0; i < iovec_count; i++) { |
| 781 | u32 base, len; |
| 782 | |
| 783 | if (get_user(base, &iov32[i].iov_base) || |
| 784 | get_user(len, &iov32[i].iov_len) || |
| 785 | put_user(compat_ptr(base), &iov[i].iov_base) || |
| 786 | put_user(len, &iov[i].iov_len)) |
| 787 | return -EFAULT; |
| 788 | } |
| 789 | |
| 790 | if (put_user(iov, &sgio->dxferp)) |
| 791 | return -EFAULT; |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 796 | { |
| 797 | sg_io_hdr_t __user *sgio; |
| 798 | sg_io_hdr32_t __user *sgio32; |
| 799 | u16 iovec_count; |
| 800 | u32 data; |
| 801 | void __user *dxferp; |
| 802 | int err; |
| 803 | |
| 804 | sgio32 = compat_ptr(arg); |
| 805 | if (get_user(iovec_count, &sgio32->iovec_count)) |
| 806 | return -EFAULT; |
| 807 | |
| 808 | { |
| 809 | void __user *top = compat_alloc_user_space(0); |
| 810 | void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) + |
| 811 | (iovec_count * sizeof(sg_iovec_t))); |
| 812 | if (new > top) |
| 813 | return -EINVAL; |
| 814 | |
| 815 | sgio = new; |
| 816 | } |
| 817 | |
| 818 | /* Ok, now construct. */ |
| 819 | if (copy_in_user(&sgio->interface_id, &sgio32->interface_id, |
| 820 | (2 * sizeof(int)) + |
| 821 | (2 * sizeof(unsigned char)) + |
| 822 | (1 * sizeof(unsigned short)) + |
| 823 | (1 * sizeof(unsigned int)))) |
| 824 | return -EFAULT; |
| 825 | |
| 826 | if (get_user(data, &sgio32->dxferp)) |
| 827 | return -EFAULT; |
| 828 | dxferp = compat_ptr(data); |
| 829 | if (iovec_count) { |
| 830 | if (sg_build_iovec(sgio, dxferp, iovec_count)) |
| 831 | return -EFAULT; |
| 832 | } else { |
| 833 | if (put_user(dxferp, &sgio->dxferp)) |
| 834 | return -EFAULT; |
| 835 | } |
| 836 | |
| 837 | { |
| 838 | unsigned char __user *cmdp; |
| 839 | unsigned char __user *sbp; |
| 840 | |
| 841 | if (get_user(data, &sgio32->cmdp)) |
| 842 | return -EFAULT; |
| 843 | cmdp = compat_ptr(data); |
| 844 | |
| 845 | if (get_user(data, &sgio32->sbp)) |
| 846 | return -EFAULT; |
| 847 | sbp = compat_ptr(data); |
| 848 | |
| 849 | if (put_user(cmdp, &sgio->cmdp) || |
| 850 | put_user(sbp, &sgio->sbp)) |
| 851 | return -EFAULT; |
| 852 | } |
| 853 | |
| 854 | if (copy_in_user(&sgio->timeout, &sgio32->timeout, |
| 855 | 3 * sizeof(int))) |
| 856 | return -EFAULT; |
| 857 | |
| 858 | if (get_user(data, &sgio32->usr_ptr)) |
| 859 | return -EFAULT; |
| 860 | if (put_user(compat_ptr(data), &sgio->usr_ptr)) |
| 861 | return -EFAULT; |
| 862 | |
| 863 | if (copy_in_user(&sgio->status, &sgio32->status, |
| 864 | (4 * sizeof(unsigned char)) + |
| 865 | (2 * sizeof(unsigned (short))) + |
| 866 | (3 * sizeof(int)))) |
| 867 | return -EFAULT; |
| 868 | |
| 869 | err = sys_ioctl(fd, cmd, (unsigned long) sgio); |
| 870 | |
| 871 | if (err >= 0) { |
| 872 | void __user *datap; |
| 873 | |
| 874 | if (copy_in_user(&sgio32->pack_id, &sgio->pack_id, |
| 875 | sizeof(int)) || |
| 876 | get_user(datap, &sgio->usr_ptr) || |
| 877 | put_user((u32)(unsigned long)datap, |
| 878 | &sgio32->usr_ptr) || |
| 879 | copy_in_user(&sgio32->status, &sgio->status, |
| 880 | (4 * sizeof(unsigned char)) + |
| 881 | (2 * sizeof(unsigned short)) + |
| 882 | (3 * sizeof(int)))) |
| 883 | err = -EFAULT; |
| 884 | } |
| 885 | |
| 886 | return err; |
| 887 | } |
| 888 | |
Andi Kleen | 2966387 | 2006-01-11 22:44:03 +0100 | [diff] [blame] | 889 | struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */ |
| 890 | char req_state; |
| 891 | char orphan; |
| 892 | char sg_io_owned; |
| 893 | char problem; |
| 894 | int pack_id; |
| 895 | compat_uptr_t usr_ptr; |
| 896 | unsigned int duration; |
| 897 | int unused; |
| 898 | }; |
| 899 | |
| 900 | static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 901 | { |
| 902 | int err, i; |
Al Viro | 6b2b4e5 | 2006-02-01 06:33:33 -0500 | [diff] [blame] | 903 | sg_req_info_t __user *r; |
| 904 | struct compat_sg_req_info __user *o = (void __user *)arg; |
Andi Kleen | 2966387 | 2006-01-11 22:44:03 +0100 | [diff] [blame] | 905 | r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE); |
| 906 | err = sys_ioctl(fd,cmd,(unsigned long)r); |
| 907 | if (err < 0) |
| 908 | return err; |
| 909 | for (i = 0; i < SG_MAX_QUEUE; i++) { |
| 910 | void __user *ptr; |
| 911 | int d; |
| 912 | |
| 913 | if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) || |
| 914 | get_user(ptr, &r[i].usr_ptr) || |
| 915 | get_user(d, &r[i].duration) || |
| 916 | put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) || |
| 917 | put_user(d, &o[i].duration)) |
| 918 | return -EFAULT; |
| 919 | } |
| 920 | return err; |
| 921 | } |
| 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | struct sock_fprog32 { |
| 924 | unsigned short len; |
| 925 | compat_caddr_t filter; |
| 926 | }; |
| 927 | |
| 928 | #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) |
| 929 | #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) |
| 930 | |
| 931 | static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 932 | { |
| 933 | struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg); |
| 934 | struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog)); |
| 935 | void __user *fptr64; |
| 936 | u32 fptr32; |
| 937 | u16 flen; |
| 938 | |
| 939 | if (get_user(flen, &u_fprog32->len) || |
| 940 | get_user(fptr32, &u_fprog32->filter)) |
| 941 | return -EFAULT; |
| 942 | |
| 943 | fptr64 = compat_ptr(fptr32); |
| 944 | |
| 945 | if (put_user(flen, &u_fprog64->len) || |
| 946 | put_user(fptr64, &u_fprog64->filter)) |
| 947 | return -EFAULT; |
| 948 | |
| 949 | if (cmd == PPPIOCSPASS32) |
| 950 | cmd = PPPIOCSPASS; |
| 951 | else |
| 952 | cmd = PPPIOCSACTIVE; |
| 953 | |
| 954 | return sys_ioctl(fd, cmd, (unsigned long) u_fprog64); |
| 955 | } |
| 956 | |
| 957 | struct ppp_option_data32 { |
| 958 | compat_caddr_t ptr; |
| 959 | u32 length; |
| 960 | compat_int_t transmit; |
| 961 | }; |
| 962 | #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32) |
| 963 | |
| 964 | struct ppp_idle32 { |
| 965 | compat_time_t xmit_idle; |
| 966 | compat_time_t recv_idle; |
| 967 | }; |
| 968 | #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32) |
| 969 | |
| 970 | static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 971 | { |
| 972 | struct ppp_idle __user *idle; |
| 973 | struct ppp_idle32 __user *idle32; |
| 974 | __kernel_time_t xmit, recv; |
| 975 | int err; |
| 976 | |
| 977 | idle = compat_alloc_user_space(sizeof(*idle)); |
| 978 | idle32 = compat_ptr(arg); |
| 979 | |
| 980 | err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle); |
| 981 | |
| 982 | if (!err) { |
| 983 | if (get_user(xmit, &idle->xmit_idle) || |
| 984 | get_user(recv, &idle->recv_idle) || |
| 985 | put_user(xmit, &idle32->xmit_idle) || |
| 986 | put_user(recv, &idle32->recv_idle)) |
| 987 | err = -EFAULT; |
| 988 | } |
| 989 | return err; |
| 990 | } |
| 991 | |
| 992 | static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 993 | { |
| 994 | struct ppp_option_data __user *odata; |
| 995 | struct ppp_option_data32 __user *odata32; |
| 996 | __u32 data; |
| 997 | void __user *datap; |
| 998 | |
| 999 | odata = compat_alloc_user_space(sizeof(*odata)); |
| 1000 | odata32 = compat_ptr(arg); |
| 1001 | |
| 1002 | if (get_user(data, &odata32->ptr)) |
| 1003 | return -EFAULT; |
| 1004 | |
| 1005 | datap = compat_ptr(data); |
| 1006 | if (put_user(datap, &odata->ptr)) |
| 1007 | return -EFAULT; |
| 1008 | |
| 1009 | if (copy_in_user(&odata->length, &odata32->length, |
| 1010 | sizeof(__u32) + sizeof(int))) |
| 1011 | return -EFAULT; |
| 1012 | |
| 1013 | return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata); |
| 1014 | } |
| 1015 | |
| 1016 | static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1017 | { |
| 1018 | int err; |
| 1019 | |
| 1020 | switch (cmd) { |
| 1021 | case PPPIOCGIDLE32: |
| 1022 | err = ppp_gidle(fd, cmd, arg); |
| 1023 | break; |
| 1024 | |
| 1025 | case PPPIOCSCOMPRESS32: |
| 1026 | err = ppp_scompress(fd, cmd, arg); |
| 1027 | break; |
| 1028 | |
| 1029 | default: |
| 1030 | do { |
| 1031 | static int count; |
| 1032 | if (++count <= 20) |
| 1033 | printk("ppp_ioctl: Unknown cmd fd(%d) " |
| 1034 | "cmd(%08x) arg(%08x)\n", |
| 1035 | (int)fd, (unsigned int)cmd, (unsigned int)arg); |
| 1036 | } while(0); |
| 1037 | err = -EINVAL; |
| 1038 | break; |
| 1039 | }; |
| 1040 | |
| 1041 | return err; |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | struct mtget32 { |
| 1046 | compat_long_t mt_type; |
| 1047 | compat_long_t mt_resid; |
| 1048 | compat_long_t mt_dsreg; |
| 1049 | compat_long_t mt_gstat; |
| 1050 | compat_long_t mt_erreg; |
| 1051 | compat_daddr_t mt_fileno; |
| 1052 | compat_daddr_t mt_blkno; |
| 1053 | }; |
| 1054 | #define MTIOCGET32 _IOR('m', 2, struct mtget32) |
| 1055 | |
| 1056 | struct mtpos32 { |
| 1057 | compat_long_t mt_blkno; |
| 1058 | }; |
| 1059 | #define MTIOCPOS32 _IOR('m', 3, struct mtpos32) |
| 1060 | |
| 1061 | static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1062 | { |
| 1063 | mm_segment_t old_fs = get_fs(); |
| 1064 | struct mtget get; |
| 1065 | struct mtget32 __user *umget32; |
| 1066 | struct mtpos pos; |
| 1067 | struct mtpos32 __user *upos32; |
| 1068 | unsigned long kcmd; |
| 1069 | void *karg; |
| 1070 | int err = 0; |
| 1071 | |
| 1072 | switch(cmd) { |
| 1073 | case MTIOCPOS32: |
| 1074 | kcmd = MTIOCPOS; |
| 1075 | karg = &pos; |
| 1076 | break; |
| 1077 | case MTIOCGET32: |
| 1078 | kcmd = MTIOCGET; |
| 1079 | karg = &get; |
| 1080 | break; |
| 1081 | default: |
| 1082 | do { |
| 1083 | static int count; |
| 1084 | if (++count <= 20) |
| 1085 | printk("mt_ioctl: Unknown cmd fd(%d) " |
| 1086 | "cmd(%08x) arg(%08x)\n", |
| 1087 | (int)fd, (unsigned int)cmd, (unsigned int)arg); |
| 1088 | } while(0); |
| 1089 | return -EINVAL; |
| 1090 | } |
| 1091 | set_fs (KERNEL_DS); |
| 1092 | err = sys_ioctl (fd, kcmd, (unsigned long)karg); |
| 1093 | set_fs (old_fs); |
| 1094 | if (err) |
| 1095 | return err; |
| 1096 | switch (cmd) { |
| 1097 | case MTIOCPOS32: |
| 1098 | upos32 = compat_ptr(arg); |
| 1099 | err = __put_user(pos.mt_blkno, &upos32->mt_blkno); |
| 1100 | break; |
| 1101 | case MTIOCGET32: |
| 1102 | umget32 = compat_ptr(arg); |
| 1103 | err = __put_user(get.mt_type, &umget32->mt_type); |
| 1104 | err |= __put_user(get.mt_resid, &umget32->mt_resid); |
| 1105 | err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg); |
| 1106 | err |= __put_user(get.mt_gstat, &umget32->mt_gstat); |
| 1107 | err |= __put_user(get.mt_erreg, &umget32->mt_erreg); |
| 1108 | err |= __put_user(get.mt_fileno, &umget32->mt_fileno); |
| 1109 | err |= __put_user(get.mt_blkno, &umget32->mt_blkno); |
| 1110 | break; |
| 1111 | } |
| 1112 | return err ? -EFAULT: 0; |
| 1113 | } |
| 1114 | |
| 1115 | struct cdrom_read_audio32 { |
| 1116 | union cdrom_addr addr; |
| 1117 | u8 addr_format; |
| 1118 | compat_int_t nframes; |
| 1119 | compat_caddr_t buf; |
| 1120 | }; |
| 1121 | |
| 1122 | struct cdrom_generic_command32 { |
| 1123 | unsigned char cmd[CDROM_PACKET_SIZE]; |
| 1124 | compat_caddr_t buffer; |
| 1125 | compat_uint_t buflen; |
| 1126 | compat_int_t stat; |
| 1127 | compat_caddr_t sense; |
| 1128 | unsigned char data_direction; |
| 1129 | compat_int_t quiet; |
| 1130 | compat_int_t timeout; |
| 1131 | compat_caddr_t reserved[1]; |
| 1132 | }; |
| 1133 | |
| 1134 | static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1135 | { |
| 1136 | struct cdrom_read_audio __user *cdread_audio; |
| 1137 | struct cdrom_read_audio32 __user *cdread_audio32; |
| 1138 | __u32 data; |
| 1139 | void __user *datap; |
| 1140 | |
| 1141 | cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); |
| 1142 | cdread_audio32 = compat_ptr(arg); |
| 1143 | |
| 1144 | if (copy_in_user(&cdread_audio->addr, |
| 1145 | &cdread_audio32->addr, |
| 1146 | (sizeof(*cdread_audio32) - |
| 1147 | sizeof(compat_caddr_t)))) |
| 1148 | return -EFAULT; |
| 1149 | |
| 1150 | if (get_user(data, &cdread_audio32->buf)) |
| 1151 | return -EFAULT; |
| 1152 | datap = compat_ptr(data); |
| 1153 | if (put_user(datap, &cdread_audio->buf)) |
| 1154 | return -EFAULT; |
| 1155 | |
| 1156 | return sys_ioctl(fd, cmd, (unsigned long) cdread_audio); |
| 1157 | } |
| 1158 | |
| 1159 | static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1160 | { |
| 1161 | struct cdrom_generic_command __user *cgc; |
| 1162 | struct cdrom_generic_command32 __user *cgc32; |
| 1163 | u32 data; |
| 1164 | unsigned char dir; |
| 1165 | int itmp; |
| 1166 | |
| 1167 | cgc = compat_alloc_user_space(sizeof(*cgc)); |
| 1168 | cgc32 = compat_ptr(arg); |
| 1169 | |
| 1170 | if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || |
| 1171 | get_user(data, &cgc32->buffer) || |
| 1172 | put_user(compat_ptr(data), &cgc->buffer) || |
| 1173 | copy_in_user(&cgc->buflen, &cgc32->buflen, |
| 1174 | (sizeof(unsigned int) + sizeof(int))) || |
| 1175 | get_user(data, &cgc32->sense) || |
| 1176 | put_user(compat_ptr(data), &cgc->sense) || |
| 1177 | get_user(dir, &cgc32->data_direction) || |
| 1178 | put_user(dir, &cgc->data_direction) || |
| 1179 | get_user(itmp, &cgc32->quiet) || |
| 1180 | put_user(itmp, &cgc->quiet) || |
| 1181 | get_user(itmp, &cgc32->timeout) || |
| 1182 | put_user(itmp, &cgc->timeout) || |
| 1183 | get_user(data, &cgc32->reserved[0]) || |
| 1184 | put_user(compat_ptr(data), &cgc->reserved[0])) |
| 1185 | return -EFAULT; |
| 1186 | |
| 1187 | return sys_ioctl(fd, cmd, (unsigned long) cgc); |
| 1188 | } |
| 1189 | |
| 1190 | static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1191 | { |
| 1192 | int err; |
| 1193 | |
| 1194 | switch(cmd) { |
| 1195 | case CDROMREADAUDIO: |
| 1196 | err = cdrom_do_read_audio(fd, cmd, arg); |
| 1197 | break; |
| 1198 | |
| 1199 | case CDROM_SEND_PACKET: |
| 1200 | err = cdrom_do_generic_command(fd, cmd, arg); |
| 1201 | break; |
| 1202 | |
| 1203 | default: |
| 1204 | do { |
| 1205 | static int count; |
| 1206 | if (++count <= 20) |
| 1207 | printk("cdrom_ioctl: Unknown cmd fd(%d) " |
| 1208 | "cmd(%08x) arg(%08x)\n", |
| 1209 | (int)fd, (unsigned int)cmd, (unsigned int)arg); |
| 1210 | } while(0); |
| 1211 | err = -EINVAL; |
| 1212 | break; |
| 1213 | }; |
| 1214 | |
| 1215 | return err; |
| 1216 | } |
| 1217 | |
| 1218 | struct loop_info32 { |
| 1219 | compat_int_t lo_number; /* ioctl r/o */ |
| 1220 | compat_dev_t lo_device; /* ioctl r/o */ |
| 1221 | compat_ulong_t lo_inode; /* ioctl r/o */ |
| 1222 | compat_dev_t lo_rdevice; /* ioctl r/o */ |
| 1223 | compat_int_t lo_offset; |
| 1224 | compat_int_t lo_encrypt_type; |
| 1225 | compat_int_t lo_encrypt_key_size; /* ioctl w/o */ |
| 1226 | compat_int_t lo_flags; /* ioctl r/o */ |
| 1227 | char lo_name[LO_NAME_SIZE]; |
| 1228 | unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ |
| 1229 | compat_ulong_t lo_init[2]; |
| 1230 | char reserved[4]; |
| 1231 | }; |
| 1232 | |
| 1233 | static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1234 | { |
| 1235 | mm_segment_t old_fs = get_fs(); |
| 1236 | struct loop_info l; |
| 1237 | struct loop_info32 __user *ul; |
| 1238 | int err = -EINVAL; |
| 1239 | |
| 1240 | ul = compat_ptr(arg); |
| 1241 | switch(cmd) { |
| 1242 | case LOOP_SET_STATUS: |
| 1243 | err = get_user(l.lo_number, &ul->lo_number); |
| 1244 | err |= __get_user(l.lo_device, &ul->lo_device); |
| 1245 | err |= __get_user(l.lo_inode, &ul->lo_inode); |
| 1246 | err |= __get_user(l.lo_rdevice, &ul->lo_rdevice); |
| 1247 | err |= __copy_from_user(&l.lo_offset, &ul->lo_offset, |
| 1248 | 8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset); |
| 1249 | if (err) { |
| 1250 | err = -EFAULT; |
| 1251 | } else { |
| 1252 | set_fs (KERNEL_DS); |
| 1253 | err = sys_ioctl (fd, cmd, (unsigned long)&l); |
| 1254 | set_fs (old_fs); |
| 1255 | } |
| 1256 | break; |
| 1257 | case LOOP_GET_STATUS: |
| 1258 | set_fs (KERNEL_DS); |
| 1259 | err = sys_ioctl (fd, cmd, (unsigned long)&l); |
| 1260 | set_fs (old_fs); |
| 1261 | if (!err) { |
| 1262 | err = put_user(l.lo_number, &ul->lo_number); |
| 1263 | err |= __put_user(l.lo_device, &ul->lo_device); |
| 1264 | err |= __put_user(l.lo_inode, &ul->lo_inode); |
| 1265 | err |= __put_user(l.lo_rdevice, &ul->lo_rdevice); |
| 1266 | err |= __copy_to_user(&ul->lo_offset, &l.lo_offset, |
| 1267 | (unsigned long)l.lo_init - (unsigned long)&l.lo_offset); |
| 1268 | if (err) |
| 1269 | err = -EFAULT; |
| 1270 | } |
| 1271 | break; |
| 1272 | default: { |
| 1273 | static int count; |
| 1274 | if (++count <= 20) |
| 1275 | printk("%s: Unknown loop ioctl cmd, fd(%d) " |
| 1276 | "cmd(%08x) arg(%08lx)\n", |
| 1277 | __FUNCTION__, fd, cmd, arg); |
| 1278 | } |
| 1279 | } |
| 1280 | return err; |
| 1281 | } |
| 1282 | |
| 1283 | extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg); |
| 1284 | |
| 1285 | #ifdef CONFIG_VT |
| 1286 | |
| 1287 | static int vt_check(struct file *file) |
| 1288 | { |
| 1289 | struct tty_struct *tty; |
| 1290 | struct inode *inode = file->f_dentry->d_inode; |
| 1291 | |
| 1292 | if (file->f_op->ioctl != tty_ioctl) |
| 1293 | return -EINVAL; |
| 1294 | |
| 1295 | tty = (struct tty_struct *)file->private_data; |
| 1296 | if (tty_paranoia_check(tty, inode, "tty_ioctl")) |
| 1297 | return -EINVAL; |
| 1298 | |
| 1299 | if (tty->driver->ioctl != vt_ioctl) |
| 1300 | return -EINVAL; |
| 1301 | |
| 1302 | /* |
| 1303 | * To have permissions to do most of the vt ioctls, we either have |
| 1304 | * to be the owner of the tty, or super-user. |
| 1305 | */ |
| 1306 | if (current->signal->tty == tty || capable(CAP_SYS_ADMIN)) |
| 1307 | return 1; |
| 1308 | return 0; |
| 1309 | } |
| 1310 | |
| 1311 | struct consolefontdesc32 { |
| 1312 | unsigned short charcount; /* characters in font (256 or 512) */ |
| 1313 | unsigned short charheight; /* scan lines per character (1-32) */ |
| 1314 | compat_caddr_t chardata; /* font data in expanded form */ |
| 1315 | }; |
| 1316 | |
| 1317 | static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) |
| 1318 | { |
| 1319 | struct consolefontdesc32 __user *user_cfd = compat_ptr(arg); |
| 1320 | struct console_font_op op; |
| 1321 | compat_caddr_t data; |
| 1322 | int i, perm; |
| 1323 | |
| 1324 | perm = vt_check(file); |
| 1325 | if (perm < 0) return perm; |
| 1326 | |
| 1327 | switch (cmd) { |
| 1328 | case PIO_FONTX: |
| 1329 | if (!perm) |
| 1330 | return -EPERM; |
| 1331 | op.op = KD_FONT_OP_SET; |
| 1332 | op.flags = 0; |
| 1333 | op.width = 8; |
| 1334 | if (get_user(op.height, &user_cfd->charheight) || |
| 1335 | get_user(op.charcount, &user_cfd->charcount) || |
| 1336 | get_user(data, &user_cfd->chardata)) |
| 1337 | return -EFAULT; |
| 1338 | op.data = compat_ptr(data); |
| 1339 | return con_font_op(vc_cons[fg_console].d, &op); |
| 1340 | case GIO_FONTX: |
| 1341 | op.op = KD_FONT_OP_GET; |
| 1342 | op.flags = 0; |
| 1343 | op.width = 8; |
| 1344 | if (get_user(op.height, &user_cfd->charheight) || |
| 1345 | get_user(op.charcount, &user_cfd->charcount) || |
| 1346 | get_user(data, &user_cfd->chardata)) |
| 1347 | return -EFAULT; |
| 1348 | if (!data) |
| 1349 | return 0; |
| 1350 | op.data = compat_ptr(data); |
| 1351 | i = con_font_op(vc_cons[fg_console].d, &op); |
| 1352 | if (i) |
| 1353 | return i; |
| 1354 | if (put_user(op.height, &user_cfd->charheight) || |
| 1355 | put_user(op.charcount, &user_cfd->charcount) || |
| 1356 | put_user((compat_caddr_t)(unsigned long)op.data, |
| 1357 | &user_cfd->chardata)) |
| 1358 | return -EFAULT; |
| 1359 | return 0; |
| 1360 | } |
| 1361 | return -EINVAL; |
| 1362 | } |
| 1363 | |
| 1364 | struct console_font_op32 { |
| 1365 | compat_uint_t op; /* operation code KD_FONT_OP_* */ |
| 1366 | compat_uint_t flags; /* KD_FONT_FLAG_* */ |
| 1367 | compat_uint_t width, height; /* font size */ |
| 1368 | compat_uint_t charcount; |
| 1369 | compat_caddr_t data; /* font data with height fixed to 32 */ |
| 1370 | }; |
| 1371 | |
| 1372 | static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) |
| 1373 | { |
| 1374 | struct console_font_op op; |
| 1375 | struct console_font_op32 __user *fontop = compat_ptr(arg); |
| 1376 | int perm = vt_check(file), i; |
| 1377 | struct vc_data *vc; |
| 1378 | |
| 1379 | if (perm < 0) return perm; |
| 1380 | |
| 1381 | if (copy_from_user(&op, fontop, sizeof(struct console_font_op32))) |
| 1382 | return -EFAULT; |
| 1383 | if (!perm && op.op != KD_FONT_OP_GET) |
| 1384 | return -EPERM; |
| 1385 | op.data = compat_ptr(((struct console_font_op32 *)&op)->data); |
| 1386 | op.flags |= KD_FONT_FLAG_OLD; |
| 1387 | vc = ((struct tty_struct *)file->private_data)->driver_data; |
| 1388 | i = con_font_op(vc, &op); |
| 1389 | if (i) |
| 1390 | return i; |
| 1391 | ((struct console_font_op32 *)&op)->data = (unsigned long)op.data; |
| 1392 | if (copy_to_user(fontop, &op, sizeof(struct console_font_op32))) |
| 1393 | return -EFAULT; |
| 1394 | return 0; |
| 1395 | } |
| 1396 | |
| 1397 | struct unimapdesc32 { |
| 1398 | unsigned short entry_ct; |
| 1399 | compat_caddr_t entries; |
| 1400 | }; |
| 1401 | |
| 1402 | static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file) |
| 1403 | { |
| 1404 | struct unimapdesc32 tmp; |
| 1405 | struct unimapdesc32 __user *user_ud = compat_ptr(arg); |
| 1406 | int perm = vt_check(file); |
| 1407 | |
| 1408 | if (perm < 0) return perm; |
| 1409 | if (copy_from_user(&tmp, user_ud, sizeof tmp)) |
| 1410 | return -EFAULT; |
| 1411 | switch (cmd) { |
| 1412 | case PIO_UNIMAP: |
| 1413 | if (!perm) return -EPERM; |
| 1414 | return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries)); |
| 1415 | case GIO_UNIMAP: |
| 1416 | return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries)); |
| 1417 | } |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | #endif /* CONFIG_VT */ |
| 1422 | |
| 1423 | static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1424 | { |
| 1425 | mm_segment_t old_fs = get_fs(); |
| 1426 | __kernel_uid_t kuid; |
| 1427 | int err; |
| 1428 | |
| 1429 | cmd = SMB_IOC_GETMOUNTUID; |
| 1430 | |
| 1431 | set_fs(KERNEL_DS); |
| 1432 | err = sys_ioctl(fd, cmd, (unsigned long)&kuid); |
| 1433 | set_fs(old_fs); |
| 1434 | |
| 1435 | if (err >= 0) |
| 1436 | err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg)); |
| 1437 | |
| 1438 | return err; |
| 1439 | } |
| 1440 | |
| 1441 | struct atmif_sioc32 { |
| 1442 | compat_int_t number; |
| 1443 | compat_int_t length; |
| 1444 | compat_caddr_t arg; |
| 1445 | }; |
| 1446 | |
| 1447 | struct atm_iobuf32 { |
| 1448 | compat_int_t length; |
| 1449 | compat_caddr_t buffer; |
| 1450 | }; |
| 1451 | |
| 1452 | #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32) |
| 1453 | #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32) |
| 1454 | #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32) |
| 1455 | #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32) |
| 1456 | #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32) |
| 1457 | #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32) |
| 1458 | #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32) |
| 1459 | #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32) |
| 1460 | #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32) |
| 1461 | #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32) |
| 1462 | #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32) |
| 1463 | #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32) |
| 1464 | #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32) |
| 1465 | #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32) |
| 1466 | #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32) |
| 1467 | #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32) |
| 1468 | #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32) |
| 1469 | |
| 1470 | static struct { |
| 1471 | unsigned int cmd32; |
| 1472 | unsigned int cmd; |
| 1473 | } atm_ioctl_map[] = { |
| 1474 | { ATM_GETLINKRATE32, ATM_GETLINKRATE }, |
| 1475 | { ATM_GETNAMES32, ATM_GETNAMES }, |
| 1476 | { ATM_GETTYPE32, ATM_GETTYPE }, |
| 1477 | { ATM_GETESI32, ATM_GETESI }, |
| 1478 | { ATM_GETADDR32, ATM_GETADDR }, |
| 1479 | { ATM_RSTADDR32, ATM_RSTADDR }, |
| 1480 | { ATM_ADDADDR32, ATM_ADDADDR }, |
| 1481 | { ATM_DELADDR32, ATM_DELADDR }, |
| 1482 | { ATM_GETCIRANGE32, ATM_GETCIRANGE }, |
| 1483 | { ATM_SETCIRANGE32, ATM_SETCIRANGE }, |
| 1484 | { ATM_SETESI32, ATM_SETESI }, |
| 1485 | { ATM_SETESIF32, ATM_SETESIF }, |
| 1486 | { ATM_GETSTAT32, ATM_GETSTAT }, |
| 1487 | { ATM_GETSTATZ32, ATM_GETSTATZ }, |
| 1488 | { ATM_GETLOOP32, ATM_GETLOOP }, |
| 1489 | { ATM_SETLOOP32, ATM_SETLOOP }, |
| 1490 | { ATM_QUERYLOOP32, ATM_QUERYLOOP } |
| 1491 | }; |
| 1492 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 1493 | #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
| 1495 | static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1496 | { |
| 1497 | struct atm_iobuf __user *iobuf; |
| 1498 | struct atm_iobuf32 __user *iobuf32; |
| 1499 | u32 data; |
| 1500 | void __user *datap; |
| 1501 | int len, err; |
| 1502 | |
| 1503 | iobuf = compat_alloc_user_space(sizeof(*iobuf)); |
| 1504 | iobuf32 = compat_ptr(arg); |
| 1505 | |
| 1506 | if (get_user(len, &iobuf32->length) || |
| 1507 | get_user(data, &iobuf32->buffer)) |
| 1508 | return -EFAULT; |
| 1509 | datap = compat_ptr(data); |
| 1510 | if (put_user(len, &iobuf->length) || |
| 1511 | put_user(datap, &iobuf->buffer)) |
| 1512 | return -EFAULT; |
| 1513 | |
| 1514 | err = sys_ioctl(fd, cmd, (unsigned long)iobuf); |
| 1515 | |
| 1516 | if (!err) { |
| 1517 | if (copy_in_user(&iobuf32->length, &iobuf->length, |
| 1518 | sizeof(int))) |
| 1519 | err = -EFAULT; |
| 1520 | } |
| 1521 | |
| 1522 | return err; |
| 1523 | } |
| 1524 | |
| 1525 | static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1526 | { |
| 1527 | struct atmif_sioc __user *sioc; |
| 1528 | struct atmif_sioc32 __user *sioc32; |
| 1529 | u32 data; |
| 1530 | void __user *datap; |
| 1531 | int err; |
| 1532 | |
| 1533 | sioc = compat_alloc_user_space(sizeof(*sioc)); |
| 1534 | sioc32 = compat_ptr(arg); |
| 1535 | |
| 1536 | if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) || |
| 1537 | get_user(data, &sioc32->arg)) |
| 1538 | return -EFAULT; |
| 1539 | datap = compat_ptr(data); |
| 1540 | if (put_user(datap, &sioc->arg)) |
| 1541 | return -EFAULT; |
| 1542 | |
| 1543 | err = sys_ioctl(fd, cmd, (unsigned long) sioc); |
| 1544 | |
| 1545 | if (!err) { |
| 1546 | if (copy_in_user(&sioc32->length, &sioc->length, |
| 1547 | sizeof(int))) |
| 1548 | err = -EFAULT; |
| 1549 | } |
| 1550 | return err; |
| 1551 | } |
| 1552 | |
| 1553 | static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg) |
| 1554 | { |
| 1555 | int i; |
| 1556 | unsigned int cmd = 0; |
| 1557 | |
| 1558 | switch (cmd32) { |
| 1559 | case SONET_GETSTAT: |
| 1560 | case SONET_GETSTATZ: |
| 1561 | case SONET_GETDIAG: |
| 1562 | case SONET_SETDIAG: |
| 1563 | case SONET_CLRDIAG: |
| 1564 | case SONET_SETFRAMING: |
| 1565 | case SONET_GETFRAMING: |
| 1566 | case SONET_GETFRSENSE: |
| 1567 | return do_atmif_sioc(fd, cmd32, arg); |
| 1568 | } |
| 1569 | |
| 1570 | for (i = 0; i < NR_ATM_IOCTL; i++) { |
| 1571 | if (cmd32 == atm_ioctl_map[i].cmd32) { |
| 1572 | cmd = atm_ioctl_map[i].cmd; |
| 1573 | break; |
| 1574 | } |
| 1575 | } |
| 1576 | if (i == NR_ATM_IOCTL) |
| 1577 | return -EINVAL; |
| 1578 | |
| 1579 | switch (cmd) { |
| 1580 | case ATM_GETNAMES: |
| 1581 | return do_atm_iobuf(fd, cmd, arg); |
| 1582 | |
| 1583 | case ATM_GETLINKRATE: |
| 1584 | case ATM_GETTYPE: |
| 1585 | case ATM_GETESI: |
| 1586 | case ATM_GETADDR: |
| 1587 | case ATM_RSTADDR: |
| 1588 | case ATM_ADDADDR: |
| 1589 | case ATM_DELADDR: |
| 1590 | case ATM_GETCIRANGE: |
| 1591 | case ATM_SETCIRANGE: |
| 1592 | case ATM_SETESI: |
| 1593 | case ATM_SETESIF: |
| 1594 | case ATM_GETSTAT: |
| 1595 | case ATM_GETSTATZ: |
| 1596 | case ATM_GETLOOP: |
| 1597 | case ATM_SETLOOP: |
| 1598 | case ATM_QUERYLOOP: |
| 1599 | return do_atmif_sioc(fd, cmd, arg); |
| 1600 | } |
| 1601 | |
| 1602 | return -EINVAL; |
| 1603 | } |
| 1604 | |
| 1605 | static __attribute_used__ int |
| 1606 | ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1607 | { |
| 1608 | return -EINVAL; |
| 1609 | } |
| 1610 | |
| 1611 | static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1612 | { |
| 1613 | /* The mkswap binary hard codes it to Intel value :-((( */ |
| 1614 | return w_long(fd, BLKGETSIZE, arg); |
| 1615 | } |
| 1616 | |
| 1617 | struct blkpg_ioctl_arg32 { |
| 1618 | compat_int_t op; |
| 1619 | compat_int_t flags; |
| 1620 | compat_int_t datalen; |
| 1621 | compat_caddr_t data; |
| 1622 | }; |
| 1623 | |
| 1624 | static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1625 | { |
| 1626 | struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg); |
| 1627 | struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); |
| 1628 | compat_caddr_t udata; |
| 1629 | compat_int_t n; |
| 1630 | int err; |
| 1631 | |
| 1632 | err = get_user(n, &ua32->op); |
| 1633 | err |= put_user(n, &a->op); |
| 1634 | err |= get_user(n, &ua32->flags); |
| 1635 | err |= put_user(n, &a->flags); |
| 1636 | err |= get_user(n, &ua32->datalen); |
| 1637 | err |= put_user(n, &a->datalen); |
| 1638 | err |= get_user(udata, &ua32->data); |
| 1639 | err |= put_user(compat_ptr(udata), &a->data); |
| 1640 | if (err) |
| 1641 | return err; |
| 1642 | |
| 1643 | return sys_ioctl(fd, cmd, (unsigned long)a); |
| 1644 | } |
| 1645 | |
| 1646 | static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1647 | { |
| 1648 | return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg); |
| 1649 | } |
| 1650 | |
| 1651 | /* Fix sizeof(sizeof()) breakage */ |
| 1652 | #define BLKBSZGET_32 _IOR(0x12,112,int) |
| 1653 | #define BLKBSZSET_32 _IOW(0x12,113,int) |
| 1654 | #define BLKGETSIZE64_32 _IOR(0x12,114,int) |
| 1655 | |
| 1656 | static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1657 | { |
| 1658 | return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg)); |
| 1659 | } |
| 1660 | |
| 1661 | static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1662 | { |
| 1663 | return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg)); |
| 1664 | } |
| 1665 | |
| 1666 | static int do_blkgetsize64(unsigned int fd, unsigned int cmd, |
| 1667 | unsigned long arg) |
| 1668 | { |
| 1669 | return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg)); |
| 1670 | } |
| 1671 | |
| 1672 | /* Bluetooth ioctls */ |
| 1673 | #define HCIUARTSETPROTO _IOW('U', 200, int) |
| 1674 | #define HCIUARTGETPROTO _IOR('U', 201, int) |
| 1675 | |
| 1676 | #define BNEPCONNADD _IOW('B', 200, int) |
| 1677 | #define BNEPCONNDEL _IOW('B', 201, int) |
| 1678 | #define BNEPGETCONNLIST _IOR('B', 210, int) |
| 1679 | #define BNEPGETCONNINFO _IOR('B', 211, int) |
| 1680 | |
| 1681 | #define CMTPCONNADD _IOW('C', 200, int) |
| 1682 | #define CMTPCONNDEL _IOW('C', 201, int) |
| 1683 | #define CMTPGETCONNLIST _IOR('C', 210, int) |
| 1684 | #define CMTPGETCONNINFO _IOR('C', 211, int) |
| 1685 | |
| 1686 | #define HIDPCONNADD _IOW('H', 200, int) |
| 1687 | #define HIDPCONNDEL _IOW('H', 201, int) |
| 1688 | #define HIDPGETCONNLIST _IOR('H', 210, int) |
| 1689 | #define HIDPGETCONNINFO _IOR('H', 211, int) |
| 1690 | |
| 1691 | struct floppy_struct32 { |
| 1692 | compat_uint_t size; |
| 1693 | compat_uint_t sect; |
| 1694 | compat_uint_t head; |
| 1695 | compat_uint_t track; |
| 1696 | compat_uint_t stretch; |
| 1697 | unsigned char gap; |
| 1698 | unsigned char rate; |
| 1699 | unsigned char spec1; |
| 1700 | unsigned char fmt_gap; |
| 1701 | const compat_caddr_t name; |
| 1702 | }; |
| 1703 | |
| 1704 | struct floppy_drive_params32 { |
| 1705 | char cmos; |
| 1706 | compat_ulong_t max_dtr; |
| 1707 | compat_ulong_t hlt; |
| 1708 | compat_ulong_t hut; |
| 1709 | compat_ulong_t srt; |
| 1710 | compat_ulong_t spinup; |
| 1711 | compat_ulong_t spindown; |
| 1712 | unsigned char spindown_offset; |
| 1713 | unsigned char select_delay; |
| 1714 | unsigned char rps; |
| 1715 | unsigned char tracks; |
| 1716 | compat_ulong_t timeout; |
| 1717 | unsigned char interleave_sect; |
| 1718 | struct floppy_max_errors max_errors; |
| 1719 | char flags; |
| 1720 | char read_track; |
| 1721 | short autodetect[8]; |
| 1722 | compat_int_t checkfreq; |
| 1723 | compat_int_t native_format; |
| 1724 | }; |
| 1725 | |
| 1726 | struct floppy_drive_struct32 { |
| 1727 | signed char flags; |
| 1728 | compat_ulong_t spinup_date; |
| 1729 | compat_ulong_t select_date; |
| 1730 | compat_ulong_t first_read_date; |
| 1731 | short probed_format; |
| 1732 | short track; |
| 1733 | short maxblock; |
| 1734 | short maxtrack; |
| 1735 | compat_int_t generation; |
| 1736 | compat_int_t keep_data; |
| 1737 | compat_int_t fd_ref; |
| 1738 | compat_int_t fd_device; |
| 1739 | compat_int_t last_checked; |
| 1740 | compat_caddr_t dmabuf; |
| 1741 | compat_int_t bufblocks; |
| 1742 | }; |
| 1743 | |
| 1744 | struct floppy_fdc_state32 { |
| 1745 | compat_int_t spec1; |
| 1746 | compat_int_t spec2; |
| 1747 | compat_int_t dtr; |
| 1748 | unsigned char version; |
| 1749 | unsigned char dor; |
| 1750 | compat_ulong_t address; |
| 1751 | unsigned int rawcmd:2; |
| 1752 | unsigned int reset:1; |
| 1753 | unsigned int need_configure:1; |
| 1754 | unsigned int perp_mode:2; |
| 1755 | unsigned int has_fifo:1; |
| 1756 | unsigned int driver_version; |
| 1757 | unsigned char track[4]; |
| 1758 | }; |
| 1759 | |
| 1760 | struct floppy_write_errors32 { |
| 1761 | unsigned int write_errors; |
| 1762 | compat_ulong_t first_error_sector; |
| 1763 | compat_int_t first_error_generation; |
| 1764 | compat_ulong_t last_error_sector; |
| 1765 | compat_int_t last_error_generation; |
| 1766 | compat_uint_t badness; |
| 1767 | }; |
| 1768 | |
| 1769 | #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32) |
| 1770 | #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32) |
| 1771 | #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32) |
| 1772 | #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32) |
| 1773 | #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32) |
| 1774 | #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32) |
| 1775 | #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32) |
| 1776 | #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32) |
| 1777 | #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32) |
| 1778 | |
| 1779 | static struct { |
| 1780 | unsigned int cmd32; |
| 1781 | unsigned int cmd; |
| 1782 | } fd_ioctl_trans_table[] = { |
| 1783 | { FDSETPRM32, FDSETPRM }, |
| 1784 | { FDDEFPRM32, FDDEFPRM }, |
| 1785 | { FDGETPRM32, FDGETPRM }, |
| 1786 | { FDSETDRVPRM32, FDSETDRVPRM }, |
| 1787 | { FDGETDRVPRM32, FDGETDRVPRM }, |
| 1788 | { FDGETDRVSTAT32, FDGETDRVSTAT }, |
| 1789 | { FDPOLLDRVSTAT32, FDPOLLDRVSTAT }, |
| 1790 | { FDGETFDCSTAT32, FDGETFDCSTAT }, |
| 1791 | { FDWERRORGET32, FDWERRORGET } |
| 1792 | }; |
| 1793 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 1794 | #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | |
| 1796 | static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 1797 | { |
| 1798 | mm_segment_t old_fs = get_fs(); |
| 1799 | void *karg = NULL; |
| 1800 | unsigned int kcmd = 0; |
| 1801 | int i, err; |
| 1802 | |
| 1803 | for (i = 0; i < NR_FD_IOCTL_TRANS; i++) |
| 1804 | if (cmd == fd_ioctl_trans_table[i].cmd32) { |
| 1805 | kcmd = fd_ioctl_trans_table[i].cmd; |
| 1806 | break; |
| 1807 | } |
| 1808 | if (!kcmd) |
| 1809 | return -EINVAL; |
| 1810 | |
| 1811 | switch (cmd) { |
| 1812 | case FDSETPRM32: |
| 1813 | case FDDEFPRM32: |
| 1814 | case FDGETPRM32: |
| 1815 | { |
| 1816 | compat_uptr_t name; |
| 1817 | struct floppy_struct32 __user *uf; |
| 1818 | struct floppy_struct *f; |
| 1819 | |
| 1820 | uf = compat_ptr(arg); |
| 1821 | f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL); |
| 1822 | if (!karg) |
| 1823 | return -ENOMEM; |
| 1824 | if (cmd == FDGETPRM32) |
| 1825 | break; |
| 1826 | err = __get_user(f->size, &uf->size); |
| 1827 | err |= __get_user(f->sect, &uf->sect); |
| 1828 | err |= __get_user(f->head, &uf->head); |
| 1829 | err |= __get_user(f->track, &uf->track); |
| 1830 | err |= __get_user(f->stretch, &uf->stretch); |
| 1831 | err |= __get_user(f->gap, &uf->gap); |
| 1832 | err |= __get_user(f->rate, &uf->rate); |
| 1833 | err |= __get_user(f->spec1, &uf->spec1); |
| 1834 | err |= __get_user(f->fmt_gap, &uf->fmt_gap); |
| 1835 | err |= __get_user(name, &uf->name); |
| 1836 | f->name = compat_ptr(name); |
| 1837 | if (err) { |
| 1838 | err = -EFAULT; |
| 1839 | goto out; |
| 1840 | } |
| 1841 | break; |
| 1842 | } |
| 1843 | case FDSETDRVPRM32: |
| 1844 | case FDGETDRVPRM32: |
| 1845 | { |
| 1846 | struct floppy_drive_params32 __user *uf; |
| 1847 | struct floppy_drive_params *f; |
| 1848 | |
| 1849 | uf = compat_ptr(arg); |
| 1850 | f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL); |
| 1851 | if (!karg) |
| 1852 | return -ENOMEM; |
| 1853 | if (cmd == FDGETDRVPRM32) |
| 1854 | break; |
| 1855 | err = __get_user(f->cmos, &uf->cmos); |
| 1856 | err |= __get_user(f->max_dtr, &uf->max_dtr); |
| 1857 | err |= __get_user(f->hlt, &uf->hlt); |
| 1858 | err |= __get_user(f->hut, &uf->hut); |
| 1859 | err |= __get_user(f->srt, &uf->srt); |
| 1860 | err |= __get_user(f->spinup, &uf->spinup); |
| 1861 | err |= __get_user(f->spindown, &uf->spindown); |
| 1862 | err |= __get_user(f->spindown_offset, &uf->spindown_offset); |
| 1863 | err |= __get_user(f->select_delay, &uf->select_delay); |
| 1864 | err |= __get_user(f->rps, &uf->rps); |
| 1865 | err |= __get_user(f->tracks, &uf->tracks); |
| 1866 | err |= __get_user(f->timeout, &uf->timeout); |
| 1867 | err |= __get_user(f->interleave_sect, &uf->interleave_sect); |
| 1868 | err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors)); |
| 1869 | err |= __get_user(f->flags, &uf->flags); |
| 1870 | err |= __get_user(f->read_track, &uf->read_track); |
| 1871 | err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect)); |
| 1872 | err |= __get_user(f->checkfreq, &uf->checkfreq); |
| 1873 | err |= __get_user(f->native_format, &uf->native_format); |
| 1874 | if (err) { |
| 1875 | err = -EFAULT; |
| 1876 | goto out; |
| 1877 | } |
| 1878 | break; |
| 1879 | } |
| 1880 | case FDGETDRVSTAT32: |
| 1881 | case FDPOLLDRVSTAT32: |
| 1882 | karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL); |
| 1883 | if (!karg) |
| 1884 | return -ENOMEM; |
| 1885 | break; |
| 1886 | case FDGETFDCSTAT32: |
| 1887 | karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL); |
| 1888 | if (!karg) |
| 1889 | return -ENOMEM; |
| 1890 | break; |
| 1891 | case FDWERRORGET32: |
| 1892 | karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL); |
| 1893 | if (!karg) |
| 1894 | return -ENOMEM; |
| 1895 | break; |
| 1896 | default: |
| 1897 | return -EINVAL; |
| 1898 | } |
| 1899 | set_fs (KERNEL_DS); |
| 1900 | err = sys_ioctl (fd, kcmd, (unsigned long)karg); |
| 1901 | set_fs (old_fs); |
| 1902 | if (err) |
| 1903 | goto out; |
| 1904 | switch (cmd) { |
| 1905 | case FDGETPRM32: |
| 1906 | { |
| 1907 | struct floppy_struct *f = karg; |
| 1908 | struct floppy_struct32 __user *uf = compat_ptr(arg); |
| 1909 | |
| 1910 | err = __put_user(f->size, &uf->size); |
| 1911 | err |= __put_user(f->sect, &uf->sect); |
| 1912 | err |= __put_user(f->head, &uf->head); |
| 1913 | err |= __put_user(f->track, &uf->track); |
| 1914 | err |= __put_user(f->stretch, &uf->stretch); |
| 1915 | err |= __put_user(f->gap, &uf->gap); |
| 1916 | err |= __put_user(f->rate, &uf->rate); |
| 1917 | err |= __put_user(f->spec1, &uf->spec1); |
| 1918 | err |= __put_user(f->fmt_gap, &uf->fmt_gap); |
| 1919 | err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name); |
| 1920 | break; |
| 1921 | } |
| 1922 | case FDGETDRVPRM32: |
| 1923 | { |
| 1924 | struct floppy_drive_params32 __user *uf; |
| 1925 | struct floppy_drive_params *f = karg; |
| 1926 | |
| 1927 | uf = compat_ptr(arg); |
| 1928 | err = __put_user(f->cmos, &uf->cmos); |
| 1929 | err |= __put_user(f->max_dtr, &uf->max_dtr); |
| 1930 | err |= __put_user(f->hlt, &uf->hlt); |
| 1931 | err |= __put_user(f->hut, &uf->hut); |
| 1932 | err |= __put_user(f->srt, &uf->srt); |
| 1933 | err |= __put_user(f->spinup, &uf->spinup); |
| 1934 | err |= __put_user(f->spindown, &uf->spindown); |
| 1935 | err |= __put_user(f->spindown_offset, &uf->spindown_offset); |
| 1936 | err |= __put_user(f->select_delay, &uf->select_delay); |
| 1937 | err |= __put_user(f->rps, &uf->rps); |
| 1938 | err |= __put_user(f->tracks, &uf->tracks); |
| 1939 | err |= __put_user(f->timeout, &uf->timeout); |
| 1940 | err |= __put_user(f->interleave_sect, &uf->interleave_sect); |
| 1941 | err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors)); |
| 1942 | err |= __put_user(f->flags, &uf->flags); |
| 1943 | err |= __put_user(f->read_track, &uf->read_track); |
| 1944 | err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect)); |
| 1945 | err |= __put_user(f->checkfreq, &uf->checkfreq); |
| 1946 | err |= __put_user(f->native_format, &uf->native_format); |
| 1947 | break; |
| 1948 | } |
| 1949 | case FDGETDRVSTAT32: |
| 1950 | case FDPOLLDRVSTAT32: |
| 1951 | { |
| 1952 | struct floppy_drive_struct32 __user *uf; |
| 1953 | struct floppy_drive_struct *f = karg; |
| 1954 | |
| 1955 | uf = compat_ptr(arg); |
| 1956 | err = __put_user(f->flags, &uf->flags); |
| 1957 | err |= __put_user(f->spinup_date, &uf->spinup_date); |
| 1958 | err |= __put_user(f->select_date, &uf->select_date); |
| 1959 | err |= __put_user(f->first_read_date, &uf->first_read_date); |
| 1960 | err |= __put_user(f->probed_format, &uf->probed_format); |
| 1961 | err |= __put_user(f->track, &uf->track); |
| 1962 | err |= __put_user(f->maxblock, &uf->maxblock); |
| 1963 | err |= __put_user(f->maxtrack, &uf->maxtrack); |
| 1964 | err |= __put_user(f->generation, &uf->generation); |
| 1965 | err |= __put_user(f->keep_data, &uf->keep_data); |
| 1966 | err |= __put_user(f->fd_ref, &uf->fd_ref); |
| 1967 | err |= __put_user(f->fd_device, &uf->fd_device); |
| 1968 | err |= __put_user(f->last_checked, &uf->last_checked); |
| 1969 | err |= __put_user((u64)f->dmabuf, &uf->dmabuf); |
| 1970 | err |= __put_user((u64)f->bufblocks, &uf->bufblocks); |
| 1971 | break; |
| 1972 | } |
| 1973 | case FDGETFDCSTAT32: |
| 1974 | { |
| 1975 | struct floppy_fdc_state32 __user *uf; |
| 1976 | struct floppy_fdc_state *f = karg; |
| 1977 | |
| 1978 | uf = compat_ptr(arg); |
| 1979 | err = __put_user(f->spec1, &uf->spec1); |
| 1980 | err |= __put_user(f->spec2, &uf->spec2); |
| 1981 | err |= __put_user(f->dtr, &uf->dtr); |
| 1982 | err |= __put_user(f->version, &uf->version); |
| 1983 | err |= __put_user(f->dor, &uf->dor); |
| 1984 | err |= __put_user(f->address, &uf->address); |
| 1985 | err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address), |
| 1986 | (char *)&f->address + sizeof(f->address), sizeof(int)); |
| 1987 | err |= __put_user(f->driver_version, &uf->driver_version); |
| 1988 | err |= __copy_to_user(uf->track, f->track, sizeof(f->track)); |
| 1989 | break; |
| 1990 | } |
| 1991 | case FDWERRORGET32: |
| 1992 | { |
| 1993 | struct floppy_write_errors32 __user *uf; |
| 1994 | struct floppy_write_errors *f = karg; |
| 1995 | |
| 1996 | uf = compat_ptr(arg); |
| 1997 | err = __put_user(f->write_errors, &uf->write_errors); |
| 1998 | err |= __put_user(f->first_error_sector, &uf->first_error_sector); |
| 1999 | err |= __put_user(f->first_error_generation, &uf->first_error_generation); |
| 2000 | err |= __put_user(f->last_error_sector, &uf->last_error_sector); |
| 2001 | err |= __put_user(f->last_error_generation, &uf->last_error_generation); |
| 2002 | err |= __put_user(f->badness, &uf->badness); |
| 2003 | break; |
| 2004 | } |
| 2005 | default: |
| 2006 | break; |
| 2007 | } |
| 2008 | if (err) |
| 2009 | err = -EFAULT; |
| 2010 | |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 2011 | out: |
| 2012 | kfree(karg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | return err; |
| 2014 | } |
| 2015 | |
| 2016 | struct mtd_oob_buf32 { |
| 2017 | u_int32_t start; |
| 2018 | u_int32_t length; |
| 2019 | compat_caddr_t ptr; /* unsigned char* */ |
| 2020 | }; |
| 2021 | |
| 2022 | #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32) |
| 2023 | #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32) |
| 2024 | |
| 2025 | static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2026 | { |
| 2027 | struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf)); |
| 2028 | struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg); |
| 2029 | u32 data; |
| 2030 | char __user *datap; |
| 2031 | unsigned int real_cmd; |
| 2032 | int err; |
| 2033 | |
| 2034 | real_cmd = (cmd == MEMREADOOB32) ? |
| 2035 | MEMREADOOB : MEMWRITEOOB; |
| 2036 | |
| 2037 | if (copy_in_user(&buf->start, &buf32->start, |
| 2038 | 2 * sizeof(u32)) || |
| 2039 | get_user(data, &buf32->ptr)) |
| 2040 | return -EFAULT; |
| 2041 | datap = compat_ptr(data); |
| 2042 | if (put_user(datap, &buf->ptr)) |
| 2043 | return -EFAULT; |
| 2044 | |
| 2045 | err = sys_ioctl(fd, real_cmd, (unsigned long) buf); |
| 2046 | |
| 2047 | if (!err) { |
| 2048 | if (copy_in_user(&buf32->start, &buf->start, |
| 2049 | 2 * sizeof(u32))) |
| 2050 | err = -EFAULT; |
| 2051 | } |
| 2052 | |
| 2053 | return err; |
| 2054 | } |
| 2055 | |
| 2056 | #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2]) |
| 2057 | #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2]) |
| 2058 | |
| 2059 | static long |
| 2060 | put_dirent32 (struct dirent *d, struct compat_dirent __user *d32) |
| 2061 | { |
| 2062 | if (!access_ok(VERIFY_WRITE, d32, sizeof(struct compat_dirent))) |
| 2063 | return -EFAULT; |
| 2064 | |
| 2065 | __put_user(d->d_ino, &d32->d_ino); |
| 2066 | __put_user(d->d_off, &d32->d_off); |
| 2067 | __put_user(d->d_reclen, &d32->d_reclen); |
| 2068 | if (__copy_to_user(d32->d_name, d->d_name, d->d_reclen)) |
| 2069 | return -EFAULT; |
| 2070 | |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
| 2074 | static int vfat_ioctl32(unsigned fd, unsigned cmd, unsigned long arg) |
| 2075 | { |
| 2076 | struct compat_dirent __user *p = compat_ptr(arg); |
| 2077 | int ret; |
| 2078 | mm_segment_t oldfs = get_fs(); |
| 2079 | struct dirent d[2]; |
| 2080 | |
| 2081 | switch(cmd) |
| 2082 | { |
| 2083 | case VFAT_IOCTL_READDIR_BOTH32: |
| 2084 | cmd = VFAT_IOCTL_READDIR_BOTH; |
| 2085 | break; |
| 2086 | case VFAT_IOCTL_READDIR_SHORT32: |
| 2087 | cmd = VFAT_IOCTL_READDIR_SHORT; |
| 2088 | break; |
| 2089 | } |
| 2090 | |
| 2091 | set_fs(KERNEL_DS); |
| 2092 | ret = sys_ioctl(fd,cmd,(unsigned long)&d); |
| 2093 | set_fs(oldfs); |
| 2094 | if (ret >= 0) { |
| 2095 | ret |= put_dirent32(&d[0], p); |
| 2096 | ret |= put_dirent32(&d[1], p + 1); |
| 2097 | } |
| 2098 | return ret; |
| 2099 | } |
| 2100 | |
| 2101 | #define REISERFS_IOC_UNPACK32 _IOW(0xCD,1,int) |
| 2102 | |
| 2103 | static int reiserfs_ioctl32(unsigned fd, unsigned cmd, unsigned long ptr) |
| 2104 | { |
| 2105 | if (cmd == REISERFS_IOC_UNPACK32) |
| 2106 | cmd = REISERFS_IOC_UNPACK; |
| 2107 | |
| 2108 | return sys_ioctl(fd,cmd,ptr); |
| 2109 | } |
| 2110 | |
| 2111 | struct raw32_config_request |
| 2112 | { |
| 2113 | compat_int_t raw_minor; |
| 2114 | __u64 block_major; |
| 2115 | __u64 block_minor; |
| 2116 | } __attribute__((packed)); |
| 2117 | |
| 2118 | static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req) |
| 2119 | { |
| 2120 | int ret; |
| 2121 | |
| 2122 | if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request))) |
| 2123 | return -EFAULT; |
| 2124 | |
| 2125 | ret = __get_user(req->raw_minor, &user_req->raw_minor); |
| 2126 | ret |= __get_user(req->block_major, &user_req->block_major); |
| 2127 | ret |= __get_user(req->block_minor, &user_req->block_minor); |
| 2128 | |
| 2129 | return ret ? -EFAULT : 0; |
| 2130 | } |
| 2131 | |
| 2132 | static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req) |
| 2133 | { |
| 2134 | int ret; |
| 2135 | |
| 2136 | if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request))) |
| 2137 | return -EFAULT; |
| 2138 | |
| 2139 | ret = __put_user(req->raw_minor, &user_req->raw_minor); |
| 2140 | ret |= __put_user(req->block_major, &user_req->block_major); |
| 2141 | ret |= __put_user(req->block_minor, &user_req->block_minor); |
| 2142 | |
| 2143 | return ret ? -EFAULT : 0; |
| 2144 | } |
| 2145 | |
| 2146 | static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg) |
| 2147 | { |
| 2148 | int ret; |
| 2149 | |
| 2150 | switch (cmd) { |
| 2151 | case RAW_SETBIND: |
| 2152 | case RAW_GETBIND: { |
| 2153 | struct raw_config_request req; |
| 2154 | struct raw32_config_request __user *user_req = compat_ptr(arg); |
| 2155 | mm_segment_t oldfs = get_fs(); |
| 2156 | |
| 2157 | if ((ret = get_raw32_request(&req, user_req))) |
| 2158 | return ret; |
| 2159 | |
| 2160 | set_fs(KERNEL_DS); |
| 2161 | ret = sys_ioctl(fd,cmd,(unsigned long)&req); |
| 2162 | set_fs(oldfs); |
| 2163 | |
| 2164 | if ((!ret) && (cmd == RAW_GETBIND)) { |
| 2165 | ret = set_raw32_request(&req, user_req); |
| 2166 | } |
| 2167 | break; |
| 2168 | } |
| 2169 | default: |
| 2170 | ret = sys_ioctl(fd, cmd, arg); |
| 2171 | break; |
| 2172 | } |
| 2173 | return ret; |
| 2174 | } |
| 2175 | |
| 2176 | struct serial_struct32 { |
| 2177 | compat_int_t type; |
| 2178 | compat_int_t line; |
| 2179 | compat_uint_t port; |
| 2180 | compat_int_t irq; |
| 2181 | compat_int_t flags; |
| 2182 | compat_int_t xmit_fifo_size; |
| 2183 | compat_int_t custom_divisor; |
| 2184 | compat_int_t baud_base; |
| 2185 | unsigned short close_delay; |
| 2186 | char io_type; |
| 2187 | char reserved_char[1]; |
| 2188 | compat_int_t hub6; |
| 2189 | unsigned short closing_wait; /* time to wait before closing */ |
| 2190 | unsigned short closing_wait2; /* no longer used... */ |
| 2191 | compat_uint_t iomem_base; |
| 2192 | unsigned short iomem_reg_shift; |
| 2193 | unsigned int port_high; |
| 2194 | /* compat_ulong_t iomap_base FIXME */ |
| 2195 | compat_int_t reserved[1]; |
| 2196 | }; |
| 2197 | |
| 2198 | static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg) |
| 2199 | { |
| 2200 | typedef struct serial_struct SS; |
| 2201 | typedef struct serial_struct32 SS32; |
| 2202 | struct serial_struct32 __user *ss32 = compat_ptr(arg); |
| 2203 | int err; |
| 2204 | struct serial_struct ss; |
| 2205 | mm_segment_t oldseg = get_fs(); |
| 2206 | __u32 udata; |
| 2207 | |
| 2208 | if (cmd == TIOCSSERIAL) { |
| 2209 | if (!access_ok(VERIFY_READ, ss32, sizeof(SS32))) |
| 2210 | return -EFAULT; |
| 2211 | if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base))) |
| 2212 | return -EFAULT; |
| 2213 | __get_user(udata, &ss32->iomem_base); |
| 2214 | ss.iomem_base = compat_ptr(udata); |
| 2215 | __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift); |
| 2216 | __get_user(ss.port_high, &ss32->port_high); |
| 2217 | ss.iomap_base = 0UL; |
| 2218 | } |
| 2219 | set_fs(KERNEL_DS); |
| 2220 | err = sys_ioctl(fd,cmd,(unsigned long)(&ss)); |
| 2221 | set_fs(oldseg); |
| 2222 | if (cmd == TIOCGSERIAL && err >= 0) { |
| 2223 | if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32))) |
| 2224 | return -EFAULT; |
| 2225 | if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base))) |
| 2226 | return -EFAULT; |
| 2227 | __put_user((unsigned long)ss.iomem_base >> 32 ? |
| 2228 | 0xffffffff : (unsigned)(unsigned long)ss.iomem_base, |
| 2229 | &ss32->iomem_base); |
| 2230 | __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift); |
| 2231 | __put_user(ss.port_high, &ss32->port_high); |
| 2232 | |
| 2233 | } |
| 2234 | return err; |
| 2235 | } |
| 2236 | |
| 2237 | struct usbdevfs_ctrltransfer32 { |
| 2238 | u8 bRequestType; |
| 2239 | u8 bRequest; |
| 2240 | u16 wValue; |
| 2241 | u16 wIndex; |
| 2242 | u16 wLength; |
| 2243 | u32 timeout; /* in milliseconds */ |
| 2244 | compat_caddr_t data; |
| 2245 | }; |
| 2246 | |
| 2247 | #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32) |
| 2248 | |
| 2249 | static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2250 | { |
| 2251 | struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg); |
| 2252 | struct usbdevfs_ctrltransfer __user *p; |
| 2253 | __u32 udata; |
| 2254 | p = compat_alloc_user_space(sizeof(*p)); |
| 2255 | if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || |
| 2256 | get_user(udata, &p32->data) || |
| 2257 | put_user(compat_ptr(udata), &p->data)) |
| 2258 | return -EFAULT; |
| 2259 | return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p); |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | struct usbdevfs_bulktransfer32 { |
| 2264 | compat_uint_t ep; |
| 2265 | compat_uint_t len; |
| 2266 | compat_uint_t timeout; /* in milliseconds */ |
| 2267 | compat_caddr_t data; |
| 2268 | }; |
| 2269 | |
| 2270 | #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32) |
| 2271 | |
| 2272 | static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2273 | { |
| 2274 | struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg); |
| 2275 | struct usbdevfs_bulktransfer __user *p; |
| 2276 | compat_uint_t n; |
| 2277 | compat_caddr_t addr; |
| 2278 | |
| 2279 | p = compat_alloc_user_space(sizeof(*p)); |
| 2280 | |
| 2281 | if (get_user(n, &p32->ep) || put_user(n, &p->ep) || |
| 2282 | get_user(n, &p32->len) || put_user(n, &p->len) || |
| 2283 | get_user(n, &p32->timeout) || put_user(n, &p->timeout) || |
| 2284 | get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) |
| 2285 | return -EFAULT; |
| 2286 | |
| 2287 | return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p); |
| 2288 | } |
| 2289 | |
| 2290 | |
| 2291 | /* |
| 2292 | * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY |
| 2293 | * are handled in usbdevfs core. -Christopher Li |
| 2294 | */ |
| 2295 | |
| 2296 | struct usbdevfs_disconnectsignal32 { |
| 2297 | compat_int_t signr; |
| 2298 | compat_caddr_t context; |
| 2299 | }; |
| 2300 | |
| 2301 | #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32) |
| 2302 | |
| 2303 | static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2304 | { |
| 2305 | struct usbdevfs_disconnectsignal kdis; |
| 2306 | struct usbdevfs_disconnectsignal32 __user *udis; |
| 2307 | mm_segment_t old_fs; |
| 2308 | u32 uctx; |
| 2309 | int err; |
| 2310 | |
| 2311 | udis = compat_ptr(arg); |
| 2312 | |
| 2313 | if (get_user(kdis.signr, &udis->signr) || |
| 2314 | __get_user(uctx, &udis->context)) |
| 2315 | return -EFAULT; |
| 2316 | |
| 2317 | kdis.context = compat_ptr(uctx); |
| 2318 | |
| 2319 | old_fs = get_fs(); |
| 2320 | set_fs(KERNEL_DS); |
| 2321 | err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis); |
| 2322 | set_fs(old_fs); |
| 2323 | |
| 2324 | return err; |
| 2325 | } |
| 2326 | |
| 2327 | /* |
| 2328 | * I2C layer ioctls |
| 2329 | */ |
| 2330 | |
| 2331 | struct i2c_msg32 { |
| 2332 | u16 addr; |
| 2333 | u16 flags; |
| 2334 | u16 len; |
| 2335 | compat_caddr_t buf; |
| 2336 | }; |
| 2337 | |
| 2338 | struct i2c_rdwr_ioctl_data32 { |
| 2339 | compat_caddr_t msgs; /* struct i2c_msg __user *msgs */ |
| 2340 | u32 nmsgs; |
| 2341 | }; |
| 2342 | |
| 2343 | struct i2c_smbus_ioctl_data32 { |
| 2344 | u8 read_write; |
| 2345 | u8 command; |
| 2346 | u32 size; |
| 2347 | compat_caddr_t data; /* union i2c_smbus_data *data */ |
| 2348 | }; |
| 2349 | |
| 2350 | struct i2c_rdwr_aligned { |
| 2351 | struct i2c_rdwr_ioctl_data cmd; |
| 2352 | struct i2c_msg msgs[0]; |
| 2353 | }; |
| 2354 | |
| 2355 | static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2356 | { |
| 2357 | struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg); |
| 2358 | struct i2c_rdwr_aligned __user *tdata; |
| 2359 | struct i2c_msg __user *tmsgs; |
| 2360 | struct i2c_msg32 __user *umsgs; |
| 2361 | compat_caddr_t datap; |
| 2362 | int nmsgs, i; |
| 2363 | |
| 2364 | if (get_user(nmsgs, &udata->nmsgs)) |
| 2365 | return -EFAULT; |
| 2366 | if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) |
| 2367 | return -EINVAL; |
| 2368 | |
| 2369 | if (get_user(datap, &udata->msgs)) |
| 2370 | return -EFAULT; |
| 2371 | umsgs = compat_ptr(datap); |
| 2372 | |
| 2373 | tdata = compat_alloc_user_space(sizeof(*tdata) + |
| 2374 | nmsgs * sizeof(struct i2c_msg)); |
| 2375 | tmsgs = &tdata->msgs[0]; |
| 2376 | |
| 2377 | if (put_user(nmsgs, &tdata->cmd.nmsgs) || |
| 2378 | put_user(tmsgs, &tdata->cmd.msgs)) |
| 2379 | return -EFAULT; |
| 2380 | |
| 2381 | for (i = 0; i < nmsgs; i++) { |
| 2382 | if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16))) |
| 2383 | return -EFAULT; |
| 2384 | if (get_user(datap, &umsgs[i].buf) || |
| 2385 | put_user(compat_ptr(datap), &tmsgs[i].buf)) |
| 2386 | return -EFAULT; |
| 2387 | } |
| 2388 | return sys_ioctl(fd, cmd, (unsigned long)tdata); |
| 2389 | } |
| 2390 | |
| 2391 | static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2392 | { |
| 2393 | struct i2c_smbus_ioctl_data __user *tdata; |
| 2394 | struct i2c_smbus_ioctl_data32 __user *udata; |
| 2395 | compat_caddr_t datap; |
| 2396 | |
| 2397 | tdata = compat_alloc_user_space(sizeof(*tdata)); |
| 2398 | if (tdata == NULL) |
| 2399 | return -ENOMEM; |
| 2400 | if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata))) |
| 2401 | return -EFAULT; |
| 2402 | |
| 2403 | udata = compat_ptr(arg); |
| 2404 | if (!access_ok(VERIFY_READ, udata, sizeof(*udata))) |
| 2405 | return -EFAULT; |
| 2406 | |
| 2407 | if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8))) |
| 2408 | return -EFAULT; |
| 2409 | if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32))) |
| 2410 | return -EFAULT; |
| 2411 | if (__get_user(datap, &udata->data) || |
| 2412 | __put_user(compat_ptr(datap), &tdata->data)) |
| 2413 | return -EFAULT; |
| 2414 | |
| 2415 | return sys_ioctl(fd, cmd, (unsigned long)tdata); |
| 2416 | } |
| 2417 | |
| 2418 | struct compat_iw_point { |
| 2419 | compat_caddr_t pointer; |
| 2420 | __u16 length; |
| 2421 | __u16 flags; |
| 2422 | }; |
| 2423 | |
| 2424 | static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2425 | { |
| 2426 | struct iwreq __user *iwr; |
| 2427 | struct iwreq __user *iwr_u; |
| 2428 | struct iw_point __user *iwp; |
| 2429 | struct compat_iw_point __user *iwp_u; |
| 2430 | compat_caddr_t pointer; |
| 2431 | __u16 length, flags; |
| 2432 | |
| 2433 | iwr_u = compat_ptr(arg); |
| 2434 | iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data; |
| 2435 | iwr = compat_alloc_user_space(sizeof(*iwr)); |
| 2436 | if (iwr == NULL) |
| 2437 | return -ENOMEM; |
| 2438 | |
| 2439 | iwp = &iwr->u.data; |
| 2440 | |
| 2441 | if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr))) |
| 2442 | return -EFAULT; |
| 2443 | |
| 2444 | if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0], |
| 2445 | &iwr_u->ifr_ifrn.ifrn_name[0], |
| 2446 | sizeof(iwr->ifr_ifrn.ifrn_name))) |
| 2447 | return -EFAULT; |
| 2448 | |
| 2449 | if (__get_user(pointer, &iwp_u->pointer) || |
| 2450 | __get_user(length, &iwp_u->length) || |
| 2451 | __get_user(flags, &iwp_u->flags)) |
| 2452 | return -EFAULT; |
| 2453 | |
| 2454 | if (__put_user(compat_ptr(pointer), &iwp->pointer) || |
| 2455 | __put_user(length, &iwp->length) || |
| 2456 | __put_user(flags, &iwp->flags)) |
| 2457 | return -EFAULT; |
| 2458 | |
| 2459 | return sys_ioctl(fd, cmd, (unsigned long) iwr); |
| 2460 | } |
| 2461 | |
| 2462 | /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE |
| 2463 | * for some operations; this forces use of the newer bridge-utils that |
| 2464 | * use compatiable ioctls |
| 2465 | */ |
| 2466 | static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2467 | { |
| 2468 | u32 tmp; |
| 2469 | |
| 2470 | if (get_user(tmp, (u32 __user *) arg)) |
| 2471 | return -EFAULT; |
| 2472 | if (tmp == BRCTL_GET_VERSION) |
| 2473 | return BRCTL_VERSION + 1; |
| 2474 | return -EINVAL; |
| 2475 | } |
| 2476 | |
Christoph Hellwig | ec3cad9 | 2006-01-09 20:52:11 -0800 | [diff] [blame] | 2477 | #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) |
| 2478 | #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) |
| 2479 | #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) |
| 2480 | #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) |
| 2481 | |
| 2482 | static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg) |
| 2483 | { |
| 2484 | mm_segment_t oldfs = get_fs(); |
| 2485 | compat_ulong_t val32; |
| 2486 | unsigned long kval; |
| 2487 | int ret; |
| 2488 | |
| 2489 | switch (cmd) { |
| 2490 | case RTC_IRQP_READ32: |
| 2491 | case RTC_EPOCH_READ32: |
| 2492 | set_fs(KERNEL_DS); |
| 2493 | ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ? |
| 2494 | RTC_IRQP_READ : RTC_EPOCH_READ, |
| 2495 | (unsigned long)&kval); |
| 2496 | set_fs(oldfs); |
| 2497 | if (ret) |
| 2498 | return ret; |
| 2499 | val32 = kval; |
| 2500 | return put_user(val32, (unsigned int __user *)arg); |
| 2501 | case RTC_IRQP_SET32: |
Andi Kleen | fc5870f | 2006-02-26 04:18:55 +0100 | [diff] [blame] | 2502 | return sys_ioctl(fd, RTC_IRQP_SET, arg); |
Christoph Hellwig | ec3cad9 | 2006-01-09 20:52:11 -0800 | [diff] [blame] | 2503 | case RTC_EPOCH_SET32: |
Andi Kleen | fc5870f | 2006-02-26 04:18:55 +0100 | [diff] [blame] | 2504 | return sys_ioctl(fd, RTC_EPOCH_SET, arg); |
Christoph Hellwig | ec3cad9 | 2006-01-09 20:52:11 -0800 | [diff] [blame] | 2505 | default: |
| 2506 | /* unreached */ |
| 2507 | return -ENOIOCTLCMD; |
| 2508 | } |
| 2509 | } |
| 2510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE) |
| 2512 | struct ncp_ioctl_request_32 { |
| 2513 | u32 function; |
| 2514 | u32 size; |
| 2515 | compat_caddr_t data; |
| 2516 | }; |
| 2517 | |
| 2518 | struct ncp_fs_info_v2_32 { |
| 2519 | s32 version; |
| 2520 | u32 mounted_uid; |
| 2521 | u32 connection; |
| 2522 | u32 buffer_size; |
| 2523 | |
| 2524 | u32 volume_number; |
| 2525 | u32 directory_id; |
| 2526 | |
| 2527 | u32 dummy1; |
| 2528 | u32 dummy2; |
| 2529 | u32 dummy3; |
| 2530 | }; |
| 2531 | |
| 2532 | struct ncp_objectname_ioctl_32 |
| 2533 | { |
| 2534 | s32 auth_type; |
| 2535 | u32 object_name_len; |
| 2536 | compat_caddr_t object_name; /* an userspace data, in most cases user name */ |
| 2537 | }; |
| 2538 | |
| 2539 | struct ncp_privatedata_ioctl_32 |
| 2540 | { |
| 2541 | u32 len; |
| 2542 | compat_caddr_t data; /* ~1000 for NDS */ |
| 2543 | }; |
| 2544 | |
| 2545 | #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32) |
| 2546 | #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32) |
| 2547 | #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32) |
| 2548 | #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32) |
| 2549 | #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32) |
| 2550 | #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32) |
| 2551 | #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32) |
| 2552 | |
| 2553 | static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2554 | { |
| 2555 | struct ncp_ioctl_request_32 n32; |
| 2556 | struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p)); |
| 2557 | |
| 2558 | if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) || |
| 2559 | put_user(n32.function, &p->function) || |
| 2560 | put_user(n32.size, &p->size) || |
| 2561 | put_user(compat_ptr(n32.data), &p->data)) |
| 2562 | return -EFAULT; |
| 2563 | |
| 2564 | return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p); |
| 2565 | } |
| 2566 | |
| 2567 | static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2568 | { |
| 2569 | mm_segment_t old_fs = get_fs(); |
| 2570 | __kernel_uid_t kuid; |
| 2571 | int err; |
| 2572 | |
| 2573 | cmd = NCP_IOC_GETMOUNTUID2; |
| 2574 | |
| 2575 | set_fs(KERNEL_DS); |
| 2576 | err = sys_ioctl(fd, cmd, (unsigned long)&kuid); |
| 2577 | set_fs(old_fs); |
| 2578 | |
| 2579 | if (!err) |
| 2580 | err = put_user(kuid, |
| 2581 | (unsigned int __user *) compat_ptr(arg)); |
| 2582 | |
| 2583 | return err; |
| 2584 | } |
| 2585 | |
| 2586 | static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2587 | { |
| 2588 | mm_segment_t old_fs = get_fs(); |
| 2589 | struct ncp_fs_info_v2_32 n32; |
| 2590 | struct ncp_fs_info_v2 n; |
| 2591 | int err; |
| 2592 | |
| 2593 | if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32))) |
| 2594 | return -EFAULT; |
| 2595 | if (n32.version != NCP_GET_FS_INFO_VERSION_V2) |
| 2596 | return -EINVAL; |
| 2597 | n.version = NCP_GET_FS_INFO_VERSION_V2; |
| 2598 | |
| 2599 | set_fs(KERNEL_DS); |
| 2600 | err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n); |
| 2601 | set_fs(old_fs); |
| 2602 | |
| 2603 | if (!err) { |
| 2604 | n32.version = n.version; |
| 2605 | n32.mounted_uid = n.mounted_uid; |
| 2606 | n32.connection = n.connection; |
| 2607 | n32.buffer_size = n.buffer_size; |
| 2608 | n32.volume_number = n.volume_number; |
| 2609 | n32.directory_id = n.directory_id; |
| 2610 | n32.dummy1 = n.dummy1; |
| 2611 | n32.dummy2 = n.dummy2; |
| 2612 | n32.dummy3 = n.dummy3; |
| 2613 | err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0; |
| 2614 | } |
| 2615 | return err; |
| 2616 | } |
| 2617 | |
| 2618 | static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2619 | { |
| 2620 | struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg); |
| 2621 | struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); |
| 2622 | s32 auth_type; |
| 2623 | u32 name_len; |
| 2624 | int err; |
| 2625 | |
| 2626 | if (copy_from_user(&n32, p32, sizeof(n32)) || |
| 2627 | put_user(n32.object_name_len, &p->object_name_len) || |
| 2628 | put_user(compat_ptr(n32.object_name), &p->object_name)) |
| 2629 | return -EFAULT; |
| 2630 | |
| 2631 | err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p); |
| 2632 | if (err) |
| 2633 | return err; |
| 2634 | |
| 2635 | if (get_user(auth_type, &p->auth_type) || |
| 2636 | put_user(auth_type, &p32->auth_type) || |
| 2637 | get_user(name_len, &p->object_name_len) || |
| 2638 | put_user(name_len, &p32->object_name_len)) |
| 2639 | return -EFAULT; |
| 2640 | |
| 2641 | return 0; |
| 2642 | } |
| 2643 | |
| 2644 | static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2645 | { |
| 2646 | struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg); |
| 2647 | struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p)); |
| 2648 | |
| 2649 | if (copy_from_user(&n32, p32, sizeof(n32)) || |
| 2650 | put_user(n32.auth_type, &p->auth_type) || |
| 2651 | put_user(n32.object_name_len, &p->object_name_len) || |
| 2652 | put_user(compat_ptr(n32.object_name), &p->object_name)) |
| 2653 | return -EFAULT; |
| 2654 | |
| 2655 | return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p); |
| 2656 | } |
| 2657 | |
| 2658 | static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2659 | { |
| 2660 | struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg); |
| 2661 | struct ncp_privatedata_ioctl __user *p = |
| 2662 | compat_alloc_user_space(sizeof(*p)); |
| 2663 | u32 len; |
| 2664 | int err; |
| 2665 | |
| 2666 | if (copy_from_user(&n32, p32, sizeof(n32)) || |
| 2667 | put_user(n32.len, &p->len) || |
| 2668 | put_user(compat_ptr(n32.data), &p->data)) |
| 2669 | return -EFAULT; |
| 2670 | |
| 2671 | err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p); |
| 2672 | if (err) |
| 2673 | return err; |
| 2674 | |
| 2675 | if (get_user(len, &p->len) || |
| 2676 | put_user(len, &p32->len)) |
| 2677 | return -EFAULT; |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | |
| 2682 | static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2683 | { |
| 2684 | struct ncp_privatedata_ioctl_32 n32; |
| 2685 | struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg); |
| 2686 | struct ncp_privatedata_ioctl __user *p = |
| 2687 | compat_alloc_user_space(sizeof(*p)); |
| 2688 | |
| 2689 | if (copy_from_user(&n32, p32, sizeof(n32)) || |
| 2690 | put_user(n32.len, &p->len) || |
| 2691 | put_user(compat_ptr(n32.data), &p->data)) |
| 2692 | return -EFAULT; |
| 2693 | |
| 2694 | return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p); |
| 2695 | } |
| 2696 | #endif |
| 2697 | |
Andi Kleen | c6b44d1 | 2006-01-12 01:05:26 -0800 | [diff] [blame] | 2698 | static int |
| 2699 | lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 2700 | { |
Al Viro | 6b2b4e5 | 2006-02-01 06:33:33 -0500 | [diff] [blame] | 2701 | struct compat_timeval __user *tc = (struct compat_timeval __user *)arg; |
| 2702 | struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval)); |
Andi Kleen | c6b44d1 | 2006-01-12 01:05:26 -0800 | [diff] [blame] | 2703 | struct timeval ts; |
| 2704 | if (get_user(ts.tv_sec, &tc->tv_sec) || |
| 2705 | get_user(ts.tv_usec, &tc->tv_usec) || |
| 2706 | put_user(ts.tv_sec, &tn->tv_sec) || |
| 2707 | put_user(ts.tv_usec, &tn->tv_usec)) |
| 2708 | return -EFAULT; |
| 2709 | return sys_ioctl(fd, cmd, (unsigned long)tn); |
| 2710 | } |
| 2711 | |
Christoph Hellwig | e6a6d2e | 2006-01-09 20:52:14 -0800 | [diff] [blame] | 2712 | #define HANDLE_IOCTL(cmd,handler) \ |
| 2713 | { (cmd), (ioctl_trans_handler_t)(handler) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | |
Christoph Hellwig | e6a6d2e | 2006-01-09 20:52:14 -0800 | [diff] [blame] | 2715 | /* pointer to compatible structure or no argument */ |
| 2716 | #define COMPATIBLE_IOCTL(cmd) \ |
| 2717 | { (cmd), do_ioctl32_pointer }, |
| 2718 | |
| 2719 | /* argument is an unsigned long integer, not a pointer */ |
| 2720 | #define ULONG_IOCTL(cmd) \ |
| 2721 | { (cmd), (ioctl_trans_handler_t)sys_ioctl }, |
| 2722 | |
| 2723 | |
| 2724 | struct ioctl_trans ioctl_start[] = { |
| 2725 | #include <linux/compat_ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob) |
| 2727 | HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob) |
| 2728 | #ifdef CONFIG_NET |
| 2729 | HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32) |
| 2730 | HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf) |
| 2731 | HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc) |
| 2732 | HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc) |
| 2733 | HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc) |
| 2734 | HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc) |
| 2735 | HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc) |
| 2736 | HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc) |
| 2737 | HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc) |
| 2738 | HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc) |
| 2739 | HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc) |
| 2740 | HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc) |
| 2741 | HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc) |
| 2742 | HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc) |
| 2743 | HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc) |
| 2744 | HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc) |
| 2745 | HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc) |
| 2746 | HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc) |
| 2747 | HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc) |
| 2748 | |
| 2749 | /* ioctls used by appletalk ddp.c */ |
| 2750 | HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc) |
| 2751 | HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc) |
| 2752 | HANDLE_IOCTL(SIOCSARP, dev_ifsioc) |
| 2753 | HANDLE_IOCTL(SIOCDARP, dev_ifsioc) |
| 2754 | |
| 2755 | HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc) |
| 2756 | HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc) |
| 2757 | HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc) |
| 2758 | HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc) |
| 2759 | HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc) |
| 2760 | HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc) |
| 2761 | HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc) |
| 2762 | HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc) |
| 2763 | HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc) |
| 2764 | HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc) |
| 2765 | HANDLE_IOCTL(TUNSETIFF, dev_ifsioc) |
| 2766 | HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl) |
| 2767 | HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl) |
| 2768 | HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl) |
| 2769 | HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl) |
| 2770 | HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl) |
| 2771 | HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl) |
| 2772 | HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl) |
| 2773 | HANDLE_IOCTL(SIOCADDRT, routing_ioctl) |
| 2774 | HANDLE_IOCTL(SIOCDELRT, routing_ioctl) |
| 2775 | HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc) |
| 2776 | HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc) |
| 2777 | /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */ |
| 2778 | HANDLE_IOCTL(SIOCRTMSG, ret_einval) |
| 2779 | HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp) |
| 2780 | #endif |
| 2781 | HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo) |
| 2782 | HANDLE_IOCTL(BLKRAGET, w_long) |
| 2783 | HANDLE_IOCTL(BLKGETSIZE, w_long) |
| 2784 | HANDLE_IOCTL(0x1260, broken_blkgetsize) |
| 2785 | HANDLE_IOCTL(BLKFRAGET, w_long) |
| 2786 | HANDLE_IOCTL(BLKSECTGET, w_long) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans) |
| 2789 | HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans) |
| 2790 | HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans) |
| 2791 | HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans) |
| 2792 | HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans) |
| 2793 | HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans) |
| 2794 | HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans) |
| 2795 | HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans) |
| 2796 | HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans) |
| 2797 | HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans) |
| 2798 | HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans) |
| 2799 | HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans) |
| 2800 | HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans) |
| 2801 | HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans) |
| 2802 | HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans) |
| 2803 | HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans) |
| 2804 | HANDLE_IOCTL(SG_IO,sg_ioctl_trans) |
Andi Kleen | 2966387 | 2006-01-11 22:44:03 +0100 | [diff] [blame] | 2805 | HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans) |
| 2807 | HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans) |
| 2808 | HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans) |
| 2809 | HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans) |
| 2810 | HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans) |
| 2811 | HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans) |
| 2812 | HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans) |
| 2813 | HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans) |
| 2814 | HANDLE_IOCTL(LOOP_SET_STATUS, loop_status) |
| 2815 | HANDLE_IOCTL(LOOP_GET_STATUS, loop_status) |
| 2816 | #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int) |
| 2817 | HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout) |
| 2818 | #ifdef CONFIG_VT |
| 2819 | HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl) |
| 2820 | HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl) |
| 2821 | HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl) |
| 2822 | HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl) |
| 2823 | HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl) |
| 2824 | #endif |
| 2825 | HANDLE_IOCTL(EXT2_IOC32_GETFLAGS, do_ext2_ioctl) |
| 2826 | HANDLE_IOCTL(EXT2_IOC32_SETFLAGS, do_ext2_ioctl) |
| 2827 | HANDLE_IOCTL(EXT2_IOC32_GETVERSION, do_ext2_ioctl) |
| 2828 | HANDLE_IOCTL(EXT2_IOC32_SETVERSION, do_ext2_ioctl) |
David S. Miller | d5ea655 | 2005-11-17 15:04:34 -0800 | [diff] [blame] | 2829 | HANDLE_IOCTL(EXT3_IOC32_GETVERSION, do_ext3_ioctl) |
| 2830 | HANDLE_IOCTL(EXT3_IOC32_SETVERSION, do_ext3_ioctl) |
| 2831 | HANDLE_IOCTL(EXT3_IOC32_GETRSVSZ, do_ext3_ioctl) |
| 2832 | HANDLE_IOCTL(EXT3_IOC32_SETRSVSZ, do_ext3_ioctl) |
| 2833 | HANDLE_IOCTL(EXT3_IOC32_GROUP_EXTEND, do_ext3_ioctl) |
| 2834 | COMPATIBLE_IOCTL(EXT3_IOC_GROUP_ADD) |
| 2835 | #ifdef CONFIG_JBD_DEBUG |
| 2836 | HANDLE_IOCTL(EXT3_IOC32_WAIT_FOR_READONLY, do_ext3_ioctl) |
| 2837 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | /* One SMB ioctl needs translations. */ |
| 2839 | #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t) |
| 2840 | HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid) |
| 2841 | HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl) |
| 2842 | HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl) |
| 2843 | HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl) |
| 2844 | HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl) |
| 2845 | HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl) |
| 2846 | HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl) |
| 2847 | HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl) |
| 2848 | HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl) |
| 2849 | HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl) |
| 2850 | HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl) |
| 2851 | HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl) |
| 2852 | HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl) |
| 2853 | HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl) |
| 2854 | HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl) |
| 2855 | HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl) |
| 2856 | HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl) |
| 2857 | HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl) |
| 2858 | HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl) |
| 2859 | HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl) |
| 2860 | HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl) |
| 2861 | HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl) |
| 2862 | HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl) |
| 2863 | HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl) |
| 2864 | HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl) |
| 2865 | HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl) |
| 2866 | /* block stuff */ |
| 2867 | HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget) |
| 2868 | HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset) |
| 2869 | HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64) |
| 2870 | /* vfat */ |
| 2871 | HANDLE_IOCTL(VFAT_IOCTL_READDIR_BOTH32, vfat_ioctl32) |
| 2872 | HANDLE_IOCTL(VFAT_IOCTL_READDIR_SHORT32, vfat_ioctl32) |
| 2873 | HANDLE_IOCTL(REISERFS_IOC_UNPACK32, reiserfs_ioctl32) |
| 2874 | /* Raw devices */ |
| 2875 | HANDLE_IOCTL(RAW_SETBIND, raw_ioctl) |
| 2876 | HANDLE_IOCTL(RAW_GETBIND, raw_ioctl) |
| 2877 | /* Serial */ |
| 2878 | HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl) |
| 2879 | HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl) |
Christoph Hellwig | 9c0cbd5 | 2005-10-30 15:01:41 -0800 | [diff] [blame] | 2880 | #ifdef TIOCGLTC |
| 2881 | COMPATIBLE_IOCTL(TIOCGLTC) |
| 2882 | COMPATIBLE_IOCTL(TIOCSLTC) |
| 2883 | #endif |
Christoph Hellwig | 7a81e31 | 2005-11-08 21:35:07 -0800 | [diff] [blame] | 2884 | #ifdef TIOCSTART |
| 2885 | /* |
| 2886 | * For these two we have defintions in ioctls.h and/or termios.h on |
| 2887 | * some architectures but no actual implemention. Some applications |
| 2888 | * like bash call them if they are defined in the headers, so we provide |
| 2889 | * entries here to avoid syslog message spew. |
| 2890 | */ |
| 2891 | COMPATIBLE_IOCTL(TIOCSTART) |
| 2892 | COMPATIBLE_IOCTL(TIOCSTOP) |
| 2893 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | /* Usbdevfs */ |
| 2895 | HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control) |
| 2896 | HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk) |
| 2897 | HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal) |
Pete Zaitcev | c36fc88 | 2005-10-17 18:15:54 -0700 | [diff] [blame] | 2898 | COMPATIBLE_IOCTL(USBDEVFS_IOCTL32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | /* i2c */ |
| 2900 | HANDLE_IOCTL(I2C_FUNCS, w_long) |
| 2901 | HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl) |
| 2902 | HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl) |
| 2903 | /* wireless */ |
| 2904 | HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl) |
| 2905 | HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl) |
| 2906 | HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl) |
| 2907 | HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl) |
| 2908 | HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl) |
| 2909 | HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl) |
| 2910 | HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl) |
| 2911 | HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl) |
| 2912 | HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl) |
| 2913 | HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl) |
| 2914 | HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl) |
| 2915 | HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl) |
| 2916 | HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl) |
| 2917 | HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl) |
| 2918 | HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl) |
Christoph Hellwig | ec3cad9 | 2006-01-09 20:52:11 -0800 | [diff] [blame] | 2919 | HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl) |
| 2920 | HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl) |
| 2921 | HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl) |
| 2922 | HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | |
| 2924 | #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE) |
| 2925 | HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest) |
| 2926 | HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2) |
| 2927 | HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2) |
| 2928 | HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname) |
| 2929 | HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname) |
| 2930 | HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata) |
| 2931 | HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata) |
| 2932 | #endif |
| 2933 | |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 2934 | /* dvb */ |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 2935 | HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event) |
| 2936 | HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture) |
| 2937 | HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette) |
Andi Kleen | c6b44d1 | 2006-01-12 01:05:26 -0800 | [diff] [blame] | 2938 | |
| 2939 | /* parport */ |
| 2940 | COMPATIBLE_IOCTL(LPTIME) |
| 2941 | COMPATIBLE_IOCTL(LPCHAR) |
| 2942 | COMPATIBLE_IOCTL(LPABORTOPEN) |
| 2943 | COMPATIBLE_IOCTL(LPCAREFUL) |
| 2944 | COMPATIBLE_IOCTL(LPWAIT) |
| 2945 | COMPATIBLE_IOCTL(LPSETIRQ) |
| 2946 | COMPATIBLE_IOCTL(LPGETSTATUS) |
| 2947 | COMPATIBLE_IOCTL(LPGETSTATUS) |
| 2948 | COMPATIBLE_IOCTL(LPRESET) |
| 2949 | /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/ |
| 2950 | COMPATIBLE_IOCTL(LPGETFLAGS) |
| 2951 | HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans) |
Christoph Hellwig | e6a6d2e | 2006-01-09 20:52:14 -0800 | [diff] [blame] | 2952 | }; |
David S. Miller | 6e87abd | 2005-11-16 00:52:57 -0800 | [diff] [blame] | 2953 | |
Christoph Hellwig | e6a6d2e | 2006-01-09 20:52:14 -0800 | [diff] [blame] | 2954 | int ioctl_table_size = ARRAY_SIZE(ioctl_start); |