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