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