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