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