blob: 6b44cdc96facd51030d8798f68e3cf68aecc0d4e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3 *
4 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
7 * Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
8 *
9 * These routines maintain argument size conversion between 32bit and 64bit
10 * ioctls.
11 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/types.h>
14#include <linux/compat.h>
15#include <linux/kernel.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080016#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/compiler.h>
18#include <linux/sched.h>
19#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/ioctl.h>
21#include <linux/if.h>
22#include <linux/if_bridge.h>
23#include <linux/slab.h>
24#include <linux/hdreg.h>
25#include <linux/raid/md.h>
26#include <linux/kd.h>
27#include <linux/dirent.h>
28#include <linux/route.h>
29#include <linux/in6.h>
30#include <linux/ipv6_route.h>
31#include <linux/skbuff.h>
32#include <linux/netlink.h>
33#include <linux/vt.h>
34#include <linux/fs.h>
35#include <linux/file.h>
36#include <linux/fd.h>
37#include <linux/ppp_defs.h>
38#include <linux/if_ppp.h>
39#include <linux/if_pppox.h>
40#include <linux/mtio.h>
41#include <linux/cdrom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/auto_fs.h>
43#include <linux/auto_fs4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/tty.h>
45#include <linux/vt_kern.h>
46#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/videodev.h>
48#include <linux/netdevice.h>
49#include <linux/raw.h>
50#include <linux/smb_fs.h>
51#include <linux/blkpg.h>
52#include <linux/blkdev.h>
53#include <linux/elevator.h>
54#include <linux/rtc.h>
55#include <linux/pci.h>
56#include <linux/module.h>
57#include <linux/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/if_tun.h>
59#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <linux/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/i2c.h>
62#include <linux/i2c-dev.h>
63#include <linux/wireless.h>
64#include <linux/atalk.h>
Jens Axboe2056a782006-03-23 20:00:26 +010065#include <linux/blktrace_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include <net/bluetooth/bluetooth.h>
68#include <net/bluetooth/hci.h>
69#include <net/bluetooth/rfcomm.h>
70
71#include <linux/capi.h>
Hansjoerg Lipp5024ad42006-06-26 00:25:35 -070072#include <linux/gigaset_dev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74#include <scsi/scsi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <scsi/scsi_ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include <scsi/sg.h>
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <asm/uaccess.h>
79#include <linux/ethtool.h>
80#include <linux/mii.h>
81#include <linux/if_bonding.h>
82#include <linux/watchdog.h>
83#include <linux/dm-ioctl.h>
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#include <linux/soundcard.h>
86#include <linux/lp.h>
87#include <linux/ppdev.h>
88
89#include <linux/atm.h>
90#include <linux/atmarp.h>
91#include <linux/atmclip.h>
92#include <linux/atmdev.h>
93#include <linux/atmioc.h>
94#include <linux/atmlec.h>
95#include <linux/atmmpc.h>
96#include <linux/atmsvc.h>
97#include <linux/atm_tcp.h>
98#include <linux/sonet.h>
99#include <linux/atm_suni.h>
100#include <linux/mtd/mtd.h>
101
102#include <linux/usb.h>
103#include <linux/usbdevice_fs.h>
104#include <linux/nbd.h>
105#include <linux/random.h>
106#include <linux/filter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#include <linux/pktcdvd.h>
108
109#include <linux/hiddev.h>
110
David S. Miller6e87abd2005-11-16 00:52:57 -0800111#include <linux/dvb/audio.h>
112#include <linux/dvb/dmx.h>
113#include <linux/dvb/frontend.h>
114#include <linux/dvb/video.h>
Andi Kleenc6b44d12006-01-12 01:05:26 -0800115#include <linux/lp.h>
David S. Miller6e87abd2005-11-16 00:52:57 -0800116
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -0800117static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
118 unsigned long arg, struct file *f)
119{
120 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
124{
125 mm_segment_t old_fs = get_fs();
126 int err;
127 unsigned long val;
128
129 set_fs (KERNEL_DS);
130 err = sys_ioctl(fd, cmd, (unsigned long)&val);
131 set_fs (old_fs);
132 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
133 return -EFAULT;
134 return err;
135}
136
137static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
138{
139 mm_segment_t old_fs = get_fs();
140 u32 __user *argptr = compat_ptr(arg);
141 int err;
142 unsigned long val;
143
144 if(get_user(val, argptr))
145 return -EFAULT;
146 set_fs (KERNEL_DS);
147 err = sys_ioctl(fd, cmd, (unsigned long)&val);
148 set_fs (old_fs);
149 if (!err && put_user(val, argptr))
150 return -EFAULT;
151 return err;
152}
153
David S. Miller6e87abd2005-11-16 00:52:57 -0800154struct compat_video_event {
155 int32_t type;
156 compat_time_t timestamp;
157 union {
158 video_size_t size;
159 unsigned int frame_rate;
160 } u;
161};
162
163static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
164{
165 struct video_event kevent;
166 mm_segment_t old_fs = get_fs();
167 int err;
168
169 set_fs(KERNEL_DS);
170 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
171 set_fs(old_fs);
172
173 if (!err) {
174 struct compat_video_event __user *up = compat_ptr(arg);
175
176 err = put_user(kevent.type, &up->type);
177 err |= put_user(kevent.timestamp, &up->timestamp);
178 err |= put_user(kevent.u.size.w, &up->u.size.w);
179 err |= put_user(kevent.u.size.h, &up->u.size.h);
180 err |= put_user(kevent.u.size.aspect_ratio,
181 &up->u.size.aspect_ratio);
182 if (err)
183 err = -EFAULT;
184 }
185
186 return err;
187}
188
189struct compat_video_still_picture {
190 compat_uptr_t iFrame;
191 int32_t size;
192};
193
194static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
195{
196 struct compat_video_still_picture __user *up;
197 struct video_still_picture __user *up_native;
198 compat_uptr_t fp;
199 int32_t size;
200 int err;
201
202 up = (struct compat_video_still_picture __user *) arg;
203 err = get_user(fp, &up->iFrame);
204 err |= get_user(size, &up->size);
205 if (err)
206 return -EFAULT;
207
208 up_native =
209 compat_alloc_user_space(sizeof(struct video_still_picture));
210
Heiko Carstens7116e992006-12-06 20:36:36 -0800211 err = put_user(compat_ptr(fp), &up_native->iFrame);
212 err |= put_user(size, &up_native->size);
213 if (err)
214 return -EFAULT;
David S. Miller6e87abd2005-11-16 00:52:57 -0800215
216 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
217
218 return err;
219}
220
221struct compat_video_spu_palette {
222 int length;
223 compat_uptr_t palette;
224};
225
226static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
227{
228 struct compat_video_spu_palette __user *up;
229 struct video_spu_palette __user *up_native;
230 compat_uptr_t palp;
231 int length, err;
232
233 up = (struct compat_video_spu_palette __user *) arg;
234 err = get_user(palp, &up->palette);
235 err |= get_user(length, &up->length);
236
237 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
Heiko Carstens7116e992006-12-06 20:36:36 -0800238 err = put_user(compat_ptr(palp), &up_native->palette);
239 err |= put_user(length, &up_native->length);
240 if (err)
241 return -EFAULT;
David S. Miller6e87abd2005-11-16 00:52:57 -0800242
243 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
244
245 return err;
246}
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#ifdef CONFIG_NET
249static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
250{
251 struct compat_timeval __user *up = compat_ptr(arg);
252 struct timeval ktv;
253 mm_segment_t old_fs = get_fs();
254 int err;
255
256 set_fs(KERNEL_DS);
257 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
258 set_fs(old_fs);
259 if(!err) {
260 err = put_user(ktv.tv_sec, &up->tv_sec);
261 err |= __put_user(ktv.tv_usec, &up->tv_usec);
262 }
263 return err;
264}
265
Eric Dumazetae40eb12007-03-18 17:33:16 -0700266static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg)
267{
268 struct compat_timespec __user *up = compat_ptr(arg);
269 struct timespec kts;
270 mm_segment_t old_fs = get_fs();
271 int err;
272
273 set_fs(KERNEL_DS);
274 err = sys_ioctl(fd, cmd, (unsigned long)&kts);
275 set_fs(old_fs);
276 if (!err) {
277 err = put_user(kts.tv_sec, &up->tv_sec);
278 err |= __put_user(kts.tv_nsec, &up->tv_nsec);
279 }
280 return err;
281}
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283struct ifmap32 {
284 compat_ulong_t mem_start;
285 compat_ulong_t mem_end;
286 unsigned short base_addr;
287 unsigned char irq;
288 unsigned char dma;
289 unsigned char port;
290};
291
292struct ifreq32 {
293#define IFHWADDRLEN 6
294#define IFNAMSIZ 16
295 union {
296 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
297 } ifr_ifrn;
298 union {
299 struct sockaddr ifru_addr;
300 struct sockaddr ifru_dstaddr;
301 struct sockaddr ifru_broadaddr;
302 struct sockaddr ifru_netmask;
303 struct sockaddr ifru_hwaddr;
304 short ifru_flags;
305 compat_int_t ifru_ivalue;
306 compat_int_t ifru_mtu;
307 struct ifmap32 ifru_map;
308 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
309 char ifru_newname[IFNAMSIZ];
310 compat_caddr_t ifru_data;
311 /* XXXX? ifru_settings should be here */
312 } ifr_ifru;
313};
314
315struct ifconf32 {
316 compat_int_t ifc_len; /* size of buffer */
317 compat_caddr_t ifcbuf;
318};
319
320static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
321{
322 struct net_device *dev;
323 struct ifreq32 ifr32;
324 int err;
325
326 if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
327 return -EFAULT;
328
329 dev = dev_get_by_index(ifr32.ifr_ifindex);
330 if (!dev)
331 return -ENODEV;
332
333 strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
334 dev_put(dev);
335
336 err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
337 return (err ? -EFAULT : 0);
338}
339
340static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
341{
342 struct ifconf32 ifc32;
343 struct ifconf ifc;
344 struct ifconf __user *uifc;
345 struct ifreq32 __user *ifr32;
346 struct ifreq __user *ifr;
347 unsigned int i, j;
348 int err;
349
350 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
351 return -EFAULT;
352
353 if (ifc32.ifcbuf == 0) {
354 ifc32.ifc_len = 0;
355 ifc.ifc_len = 0;
356 ifc.ifc_req = NULL;
357 uifc = compat_alloc_user_space(sizeof(struct ifconf));
358 } else {
359 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
360 sizeof (struct ifreq);
361 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
362 ifc.ifc_len = len;
363 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
364 ifr32 = compat_ptr(ifc32.ifcbuf);
365 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
366 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
367 return -EFAULT;
368 ifr++;
369 ifr32++;
370 }
371 }
372 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
373 return -EFAULT;
374
375 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
376 if (err)
377 return err;
378
379 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
380 return -EFAULT;
381
382 ifr = ifc.ifc_req;
383 ifr32 = compat_ptr(ifc32.ifcbuf);
Alexandra Kossovsky49097242005-11-20 13:41:59 -0800384 for (i = 0, j = 0;
Randy Dunlap1efa3c02006-03-08 16:46:08 -0800385 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
387 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
388 return -EFAULT;
389 ifr32++;
390 ifr++;
391 }
392
393 if (ifc32.ifcbuf == 0) {
394 /* Translate from 64-bit structure multiple to
395 * a 32-bit one.
396 */
397 i = ifc.ifc_len;
398 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
399 ifc32.ifc_len = i;
400 } else {
Alexandra Kossovsky49097242005-11-20 13:41:59 -0800401 ifc32.ifc_len = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
404 return -EFAULT;
405
406 return 0;
407}
408
409static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
410{
411 struct ifreq __user *ifr;
412 struct ifreq32 __user *ifr32;
413 u32 data;
414 void __user *datap;
415
416 ifr = compat_alloc_user_space(sizeof(*ifr));
417 ifr32 = compat_ptr(arg);
418
419 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
420 return -EFAULT;
421
422 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
423 return -EFAULT;
424
425 datap = compat_ptr(data);
426 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
427 return -EFAULT;
428
429 return sys_ioctl(fd, cmd, (unsigned long) ifr);
430}
431
432static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
433{
434 struct ifreq kifr;
435 struct ifreq __user *uifr;
436 struct ifreq32 __user *ifr32 = compat_ptr(arg);
437 mm_segment_t old_fs;
438 int err;
439 u32 data;
440 void __user *datap;
441
442 switch (cmd) {
443 case SIOCBONDENSLAVE:
444 case SIOCBONDRELEASE:
445 case SIOCBONDSETHWADDR:
446 case SIOCBONDCHANGEACTIVE:
447 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
448 return -EFAULT;
449
450 old_fs = get_fs();
451 set_fs (KERNEL_DS);
452 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
453 set_fs (old_fs);
454
455 return err;
456 case SIOCBONDSLAVEINFOQUERY:
457 case SIOCBONDINFOQUERY:
458 uifr = compat_alloc_user_space(sizeof(*uifr));
459 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
460 return -EFAULT;
461
462 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
463 return -EFAULT;
464
465 datap = compat_ptr(data);
466 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
467 return -EFAULT;
468
469 return sys_ioctl (fd, cmd, (unsigned long)uifr);
470 default:
471 return -EINVAL;
472 };
473}
474
Christoph Hellwig6272e262007-05-08 00:29:21 -0700475static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 struct ifreq __user *u_ifreq64;
478 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
479 char tmp_buf[IFNAMSIZ];
480 void __user *data64;
481 u32 data32;
482
483 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
484 IFNAMSIZ))
485 return -EFAULT;
486 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
487 return -EFAULT;
488 data64 = compat_ptr(data32);
489
490 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
491
492 /* Don't check these user accesses, just let that get trapped
493 * in the ioctl handler instead.
494 */
495 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
496 IFNAMSIZ))
497 return -EFAULT;
498 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
499 return -EFAULT;
500
501 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
502}
503
504static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
505{
506 struct ifreq ifr;
507 struct ifreq32 __user *uifr32;
508 struct ifmap32 __user *uifmap32;
509 mm_segment_t old_fs;
510 int err;
511
512 uifr32 = compat_ptr(arg);
513 uifmap32 = &uifr32->ifr_ifru.ifru_map;
514 switch (cmd) {
515 case SIOCSIFMAP:
516 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
517 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
518 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
519 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
520 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
521 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
522 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
523 if (err)
524 return -EFAULT;
525 break;
526 default:
527 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
528 return -EFAULT;
529 break;
530 }
531 old_fs = get_fs();
532 set_fs (KERNEL_DS);
533 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
534 set_fs (old_fs);
535 if (!err) {
536 switch (cmd) {
537 /* TUNSETIFF is defined as _IOW, it should be _IORW
538 * as the data is copied back to user space, but that
539 * cannot be fixed without breaking all existing apps.
540 */
541 case TUNSETIFF:
542 case SIOCGIFFLAGS:
543 case SIOCGIFMETRIC:
544 case SIOCGIFMTU:
545 case SIOCGIFMEM:
546 case SIOCGIFHWADDR:
547 case SIOCGIFINDEX:
548 case SIOCGIFADDR:
549 case SIOCGIFBRDADDR:
550 case SIOCGIFDSTADDR:
551 case SIOCGIFNETMASK:
552 case SIOCGIFTXQLEN:
553 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
554 return -EFAULT;
555 break;
556 case SIOCGIFMAP:
557 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
558 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
559 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
560 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
561 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
562 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
563 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
564 if (err)
565 err = -EFAULT;
566 break;
567 }
568 }
569 return err;
570}
571
572struct rtentry32 {
573 u32 rt_pad1;
574 struct sockaddr rt_dst; /* target address */
575 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
576 struct sockaddr rt_genmask; /* target network mask (IP) */
577 unsigned short rt_flags;
578 short rt_pad2;
579 u32 rt_pad3;
580 unsigned char rt_tos;
581 unsigned char rt_class;
582 short rt_pad4;
583 short rt_metric; /* +1 for binary compatibility! */
584 /* char * */ u32 rt_dev; /* forcing the device at add */
585 u32 rt_mtu; /* per route MTU/Window */
586 u32 rt_window; /* Window clamping */
587 unsigned short rt_irtt; /* Initial RTT */
588
589};
590
591struct in6_rtmsg32 {
592 struct in6_addr rtmsg_dst;
593 struct in6_addr rtmsg_src;
594 struct in6_addr rtmsg_gateway;
595 u32 rtmsg_type;
596 u16 rtmsg_dst_len;
597 u16 rtmsg_src_len;
598 u32 rtmsg_metric;
599 u32 rtmsg_info;
600 u32 rtmsg_flags;
601 s32 rtmsg_ifindex;
602};
603
604static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
605{
606 int ret;
607 void *r = NULL;
608 struct in6_rtmsg r6;
609 struct rtentry r4;
610 char devname[16];
611 u32 rtdev;
612 mm_segment_t old_fs = get_fs();
613
614 struct socket *mysock = sockfd_lookup(fd, &ret);
615
616 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
617 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
618 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
619 3 * sizeof(struct in6_addr));
620 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
621 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
622 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
623 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
624 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
625 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
626 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
627
628 r = (void *) &r6;
629 } else { /* ipv4 */
630 struct rtentry32 __user *ur4 = compat_ptr(arg);
631 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
632 3 * sizeof(struct sockaddr));
633 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
634 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
635 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
636 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
637 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
638 ret |= __get_user (rtdev, &(ur4->rt_dev));
639 if (rtdev) {
640 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
641 r4.rt_dev = devname; devname[15] = 0;
642 } else
643 r4.rt_dev = NULL;
644
645 r = (void *) &r4;
646 }
647
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400648 if (ret) {
649 ret = -EFAULT;
650 goto out;
651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 set_fs (KERNEL_DS);
654 ret = sys_ioctl (fd, cmd, (unsigned long) r);
655 set_fs (old_fs);
656
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400657out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 if (mysock)
659 sockfd_put(mysock);
660
661 return ret;
662}
663#endif
664
David Howells93614012006-09-30 20:45:40 +0200665#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666struct hd_geometry32 {
667 unsigned char heads;
668 unsigned char sectors;
669 unsigned short cylinders;
670 u32 start;
671};
672
673static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
674{
675 mm_segment_t old_fs = get_fs();
676 struct hd_geometry geo;
677 struct hd_geometry32 __user *ugeo;
678 int err;
679
680 set_fs (KERNEL_DS);
681 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
682 set_fs (old_fs);
683 ugeo = compat_ptr(arg);
684 if (!err) {
685 err = copy_to_user (ugeo, &geo, 4);
686 err |= __put_user (geo.start, &ugeo->start);
Andreas Schwab83ae1b72007-05-08 00:31:38 -0700687 if (err)
688 err = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
Andreas Schwab83ae1b72007-05-08 00:31:38 -0700690 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
694{
695 mm_segment_t old_fs = get_fs();
696 unsigned long kval;
697 unsigned int __user *uvp;
698 int error;
699
700 set_fs(KERNEL_DS);
701 error = sys_ioctl(fd, cmd, (long)&kval);
702 set_fs(old_fs);
703
704 if(error == 0) {
705 uvp = compat_ptr(arg);
706 if(put_user(kval, uvp))
707 error = -EFAULT;
708 }
709 return error;
710}
711
712
713typedef struct sg_io_hdr32 {
714 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
715 compat_int_t dxfer_direction; /* [i] data transfer direction */
716 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
717 unsigned char mx_sb_len; /* [i] max length to write to sbp */
718 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
719 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
720 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
721 or scatter gather list */
722 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
723 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
724 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
725 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
726 compat_int_t pack_id; /* [i->o] unused internally (normally) */
727 compat_uptr_t usr_ptr; /* [i->o] unused internally */
728 unsigned char status; /* [o] scsi status */
729 unsigned char masked_status; /* [o] shifted, masked scsi status */
730 unsigned char msg_status; /* [o] messaging level data (optional) */
731 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
732 unsigned short host_status; /* [o] errors from host adapter */
733 unsigned short driver_status; /* [o] errors from software driver */
734 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
735 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
736 compat_uint_t info; /* [o] auxiliary information */
737} sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
738
739typedef struct sg_iovec32 {
740 compat_uint_t iov_base;
741 compat_uint_t iov_len;
742} sg_iovec32_t;
743
744static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
745{
746 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
747 sg_iovec32_t __user *iov32 = dxferp;
748 int i;
749
750 for (i = 0; i < iovec_count; i++) {
751 u32 base, len;
752
753 if (get_user(base, &iov32[i].iov_base) ||
754 get_user(len, &iov32[i].iov_len) ||
755 put_user(compat_ptr(base), &iov[i].iov_base) ||
756 put_user(len, &iov[i].iov_len))
757 return -EFAULT;
758 }
759
760 if (put_user(iov, &sgio->dxferp))
761 return -EFAULT;
762 return 0;
763}
764
765static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
766{
767 sg_io_hdr_t __user *sgio;
768 sg_io_hdr32_t __user *sgio32;
769 u16 iovec_count;
770 u32 data;
771 void __user *dxferp;
772 int err;
773
774 sgio32 = compat_ptr(arg);
775 if (get_user(iovec_count, &sgio32->iovec_count))
776 return -EFAULT;
777
778 {
779 void __user *top = compat_alloc_user_space(0);
780 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
781 (iovec_count * sizeof(sg_iovec_t)));
782 if (new > top)
783 return -EINVAL;
784
785 sgio = new;
786 }
787
788 /* Ok, now construct. */
789 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
790 (2 * sizeof(int)) +
791 (2 * sizeof(unsigned char)) +
792 (1 * sizeof(unsigned short)) +
793 (1 * sizeof(unsigned int))))
794 return -EFAULT;
795
796 if (get_user(data, &sgio32->dxferp))
797 return -EFAULT;
798 dxferp = compat_ptr(data);
799 if (iovec_count) {
800 if (sg_build_iovec(sgio, dxferp, iovec_count))
801 return -EFAULT;
802 } else {
803 if (put_user(dxferp, &sgio->dxferp))
804 return -EFAULT;
805 }
806
807 {
808 unsigned char __user *cmdp;
809 unsigned char __user *sbp;
810
811 if (get_user(data, &sgio32->cmdp))
812 return -EFAULT;
813 cmdp = compat_ptr(data);
814
815 if (get_user(data, &sgio32->sbp))
816 return -EFAULT;
817 sbp = compat_ptr(data);
818
819 if (put_user(cmdp, &sgio->cmdp) ||
820 put_user(sbp, &sgio->sbp))
821 return -EFAULT;
822 }
823
824 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
825 3 * sizeof(int)))
826 return -EFAULT;
827
828 if (get_user(data, &sgio32->usr_ptr))
829 return -EFAULT;
830 if (put_user(compat_ptr(data), &sgio->usr_ptr))
831 return -EFAULT;
832
833 if (copy_in_user(&sgio->status, &sgio32->status,
834 (4 * sizeof(unsigned char)) +
835 (2 * sizeof(unsigned (short))) +
836 (3 * sizeof(int))))
837 return -EFAULT;
838
839 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
840
841 if (err >= 0) {
842 void __user *datap;
843
844 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
845 sizeof(int)) ||
846 get_user(datap, &sgio->usr_ptr) ||
847 put_user((u32)(unsigned long)datap,
848 &sgio32->usr_ptr) ||
849 copy_in_user(&sgio32->status, &sgio->status,
850 (4 * sizeof(unsigned char)) +
851 (2 * sizeof(unsigned short)) +
852 (3 * sizeof(int))))
853 err = -EFAULT;
854 }
855
856 return err;
857}
858
Andi Kleen29663872006-01-11 22:44:03 +0100859struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
860 char req_state;
861 char orphan;
862 char sg_io_owned;
863 char problem;
864 int pack_id;
865 compat_uptr_t usr_ptr;
866 unsigned int duration;
867 int unused;
868};
869
870static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
871{
872 int err, i;
Al Viro6b2b4e52006-02-01 06:33:33 -0500873 sg_req_info_t __user *r;
874 struct compat_sg_req_info __user *o = (void __user *)arg;
Andi Kleen29663872006-01-11 22:44:03 +0100875 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
876 err = sys_ioctl(fd,cmd,(unsigned long)r);
877 if (err < 0)
878 return err;
879 for (i = 0; i < SG_MAX_QUEUE; i++) {
880 void __user *ptr;
881 int d;
882
883 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
884 get_user(ptr, &r[i].usr_ptr) ||
885 get_user(d, &r[i].duration) ||
886 put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
887 put_user(d, &o[i].duration))
888 return -EFAULT;
889 }
890 return err;
891}
David Howells93614012006-09-30 20:45:40 +0200892#endif /* CONFIG_BLOCK */
Andi Kleen29663872006-01-11 22:44:03 +0100893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894struct sock_fprog32 {
895 unsigned short len;
896 compat_caddr_t filter;
897};
898
899#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
900#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
901
902static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
903{
904 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
905 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
906 void __user *fptr64;
907 u32 fptr32;
908 u16 flen;
909
910 if (get_user(flen, &u_fprog32->len) ||
911 get_user(fptr32, &u_fprog32->filter))
912 return -EFAULT;
913
914 fptr64 = compat_ptr(fptr32);
915
916 if (put_user(flen, &u_fprog64->len) ||
917 put_user(fptr64, &u_fprog64->filter))
918 return -EFAULT;
919
920 if (cmd == PPPIOCSPASS32)
921 cmd = PPPIOCSPASS;
922 else
923 cmd = PPPIOCSACTIVE;
924
925 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
926}
927
928struct ppp_option_data32 {
929 compat_caddr_t ptr;
930 u32 length;
931 compat_int_t transmit;
932};
933#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
934
935struct ppp_idle32 {
936 compat_time_t xmit_idle;
937 compat_time_t recv_idle;
938};
939#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
940
941static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
942{
943 struct ppp_idle __user *idle;
944 struct ppp_idle32 __user *idle32;
945 __kernel_time_t xmit, recv;
946 int err;
947
948 idle = compat_alloc_user_space(sizeof(*idle));
949 idle32 = compat_ptr(arg);
950
951 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
952
953 if (!err) {
954 if (get_user(xmit, &idle->xmit_idle) ||
955 get_user(recv, &idle->recv_idle) ||
956 put_user(xmit, &idle32->xmit_idle) ||
957 put_user(recv, &idle32->recv_idle))
958 err = -EFAULT;
959 }
960 return err;
961}
962
963static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
964{
965 struct ppp_option_data __user *odata;
966 struct ppp_option_data32 __user *odata32;
967 __u32 data;
968 void __user *datap;
969
970 odata = compat_alloc_user_space(sizeof(*odata));
971 odata32 = compat_ptr(arg);
972
973 if (get_user(data, &odata32->ptr))
974 return -EFAULT;
975
976 datap = compat_ptr(data);
977 if (put_user(datap, &odata->ptr))
978 return -EFAULT;
979
980 if (copy_in_user(&odata->length, &odata32->length,
981 sizeof(__u32) + sizeof(int)))
982 return -EFAULT;
983
984 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
985}
986
987static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
988{
989 int err;
990
991 switch (cmd) {
992 case PPPIOCGIDLE32:
993 err = ppp_gidle(fd, cmd, arg);
994 break;
995
996 case PPPIOCSCOMPRESS32:
997 err = ppp_scompress(fd, cmd, arg);
998 break;
999
1000 default:
1001 do {
1002 static int count;
1003 if (++count <= 20)
1004 printk("ppp_ioctl: Unknown cmd fd(%d) "
1005 "cmd(%08x) arg(%08x)\n",
1006 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1007 } while(0);
1008 err = -EINVAL;
1009 break;
1010 };
1011
1012 return err;
1013}
1014
1015
David Howells93614012006-09-30 20:45:40 +02001016#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017struct mtget32 {
1018 compat_long_t mt_type;
1019 compat_long_t mt_resid;
1020 compat_long_t mt_dsreg;
1021 compat_long_t mt_gstat;
1022 compat_long_t mt_erreg;
1023 compat_daddr_t mt_fileno;
1024 compat_daddr_t mt_blkno;
1025};
1026#define MTIOCGET32 _IOR('m', 2, struct mtget32)
1027
1028struct mtpos32 {
1029 compat_long_t mt_blkno;
1030};
1031#define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
1032
1033static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1034{
1035 mm_segment_t old_fs = get_fs();
1036 struct mtget get;
1037 struct mtget32 __user *umget32;
1038 struct mtpos pos;
1039 struct mtpos32 __user *upos32;
1040 unsigned long kcmd;
1041 void *karg;
1042 int err = 0;
1043
1044 switch(cmd) {
1045 case MTIOCPOS32:
1046 kcmd = MTIOCPOS;
1047 karg = &pos;
1048 break;
1049 case MTIOCGET32:
1050 kcmd = MTIOCGET;
1051 karg = &get;
1052 break;
1053 default:
1054 do {
1055 static int count;
1056 if (++count <= 20)
1057 printk("mt_ioctl: Unknown cmd fd(%d) "
1058 "cmd(%08x) arg(%08x)\n",
1059 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1060 } while(0);
1061 return -EINVAL;
1062 }
1063 set_fs (KERNEL_DS);
1064 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1065 set_fs (old_fs);
1066 if (err)
1067 return err;
1068 switch (cmd) {
1069 case MTIOCPOS32:
1070 upos32 = compat_ptr(arg);
1071 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1072 break;
1073 case MTIOCGET32:
1074 umget32 = compat_ptr(arg);
1075 err = __put_user(get.mt_type, &umget32->mt_type);
1076 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1077 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1078 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1079 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1080 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1081 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1082 break;
1083 }
1084 return err ? -EFAULT: 0;
1085}
1086
1087struct cdrom_read_audio32 {
1088 union cdrom_addr addr;
1089 u8 addr_format;
1090 compat_int_t nframes;
1091 compat_caddr_t buf;
1092};
1093
1094struct cdrom_generic_command32 {
1095 unsigned char cmd[CDROM_PACKET_SIZE];
1096 compat_caddr_t buffer;
1097 compat_uint_t buflen;
1098 compat_int_t stat;
1099 compat_caddr_t sense;
1100 unsigned char data_direction;
1101 compat_int_t quiet;
1102 compat_int_t timeout;
1103 compat_caddr_t reserved[1];
1104};
1105
1106static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1107{
1108 struct cdrom_read_audio __user *cdread_audio;
1109 struct cdrom_read_audio32 __user *cdread_audio32;
1110 __u32 data;
1111 void __user *datap;
1112
1113 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1114 cdread_audio32 = compat_ptr(arg);
1115
1116 if (copy_in_user(&cdread_audio->addr,
1117 &cdread_audio32->addr,
1118 (sizeof(*cdread_audio32) -
1119 sizeof(compat_caddr_t))))
1120 return -EFAULT;
1121
1122 if (get_user(data, &cdread_audio32->buf))
1123 return -EFAULT;
1124 datap = compat_ptr(data);
1125 if (put_user(datap, &cdread_audio->buf))
1126 return -EFAULT;
1127
1128 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1129}
1130
1131static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1132{
1133 struct cdrom_generic_command __user *cgc;
1134 struct cdrom_generic_command32 __user *cgc32;
1135 u32 data;
1136 unsigned char dir;
1137 int itmp;
1138
1139 cgc = compat_alloc_user_space(sizeof(*cgc));
1140 cgc32 = compat_ptr(arg);
1141
1142 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1143 get_user(data, &cgc32->buffer) ||
1144 put_user(compat_ptr(data), &cgc->buffer) ||
1145 copy_in_user(&cgc->buflen, &cgc32->buflen,
1146 (sizeof(unsigned int) + sizeof(int))) ||
1147 get_user(data, &cgc32->sense) ||
1148 put_user(compat_ptr(data), &cgc->sense) ||
1149 get_user(dir, &cgc32->data_direction) ||
1150 put_user(dir, &cgc->data_direction) ||
1151 get_user(itmp, &cgc32->quiet) ||
1152 put_user(itmp, &cgc->quiet) ||
1153 get_user(itmp, &cgc32->timeout) ||
1154 put_user(itmp, &cgc->timeout) ||
1155 get_user(data, &cgc32->reserved[0]) ||
1156 put_user(compat_ptr(data), &cgc->reserved[0]))
1157 return -EFAULT;
1158
1159 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1160}
1161
1162static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1163{
1164 int err;
1165
1166 switch(cmd) {
1167 case CDROMREADAUDIO:
1168 err = cdrom_do_read_audio(fd, cmd, arg);
1169 break;
1170
1171 case CDROM_SEND_PACKET:
1172 err = cdrom_do_generic_command(fd, cmd, arg);
1173 break;
1174
1175 default:
1176 do {
1177 static int count;
1178 if (++count <= 20)
1179 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1180 "cmd(%08x) arg(%08x)\n",
1181 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1182 } while(0);
1183 err = -EINVAL;
1184 break;
1185 };
1186
1187 return err;
1188}
David Howells93614012006-09-30 20:45:40 +02001189#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191#ifdef CONFIG_VT
1192
1193static int vt_check(struct file *file)
1194{
1195 struct tty_struct *tty;
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001196 struct inode *inode = file->f_path.dentry->d_inode;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001197 struct vc_data *vc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 if (file->f_op->ioctl != tty_ioctl)
1200 return -EINVAL;
1201
1202 tty = (struct tty_struct *)file->private_data;
1203 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1204 return -EINVAL;
1205
1206 if (tty->driver->ioctl != vt_ioctl)
1207 return -EINVAL;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001208
1209 vc = (struct vc_data *)tty->driver_data;
1210 if (!vc_cons_allocated(vc->vc_num)) /* impossible? */
1211 return -ENOIOCTLCMD;
1212
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 /*
1214 * To have permissions to do most of the vt ioctls, we either have
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001215 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 */
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001217 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 return 1;
1219 return 0;
1220}
1221
1222struct consolefontdesc32 {
1223 unsigned short charcount; /* characters in font (256 or 512) */
1224 unsigned short charheight; /* scan lines per character (1-32) */
1225 compat_caddr_t chardata; /* font data in expanded form */
1226};
1227
1228static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1229{
1230 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1231 struct console_font_op op;
1232 compat_caddr_t data;
1233 int i, perm;
1234
1235 perm = vt_check(file);
1236 if (perm < 0) return perm;
1237
1238 switch (cmd) {
1239 case PIO_FONTX:
1240 if (!perm)
1241 return -EPERM;
1242 op.op = KD_FONT_OP_SET;
1243 op.flags = 0;
1244 op.width = 8;
1245 if (get_user(op.height, &user_cfd->charheight) ||
1246 get_user(op.charcount, &user_cfd->charcount) ||
1247 get_user(data, &user_cfd->chardata))
1248 return -EFAULT;
1249 op.data = compat_ptr(data);
1250 return con_font_op(vc_cons[fg_console].d, &op);
1251 case GIO_FONTX:
1252 op.op = KD_FONT_OP_GET;
1253 op.flags = 0;
1254 op.width = 8;
1255 if (get_user(op.height, &user_cfd->charheight) ||
1256 get_user(op.charcount, &user_cfd->charcount) ||
1257 get_user(data, &user_cfd->chardata))
1258 return -EFAULT;
1259 if (!data)
1260 return 0;
1261 op.data = compat_ptr(data);
1262 i = con_font_op(vc_cons[fg_console].d, &op);
1263 if (i)
1264 return i;
1265 if (put_user(op.height, &user_cfd->charheight) ||
1266 put_user(op.charcount, &user_cfd->charcount) ||
1267 put_user((compat_caddr_t)(unsigned long)op.data,
1268 &user_cfd->chardata))
1269 return -EFAULT;
1270 return 0;
1271 }
1272 return -EINVAL;
1273}
1274
1275struct console_font_op32 {
1276 compat_uint_t op; /* operation code KD_FONT_OP_* */
1277 compat_uint_t flags; /* KD_FONT_FLAG_* */
1278 compat_uint_t width, height; /* font size */
1279 compat_uint_t charcount;
1280 compat_caddr_t data; /* font data with height fixed to 32 */
1281};
1282
1283static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1284{
1285 struct console_font_op op;
1286 struct console_font_op32 __user *fontop = compat_ptr(arg);
1287 int perm = vt_check(file), i;
1288 struct vc_data *vc;
1289
1290 if (perm < 0) return perm;
1291
1292 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1293 return -EFAULT;
1294 if (!perm && op.op != KD_FONT_OP_GET)
1295 return -EPERM;
1296 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1297 op.flags |= KD_FONT_FLAG_OLD;
1298 vc = ((struct tty_struct *)file->private_data)->driver_data;
1299 i = con_font_op(vc, &op);
1300 if (i)
1301 return i;
1302 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1303 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1304 return -EFAULT;
1305 return 0;
1306}
1307
1308struct unimapdesc32 {
1309 unsigned short entry_ct;
1310 compat_caddr_t entries;
1311};
1312
1313static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1314{
1315 struct unimapdesc32 tmp;
1316 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1317 int perm = vt_check(file);
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001318 struct vc_data *vc;
1319
1320 if (perm < 0)
1321 return perm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1323 return -EFAULT;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001324 if (tmp.entries)
1325 if (!access_ok(VERIFY_WRITE, compat_ptr(tmp.entries),
1326 tmp.entry_ct*sizeof(struct unipair)))
1327 return -EFAULT;
1328 vc = ((struct tty_struct *)file->private_data)->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 switch (cmd) {
1330 case PIO_UNIMAP:
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001331 if (!perm)
1332 return -EPERM;
1333 return con_set_unimap(vc, tmp.entry_ct,
1334 compat_ptr(tmp.entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 case GIO_UNIMAP:
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001336 if (!perm && fg_console != vc->vc_num)
1337 return -EPERM;
1338 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct),
1339 compat_ptr(tmp.entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341 return 0;
1342}
1343
1344#endif /* CONFIG_VT */
1345
1346static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1347{
1348 mm_segment_t old_fs = get_fs();
1349 __kernel_uid_t kuid;
1350 int err;
1351
1352 cmd = SMB_IOC_GETMOUNTUID;
1353
1354 set_fs(KERNEL_DS);
1355 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1356 set_fs(old_fs);
1357
1358 if (err >= 0)
1359 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1360
1361 return err;
1362}
1363
1364struct atmif_sioc32 {
1365 compat_int_t number;
1366 compat_int_t length;
1367 compat_caddr_t arg;
1368};
1369
1370struct atm_iobuf32 {
1371 compat_int_t length;
1372 compat_caddr_t buffer;
1373};
1374
1375#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1376#define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1377#define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1378#define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1379#define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1380#define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1381#define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1382#define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1383#define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1384#define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1385#define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1386#define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1387#define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1388#define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1389#define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1390#define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1391#define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1392
1393static struct {
1394 unsigned int cmd32;
1395 unsigned int cmd;
1396} atm_ioctl_map[] = {
1397 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1398 { ATM_GETNAMES32, ATM_GETNAMES },
1399 { ATM_GETTYPE32, ATM_GETTYPE },
1400 { ATM_GETESI32, ATM_GETESI },
1401 { ATM_GETADDR32, ATM_GETADDR },
1402 { ATM_RSTADDR32, ATM_RSTADDR },
1403 { ATM_ADDADDR32, ATM_ADDADDR },
1404 { ATM_DELADDR32, ATM_DELADDR },
1405 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1406 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1407 { ATM_SETESI32, ATM_SETESI },
1408 { ATM_SETESIF32, ATM_SETESIF },
1409 { ATM_GETSTAT32, ATM_GETSTAT },
1410 { ATM_GETSTATZ32, ATM_GETSTATZ },
1411 { ATM_GETLOOP32, ATM_GETLOOP },
1412 { ATM_SETLOOP32, ATM_SETLOOP },
1413 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1414};
1415
Tobias Klausere8c96f82006-03-24 03:15:34 -08001416#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1419{
1420 struct atm_iobuf __user *iobuf;
1421 struct atm_iobuf32 __user *iobuf32;
1422 u32 data;
1423 void __user *datap;
1424 int len, err;
1425
1426 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1427 iobuf32 = compat_ptr(arg);
1428
1429 if (get_user(len, &iobuf32->length) ||
1430 get_user(data, &iobuf32->buffer))
1431 return -EFAULT;
1432 datap = compat_ptr(data);
1433 if (put_user(len, &iobuf->length) ||
1434 put_user(datap, &iobuf->buffer))
1435 return -EFAULT;
1436
1437 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1438
1439 if (!err) {
1440 if (copy_in_user(&iobuf32->length, &iobuf->length,
1441 sizeof(int)))
1442 err = -EFAULT;
1443 }
1444
1445 return err;
1446}
1447
1448static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1449{
1450 struct atmif_sioc __user *sioc;
1451 struct atmif_sioc32 __user *sioc32;
1452 u32 data;
1453 void __user *datap;
1454 int err;
1455
1456 sioc = compat_alloc_user_space(sizeof(*sioc));
1457 sioc32 = compat_ptr(arg);
1458
1459 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1460 get_user(data, &sioc32->arg))
1461 return -EFAULT;
1462 datap = compat_ptr(data);
1463 if (put_user(datap, &sioc->arg))
1464 return -EFAULT;
1465
1466 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1467
1468 if (!err) {
1469 if (copy_in_user(&sioc32->length, &sioc->length,
1470 sizeof(int)))
1471 err = -EFAULT;
1472 }
1473 return err;
1474}
1475
1476static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1477{
1478 int i;
1479 unsigned int cmd = 0;
1480
1481 switch (cmd32) {
1482 case SONET_GETSTAT:
1483 case SONET_GETSTATZ:
1484 case SONET_GETDIAG:
1485 case SONET_SETDIAG:
1486 case SONET_CLRDIAG:
1487 case SONET_SETFRAMING:
1488 case SONET_GETFRAMING:
1489 case SONET_GETFRSENSE:
1490 return do_atmif_sioc(fd, cmd32, arg);
1491 }
1492
1493 for (i = 0; i < NR_ATM_IOCTL; i++) {
1494 if (cmd32 == atm_ioctl_map[i].cmd32) {
1495 cmd = atm_ioctl_map[i].cmd;
1496 break;
1497 }
1498 }
1499 if (i == NR_ATM_IOCTL)
1500 return -EINVAL;
1501
1502 switch (cmd) {
1503 case ATM_GETNAMES:
1504 return do_atm_iobuf(fd, cmd, arg);
1505
1506 case ATM_GETLINKRATE:
1507 case ATM_GETTYPE:
1508 case ATM_GETESI:
1509 case ATM_GETADDR:
1510 case ATM_RSTADDR:
1511 case ATM_ADDADDR:
1512 case ATM_DELADDR:
1513 case ATM_GETCIRANGE:
1514 case ATM_SETCIRANGE:
1515 case ATM_SETESI:
1516 case ATM_SETESIF:
1517 case ATM_GETSTAT:
1518 case ATM_GETSTATZ:
1519 case ATM_GETLOOP:
1520 case ATM_SETLOOP:
1521 case ATM_QUERYLOOP:
1522 return do_atmif_sioc(fd, cmd, arg);
1523 }
1524
1525 return -EINVAL;
1526}
1527
1528static __attribute_used__ int
1529ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1530{
1531 return -EINVAL;
1532}
1533
David Howells93614012006-09-30 20:45:40 +02001534#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1536{
1537 /* The mkswap binary hard codes it to Intel value :-((( */
1538 return w_long(fd, BLKGETSIZE, arg);
1539}
1540
1541struct blkpg_ioctl_arg32 {
1542 compat_int_t op;
1543 compat_int_t flags;
1544 compat_int_t datalen;
1545 compat_caddr_t data;
1546};
1547
1548static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1549{
1550 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1551 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1552 compat_caddr_t udata;
1553 compat_int_t n;
1554 int err;
1555
1556 err = get_user(n, &ua32->op);
1557 err |= put_user(n, &a->op);
1558 err |= get_user(n, &ua32->flags);
1559 err |= put_user(n, &a->flags);
1560 err |= get_user(n, &ua32->datalen);
1561 err |= put_user(n, &a->datalen);
1562 err |= get_user(udata, &ua32->data);
1563 err |= put_user(compat_ptr(udata), &a->data);
1564 if (err)
1565 return err;
1566
1567 return sys_ioctl(fd, cmd, (unsigned long)a);
1568}
David Howells93614012006-09-30 20:45:40 +02001569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1572{
1573 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1574}
1575
David Howells93614012006-09-30 20:45:40 +02001576#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577/* Fix sizeof(sizeof()) breakage */
1578#define BLKBSZGET_32 _IOR(0x12,112,int)
1579#define BLKBSZSET_32 _IOW(0x12,113,int)
1580#define BLKGETSIZE64_32 _IOR(0x12,114,int)
1581
1582static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1583{
1584 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1585}
1586
1587static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1588{
1589 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1590}
1591
1592static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1593 unsigned long arg)
1594{
1595 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1596}
David Howells93614012006-09-30 20:45:40 +02001597#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599/* Bluetooth ioctls */
1600#define HCIUARTSETPROTO _IOW('U', 200, int)
1601#define HCIUARTGETPROTO _IOR('U', 201, int)
1602
1603#define BNEPCONNADD _IOW('B', 200, int)
1604#define BNEPCONNDEL _IOW('B', 201, int)
1605#define BNEPGETCONNLIST _IOR('B', 210, int)
1606#define BNEPGETCONNINFO _IOR('B', 211, int)
1607
1608#define CMTPCONNADD _IOW('C', 200, int)
1609#define CMTPCONNDEL _IOW('C', 201, int)
1610#define CMTPGETCONNLIST _IOR('C', 210, int)
1611#define CMTPGETCONNINFO _IOR('C', 211, int)
1612
1613#define HIDPCONNADD _IOW('H', 200, int)
1614#define HIDPCONNDEL _IOW('H', 201, int)
1615#define HIDPGETCONNLIST _IOR('H', 210, int)
1616#define HIDPGETCONNINFO _IOR('H', 211, int)
1617
David Howells93614012006-09-30 20:45:40 +02001618#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619struct floppy_struct32 {
1620 compat_uint_t size;
1621 compat_uint_t sect;
1622 compat_uint_t head;
1623 compat_uint_t track;
1624 compat_uint_t stretch;
1625 unsigned char gap;
1626 unsigned char rate;
1627 unsigned char spec1;
1628 unsigned char fmt_gap;
1629 const compat_caddr_t name;
1630};
1631
1632struct floppy_drive_params32 {
1633 char cmos;
1634 compat_ulong_t max_dtr;
1635 compat_ulong_t hlt;
1636 compat_ulong_t hut;
1637 compat_ulong_t srt;
1638 compat_ulong_t spinup;
1639 compat_ulong_t spindown;
1640 unsigned char spindown_offset;
1641 unsigned char select_delay;
1642 unsigned char rps;
1643 unsigned char tracks;
1644 compat_ulong_t timeout;
1645 unsigned char interleave_sect;
1646 struct floppy_max_errors max_errors;
1647 char flags;
1648 char read_track;
1649 short autodetect[8];
1650 compat_int_t checkfreq;
1651 compat_int_t native_format;
1652};
1653
1654struct floppy_drive_struct32 {
1655 signed char flags;
1656 compat_ulong_t spinup_date;
1657 compat_ulong_t select_date;
1658 compat_ulong_t first_read_date;
1659 short probed_format;
1660 short track;
1661 short maxblock;
1662 short maxtrack;
1663 compat_int_t generation;
1664 compat_int_t keep_data;
1665 compat_int_t fd_ref;
1666 compat_int_t fd_device;
1667 compat_int_t last_checked;
1668 compat_caddr_t dmabuf;
1669 compat_int_t bufblocks;
1670};
1671
1672struct floppy_fdc_state32 {
1673 compat_int_t spec1;
1674 compat_int_t spec2;
1675 compat_int_t dtr;
1676 unsigned char version;
1677 unsigned char dor;
1678 compat_ulong_t address;
1679 unsigned int rawcmd:2;
1680 unsigned int reset:1;
1681 unsigned int need_configure:1;
1682 unsigned int perp_mode:2;
1683 unsigned int has_fifo:1;
1684 unsigned int driver_version;
1685 unsigned char track[4];
1686};
1687
1688struct floppy_write_errors32 {
1689 unsigned int write_errors;
1690 compat_ulong_t first_error_sector;
1691 compat_int_t first_error_generation;
1692 compat_ulong_t last_error_sector;
1693 compat_int_t last_error_generation;
1694 compat_uint_t badness;
1695};
1696
1697#define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1698#define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1699#define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1700#define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1701#define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1702#define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1703#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1704#define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1705#define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1706
1707static struct {
1708 unsigned int cmd32;
1709 unsigned int cmd;
1710} fd_ioctl_trans_table[] = {
1711 { FDSETPRM32, FDSETPRM },
1712 { FDDEFPRM32, FDDEFPRM },
1713 { FDGETPRM32, FDGETPRM },
1714 { FDSETDRVPRM32, FDSETDRVPRM },
1715 { FDGETDRVPRM32, FDGETDRVPRM },
1716 { FDGETDRVSTAT32, FDGETDRVSTAT },
1717 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1718 { FDGETFDCSTAT32, FDGETFDCSTAT },
1719 { FDWERRORGET32, FDWERRORGET }
1720};
1721
Tobias Klausere8c96f82006-03-24 03:15:34 -08001722#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1725{
1726 mm_segment_t old_fs = get_fs();
1727 void *karg = NULL;
1728 unsigned int kcmd = 0;
1729 int i, err;
1730
1731 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1732 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1733 kcmd = fd_ioctl_trans_table[i].cmd;
1734 break;
1735 }
1736 if (!kcmd)
1737 return -EINVAL;
1738
1739 switch (cmd) {
1740 case FDSETPRM32:
1741 case FDDEFPRM32:
1742 case FDGETPRM32:
1743 {
1744 compat_uptr_t name;
1745 struct floppy_struct32 __user *uf;
1746 struct floppy_struct *f;
1747
1748 uf = compat_ptr(arg);
1749 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1750 if (!karg)
1751 return -ENOMEM;
1752 if (cmd == FDGETPRM32)
1753 break;
1754 err = __get_user(f->size, &uf->size);
1755 err |= __get_user(f->sect, &uf->sect);
1756 err |= __get_user(f->head, &uf->head);
1757 err |= __get_user(f->track, &uf->track);
1758 err |= __get_user(f->stretch, &uf->stretch);
1759 err |= __get_user(f->gap, &uf->gap);
1760 err |= __get_user(f->rate, &uf->rate);
1761 err |= __get_user(f->spec1, &uf->spec1);
1762 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1763 err |= __get_user(name, &uf->name);
1764 f->name = compat_ptr(name);
1765 if (err) {
1766 err = -EFAULT;
1767 goto out;
1768 }
1769 break;
1770 }
1771 case FDSETDRVPRM32:
1772 case FDGETDRVPRM32:
1773 {
1774 struct floppy_drive_params32 __user *uf;
1775 struct floppy_drive_params *f;
1776
1777 uf = compat_ptr(arg);
1778 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1779 if (!karg)
1780 return -ENOMEM;
1781 if (cmd == FDGETDRVPRM32)
1782 break;
1783 err = __get_user(f->cmos, &uf->cmos);
1784 err |= __get_user(f->max_dtr, &uf->max_dtr);
1785 err |= __get_user(f->hlt, &uf->hlt);
1786 err |= __get_user(f->hut, &uf->hut);
1787 err |= __get_user(f->srt, &uf->srt);
1788 err |= __get_user(f->spinup, &uf->spinup);
1789 err |= __get_user(f->spindown, &uf->spindown);
1790 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1791 err |= __get_user(f->select_delay, &uf->select_delay);
1792 err |= __get_user(f->rps, &uf->rps);
1793 err |= __get_user(f->tracks, &uf->tracks);
1794 err |= __get_user(f->timeout, &uf->timeout);
1795 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1796 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1797 err |= __get_user(f->flags, &uf->flags);
1798 err |= __get_user(f->read_track, &uf->read_track);
1799 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1800 err |= __get_user(f->checkfreq, &uf->checkfreq);
1801 err |= __get_user(f->native_format, &uf->native_format);
1802 if (err) {
1803 err = -EFAULT;
1804 goto out;
1805 }
1806 break;
1807 }
1808 case FDGETDRVSTAT32:
1809 case FDPOLLDRVSTAT32:
1810 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1811 if (!karg)
1812 return -ENOMEM;
1813 break;
1814 case FDGETFDCSTAT32:
1815 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1816 if (!karg)
1817 return -ENOMEM;
1818 break;
1819 case FDWERRORGET32:
1820 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1821 if (!karg)
1822 return -ENOMEM;
1823 break;
1824 default:
1825 return -EINVAL;
1826 }
1827 set_fs (KERNEL_DS);
1828 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1829 set_fs (old_fs);
1830 if (err)
1831 goto out;
1832 switch (cmd) {
1833 case FDGETPRM32:
1834 {
1835 struct floppy_struct *f = karg;
1836 struct floppy_struct32 __user *uf = compat_ptr(arg);
1837
1838 err = __put_user(f->size, &uf->size);
1839 err |= __put_user(f->sect, &uf->sect);
1840 err |= __put_user(f->head, &uf->head);
1841 err |= __put_user(f->track, &uf->track);
1842 err |= __put_user(f->stretch, &uf->stretch);
1843 err |= __put_user(f->gap, &uf->gap);
1844 err |= __put_user(f->rate, &uf->rate);
1845 err |= __put_user(f->spec1, &uf->spec1);
1846 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1847 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1848 break;
1849 }
1850 case FDGETDRVPRM32:
1851 {
1852 struct floppy_drive_params32 __user *uf;
1853 struct floppy_drive_params *f = karg;
1854
1855 uf = compat_ptr(arg);
1856 err = __put_user(f->cmos, &uf->cmos);
1857 err |= __put_user(f->max_dtr, &uf->max_dtr);
1858 err |= __put_user(f->hlt, &uf->hlt);
1859 err |= __put_user(f->hut, &uf->hut);
1860 err |= __put_user(f->srt, &uf->srt);
1861 err |= __put_user(f->spinup, &uf->spinup);
1862 err |= __put_user(f->spindown, &uf->spindown);
1863 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1864 err |= __put_user(f->select_delay, &uf->select_delay);
1865 err |= __put_user(f->rps, &uf->rps);
1866 err |= __put_user(f->tracks, &uf->tracks);
1867 err |= __put_user(f->timeout, &uf->timeout);
1868 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1869 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1870 err |= __put_user(f->flags, &uf->flags);
1871 err |= __put_user(f->read_track, &uf->read_track);
1872 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1873 err |= __put_user(f->checkfreq, &uf->checkfreq);
1874 err |= __put_user(f->native_format, &uf->native_format);
1875 break;
1876 }
1877 case FDGETDRVSTAT32:
1878 case FDPOLLDRVSTAT32:
1879 {
1880 struct floppy_drive_struct32 __user *uf;
1881 struct floppy_drive_struct *f = karg;
1882
1883 uf = compat_ptr(arg);
1884 err = __put_user(f->flags, &uf->flags);
1885 err |= __put_user(f->spinup_date, &uf->spinup_date);
1886 err |= __put_user(f->select_date, &uf->select_date);
1887 err |= __put_user(f->first_read_date, &uf->first_read_date);
1888 err |= __put_user(f->probed_format, &uf->probed_format);
1889 err |= __put_user(f->track, &uf->track);
1890 err |= __put_user(f->maxblock, &uf->maxblock);
1891 err |= __put_user(f->maxtrack, &uf->maxtrack);
1892 err |= __put_user(f->generation, &uf->generation);
1893 err |= __put_user(f->keep_data, &uf->keep_data);
1894 err |= __put_user(f->fd_ref, &uf->fd_ref);
1895 err |= __put_user(f->fd_device, &uf->fd_device);
1896 err |= __put_user(f->last_checked, &uf->last_checked);
1897 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1898 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1899 break;
1900 }
1901 case FDGETFDCSTAT32:
1902 {
1903 struct floppy_fdc_state32 __user *uf;
1904 struct floppy_fdc_state *f = karg;
1905
1906 uf = compat_ptr(arg);
1907 err = __put_user(f->spec1, &uf->spec1);
1908 err |= __put_user(f->spec2, &uf->spec2);
1909 err |= __put_user(f->dtr, &uf->dtr);
1910 err |= __put_user(f->version, &uf->version);
1911 err |= __put_user(f->dor, &uf->dor);
1912 err |= __put_user(f->address, &uf->address);
1913 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1914 (char *)&f->address + sizeof(f->address), sizeof(int));
1915 err |= __put_user(f->driver_version, &uf->driver_version);
1916 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1917 break;
1918 }
1919 case FDWERRORGET32:
1920 {
1921 struct floppy_write_errors32 __user *uf;
1922 struct floppy_write_errors *f = karg;
1923
1924 uf = compat_ptr(arg);
1925 err = __put_user(f->write_errors, &uf->write_errors);
1926 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
1927 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
1928 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
1929 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
1930 err |= __put_user(f->badness, &uf->badness);
1931 break;
1932 }
1933 default:
1934 break;
1935 }
1936 if (err)
1937 err = -EFAULT;
1938
Jesper Juhlf99d49a2005-11-07 01:01:34 -08001939out:
1940 kfree(karg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 return err;
1942}
David Howells93614012006-09-30 20:45:40 +02001943#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
1945struct mtd_oob_buf32 {
1946 u_int32_t start;
1947 u_int32_t length;
1948 compat_caddr_t ptr; /* unsigned char* */
1949};
1950
1951#define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
1952#define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
1953
1954static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
1955{
1956 struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
1957 struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
1958 u32 data;
1959 char __user *datap;
1960 unsigned int real_cmd;
1961 int err;
1962
1963 real_cmd = (cmd == MEMREADOOB32) ?
1964 MEMREADOOB : MEMWRITEOOB;
1965
1966 if (copy_in_user(&buf->start, &buf32->start,
1967 2 * sizeof(u32)) ||
1968 get_user(data, &buf32->ptr))
1969 return -EFAULT;
1970 datap = compat_ptr(data);
1971 if (put_user(datap, &buf->ptr))
1972 return -EFAULT;
1973
1974 err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
1975
1976 if (!err) {
1977 if (copy_in_user(&buf32->start, &buf->start,
1978 2 * sizeof(u32)))
1979 err = -EFAULT;
1980 }
1981
1982 return err;
1983}
1984
David Howells93614012006-09-30 20:45:40 +02001985#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986struct raw32_config_request
1987{
1988 compat_int_t raw_minor;
1989 __u64 block_major;
1990 __u64 block_minor;
1991} __attribute__((packed));
1992
1993static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1994{
1995 int ret;
1996
1997 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
1998 return -EFAULT;
1999
2000 ret = __get_user(req->raw_minor, &user_req->raw_minor);
2001 ret |= __get_user(req->block_major, &user_req->block_major);
2002 ret |= __get_user(req->block_minor, &user_req->block_minor);
2003
2004 return ret ? -EFAULT : 0;
2005}
2006
2007static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
2008{
2009 int ret;
2010
2011 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
2012 return -EFAULT;
2013
2014 ret = __put_user(req->raw_minor, &user_req->raw_minor);
2015 ret |= __put_user(req->block_major, &user_req->block_major);
2016 ret |= __put_user(req->block_minor, &user_req->block_minor);
2017
2018 return ret ? -EFAULT : 0;
2019}
2020
2021static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2022{
2023 int ret;
2024
2025 switch (cmd) {
2026 case RAW_SETBIND:
2027 case RAW_GETBIND: {
2028 struct raw_config_request req;
2029 struct raw32_config_request __user *user_req = compat_ptr(arg);
2030 mm_segment_t oldfs = get_fs();
2031
2032 if ((ret = get_raw32_request(&req, user_req)))
2033 return ret;
2034
2035 set_fs(KERNEL_DS);
2036 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
2037 set_fs(oldfs);
2038
2039 if ((!ret) && (cmd == RAW_GETBIND)) {
2040 ret = set_raw32_request(&req, user_req);
2041 }
2042 break;
2043 }
2044 default:
2045 ret = sys_ioctl(fd, cmd, arg);
2046 break;
2047 }
2048 return ret;
2049}
David Howells93614012006-09-30 20:45:40 +02002050#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
2052struct serial_struct32 {
2053 compat_int_t type;
2054 compat_int_t line;
2055 compat_uint_t port;
2056 compat_int_t irq;
2057 compat_int_t flags;
2058 compat_int_t xmit_fifo_size;
2059 compat_int_t custom_divisor;
2060 compat_int_t baud_base;
2061 unsigned short close_delay;
2062 char io_type;
2063 char reserved_char[1];
2064 compat_int_t hub6;
2065 unsigned short closing_wait; /* time to wait before closing */
2066 unsigned short closing_wait2; /* no longer used... */
2067 compat_uint_t iomem_base;
2068 unsigned short iomem_reg_shift;
2069 unsigned int port_high;
2070 /* compat_ulong_t iomap_base FIXME */
2071 compat_int_t reserved[1];
2072};
2073
2074static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2075{
2076 typedef struct serial_struct SS;
2077 typedef struct serial_struct32 SS32;
2078 struct serial_struct32 __user *ss32 = compat_ptr(arg);
2079 int err;
2080 struct serial_struct ss;
2081 mm_segment_t oldseg = get_fs();
2082 __u32 udata;
Heiko Carstens7116e992006-12-06 20:36:36 -08002083 unsigned int base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 if (cmd == TIOCSSERIAL) {
2086 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
2087 return -EFAULT;
2088 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
2089 return -EFAULT;
Heiko Carstens7116e992006-12-06 20:36:36 -08002090 if (__get_user(udata, &ss32->iomem_base))
2091 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 ss.iomem_base = compat_ptr(udata);
Heiko Carstens7116e992006-12-06 20:36:36 -08002093 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2094 __get_user(ss.port_high, &ss32->port_high))
2095 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 ss.iomap_base = 0UL;
2097 }
2098 set_fs(KERNEL_DS);
2099 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
2100 set_fs(oldseg);
2101 if (cmd == TIOCGSERIAL && err >= 0) {
2102 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
2103 return -EFAULT;
2104 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
2105 return -EFAULT;
Heiko Carstens7116e992006-12-06 20:36:36 -08002106 base = (unsigned long)ss.iomem_base >> 32 ?
2107 0xffffffff : (unsigned)(unsigned long)ss.iomem_base;
2108 if (__put_user(base, &ss32->iomem_base) ||
2109 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
2110 __put_user(ss.port_high, &ss32->port_high))
2111 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 }
2113 return err;
2114}
2115
2116struct usbdevfs_ctrltransfer32 {
2117 u8 bRequestType;
2118 u8 bRequest;
2119 u16 wValue;
2120 u16 wIndex;
2121 u16 wLength;
2122 u32 timeout; /* in milliseconds */
2123 compat_caddr_t data;
2124};
2125
2126#define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
2127
2128static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
2129{
2130 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
2131 struct usbdevfs_ctrltransfer __user *p;
2132 __u32 udata;
2133 p = compat_alloc_user_space(sizeof(*p));
2134 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
2135 get_user(udata, &p32->data) ||
2136 put_user(compat_ptr(udata), &p->data))
2137 return -EFAULT;
2138 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
2139}
2140
2141
2142struct usbdevfs_bulktransfer32 {
2143 compat_uint_t ep;
2144 compat_uint_t len;
2145 compat_uint_t timeout; /* in milliseconds */
2146 compat_caddr_t data;
2147};
2148
2149#define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
2150
2151static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
2152{
2153 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
2154 struct usbdevfs_bulktransfer __user *p;
2155 compat_uint_t n;
2156 compat_caddr_t addr;
2157
2158 p = compat_alloc_user_space(sizeof(*p));
2159
2160 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
2161 get_user(n, &p32->len) || put_user(n, &p->len) ||
2162 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
2163 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
2164 return -EFAULT;
2165
2166 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
2167}
2168
2169
2170/*
2171 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
2172 * are handled in usbdevfs core. -Christopher Li
2173 */
2174
2175struct usbdevfs_disconnectsignal32 {
2176 compat_int_t signr;
2177 compat_caddr_t context;
2178};
2179
2180#define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
2181
2182static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
2183{
2184 struct usbdevfs_disconnectsignal kdis;
2185 struct usbdevfs_disconnectsignal32 __user *udis;
2186 mm_segment_t old_fs;
2187 u32 uctx;
2188 int err;
2189
2190 udis = compat_ptr(arg);
2191
2192 if (get_user(kdis.signr, &udis->signr) ||
2193 __get_user(uctx, &udis->context))
2194 return -EFAULT;
2195
2196 kdis.context = compat_ptr(uctx);
2197
2198 old_fs = get_fs();
2199 set_fs(KERNEL_DS);
2200 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
2201 set_fs(old_fs);
2202
2203 return err;
2204}
2205
2206/*
2207 * I2C layer ioctls
2208 */
2209
2210struct i2c_msg32 {
2211 u16 addr;
2212 u16 flags;
2213 u16 len;
2214 compat_caddr_t buf;
2215};
2216
2217struct i2c_rdwr_ioctl_data32 {
2218 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
2219 u32 nmsgs;
2220};
2221
2222struct i2c_smbus_ioctl_data32 {
2223 u8 read_write;
2224 u8 command;
2225 u32 size;
2226 compat_caddr_t data; /* union i2c_smbus_data *data */
2227};
2228
2229struct i2c_rdwr_aligned {
2230 struct i2c_rdwr_ioctl_data cmd;
2231 struct i2c_msg msgs[0];
2232};
2233
2234static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2235{
2236 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
2237 struct i2c_rdwr_aligned __user *tdata;
2238 struct i2c_msg __user *tmsgs;
2239 struct i2c_msg32 __user *umsgs;
2240 compat_caddr_t datap;
2241 int nmsgs, i;
2242
2243 if (get_user(nmsgs, &udata->nmsgs))
2244 return -EFAULT;
2245 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
2246 return -EINVAL;
2247
2248 if (get_user(datap, &udata->msgs))
2249 return -EFAULT;
2250 umsgs = compat_ptr(datap);
2251
2252 tdata = compat_alloc_user_space(sizeof(*tdata) +
2253 nmsgs * sizeof(struct i2c_msg));
2254 tmsgs = &tdata->msgs[0];
2255
2256 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
2257 put_user(tmsgs, &tdata->cmd.msgs))
2258 return -EFAULT;
2259
2260 for (i = 0; i < nmsgs; i++) {
2261 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
2262 return -EFAULT;
2263 if (get_user(datap, &umsgs[i].buf) ||
2264 put_user(compat_ptr(datap), &tmsgs[i].buf))
2265 return -EFAULT;
2266 }
2267 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2268}
2269
2270static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2271{
2272 struct i2c_smbus_ioctl_data __user *tdata;
2273 struct i2c_smbus_ioctl_data32 __user *udata;
2274 compat_caddr_t datap;
2275
2276 tdata = compat_alloc_user_space(sizeof(*tdata));
2277 if (tdata == NULL)
2278 return -ENOMEM;
2279 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
2280 return -EFAULT;
2281
2282 udata = compat_ptr(arg);
2283 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
2284 return -EFAULT;
2285
2286 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
2287 return -EFAULT;
2288 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
2289 return -EFAULT;
2290 if (__get_user(datap, &udata->data) ||
2291 __put_user(compat_ptr(datap), &tdata->data))
2292 return -EFAULT;
2293
2294 return sys_ioctl(fd, cmd, (unsigned long)tdata);
2295}
2296
2297struct compat_iw_point {
2298 compat_caddr_t pointer;
2299 __u16 length;
2300 __u16 flags;
2301};
2302
2303static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2304{
2305 struct iwreq __user *iwr;
2306 struct iwreq __user *iwr_u;
2307 struct iw_point __user *iwp;
2308 struct compat_iw_point __user *iwp_u;
2309 compat_caddr_t pointer;
2310 __u16 length, flags;
2311
2312 iwr_u = compat_ptr(arg);
2313 iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
2314 iwr = compat_alloc_user_space(sizeof(*iwr));
2315 if (iwr == NULL)
2316 return -ENOMEM;
2317
2318 iwp = &iwr->u.data;
2319
2320 if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
2321 return -EFAULT;
2322
2323 if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
2324 &iwr_u->ifr_ifrn.ifrn_name[0],
2325 sizeof(iwr->ifr_ifrn.ifrn_name)))
2326 return -EFAULT;
2327
2328 if (__get_user(pointer, &iwp_u->pointer) ||
2329 __get_user(length, &iwp_u->length) ||
2330 __get_user(flags, &iwp_u->flags))
2331 return -EFAULT;
2332
2333 if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
2334 __put_user(length, &iwp->length) ||
2335 __put_user(flags, &iwp->flags))
2336 return -EFAULT;
2337
2338 return sys_ioctl(fd, cmd, (unsigned long) iwr);
2339}
2340
2341/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
2342 * for some operations; this forces use of the newer bridge-utils that
2343 * use compatiable ioctls
2344 */
2345static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
2346{
2347 u32 tmp;
2348
2349 if (get_user(tmp, (u32 __user *) arg))
2350 return -EFAULT;
2351 if (tmp == BRCTL_GET_VERSION)
2352 return BRCTL_VERSION + 1;
2353 return -EINVAL;
2354}
2355
Christoph Hellwigec3cad92006-01-09 20:52:11 -08002356#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
2357#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
2358#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
2359#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
2360
2361static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
2362{
2363 mm_segment_t oldfs = get_fs();
2364 compat_ulong_t val32;
2365 unsigned long kval;
2366 int ret;
2367
2368 switch (cmd) {
2369 case RTC_IRQP_READ32:
2370 case RTC_EPOCH_READ32:
2371 set_fs(KERNEL_DS);
2372 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
2373 RTC_IRQP_READ : RTC_EPOCH_READ,
2374 (unsigned long)&kval);
2375 set_fs(oldfs);
2376 if (ret)
2377 return ret;
2378 val32 = kval;
2379 return put_user(val32, (unsigned int __user *)arg);
2380 case RTC_IRQP_SET32:
Andi Kleenfc5870f2006-02-26 04:18:55 +01002381 return sys_ioctl(fd, RTC_IRQP_SET, arg);
Christoph Hellwigec3cad92006-01-09 20:52:11 -08002382 case RTC_EPOCH_SET32:
Andi Kleenfc5870f2006-02-26 04:18:55 +01002383 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
Christoph Hellwigec3cad92006-01-09 20:52:11 -08002384 default:
2385 /* unreached */
2386 return -ENOIOCTLCMD;
2387 }
2388}
2389
Andi Kleenc6b44d12006-01-12 01:05:26 -08002390static int
2391lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
2392{
Al Viro6b2b4e52006-02-01 06:33:33 -05002393 struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
2394 struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
Andi Kleenc6b44d12006-01-12 01:05:26 -08002395 struct timeval ts;
2396 if (get_user(ts.tv_sec, &tc->tv_sec) ||
2397 get_user(ts.tv_usec, &tc->tv_usec) ||
2398 put_user(ts.tv_sec, &tn->tv_sec) ||
2399 put_user(ts.tv_usec, &tn->tv_usec))
2400 return -EFAULT;
2401 return sys_ioctl(fd, cmd, (unsigned long)tn);
2402}
2403
Christoph Hellwig6272e262007-05-08 00:29:21 -07002404
2405typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int,
2406 unsigned long, struct file *);
2407
2408struct ioctl_trans {
2409 unsigned long cmd;
2410 ioctl_trans_handler_t handler;
2411 struct ioctl_trans *next;
2412};
2413
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08002414#define HANDLE_IOCTL(cmd,handler) \
2415 { (cmd), (ioctl_trans_handler_t)(handler) },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08002417/* pointer to compatible structure or no argument */
2418#define COMPATIBLE_IOCTL(cmd) \
2419 { (cmd), do_ioctl32_pointer },
2420
2421/* argument is an unsigned long integer, not a pointer */
2422#define ULONG_IOCTL(cmd) \
2423 { (cmd), (ioctl_trans_handler_t)sys_ioctl },
2424
Andi Kleen421f0282007-05-02 19:27:20 +02002425/* ioctl should not be warned about even if it's not implemented.
2426 Valid reasons to use this:
2427 - It is implemented with ->compat_ioctl on some device, but programs
2428 call it on others too.
2429 - The ioctl is not implemented in the native kernel, but programs
2430 call it commonly anyways.
2431 Most other reasons are not valid. */
2432#define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08002433
Christoph Hellwig6272e262007-05-08 00:29:21 -07002434static struct ioctl_trans ioctl_start[] = {
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002435/* compatible ioctls first */
2436COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */
2437COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */
2438
2439/* Big T */
2440COMPATIBLE_IOCTL(TCGETA)
2441COMPATIBLE_IOCTL(TCSETA)
2442COMPATIBLE_IOCTL(TCSETAW)
2443COMPATIBLE_IOCTL(TCSETAF)
2444COMPATIBLE_IOCTL(TCSBRK)
2445ULONG_IOCTL(TCSBRKP)
2446COMPATIBLE_IOCTL(TCXONC)
2447COMPATIBLE_IOCTL(TCFLSH)
2448COMPATIBLE_IOCTL(TCGETS)
2449COMPATIBLE_IOCTL(TCSETS)
2450COMPATIBLE_IOCTL(TCSETSW)
2451COMPATIBLE_IOCTL(TCSETSF)
2452COMPATIBLE_IOCTL(TIOCLINUX)
2453COMPATIBLE_IOCTL(TIOCSBRK)
2454COMPATIBLE_IOCTL(TIOCCBRK)
2455ULONG_IOCTL(TIOCMIWAIT)
2456COMPATIBLE_IOCTL(TIOCGICOUNT)
2457/* Little t */
2458COMPATIBLE_IOCTL(TIOCGETD)
2459COMPATIBLE_IOCTL(TIOCSETD)
2460COMPATIBLE_IOCTL(TIOCEXCL)
2461COMPATIBLE_IOCTL(TIOCNXCL)
2462COMPATIBLE_IOCTL(TIOCCONS)
2463COMPATIBLE_IOCTL(TIOCGSOFTCAR)
2464COMPATIBLE_IOCTL(TIOCSSOFTCAR)
2465COMPATIBLE_IOCTL(TIOCSWINSZ)
2466COMPATIBLE_IOCTL(TIOCGWINSZ)
2467COMPATIBLE_IOCTL(TIOCMGET)
2468COMPATIBLE_IOCTL(TIOCMBIC)
2469COMPATIBLE_IOCTL(TIOCMBIS)
2470COMPATIBLE_IOCTL(TIOCMSET)
2471COMPATIBLE_IOCTL(TIOCPKT)
2472COMPATIBLE_IOCTL(TIOCNOTTY)
2473COMPATIBLE_IOCTL(TIOCSTI)
2474COMPATIBLE_IOCTL(TIOCOUTQ)
2475COMPATIBLE_IOCTL(TIOCSPGRP)
2476COMPATIBLE_IOCTL(TIOCGPGRP)
2477ULONG_IOCTL(TIOCSCTTY)
2478COMPATIBLE_IOCTL(TIOCGPTN)
2479COMPATIBLE_IOCTL(TIOCSPTLCK)
2480COMPATIBLE_IOCTL(TIOCSERGETLSR)
2481/* Little f */
2482COMPATIBLE_IOCTL(FIOCLEX)
2483COMPATIBLE_IOCTL(FIONCLEX)
2484COMPATIBLE_IOCTL(FIOASYNC)
2485COMPATIBLE_IOCTL(FIONBIO)
2486COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */
2487/* 0x00 */
2488COMPATIBLE_IOCTL(FIBMAP)
2489COMPATIBLE_IOCTL(FIGETBSZ)
2490/* 0x03 -- HD/IDE ioctl's used by hdparm and friends.
2491 * Some need translations, these do not.
2492 */
2493COMPATIBLE_IOCTL(HDIO_GET_IDENTITY)
2494COMPATIBLE_IOCTL(HDIO_DRIVE_TASK)
2495COMPATIBLE_IOCTL(HDIO_DRIVE_CMD)
2496ULONG_IOCTL(HDIO_SET_MULTCOUNT)
2497ULONG_IOCTL(HDIO_SET_UNMASKINTR)
2498ULONG_IOCTL(HDIO_SET_KEEPSETTINGS)
2499ULONG_IOCTL(HDIO_SET_32BIT)
2500ULONG_IOCTL(HDIO_SET_NOWERR)
2501ULONG_IOCTL(HDIO_SET_DMA)
2502ULONG_IOCTL(HDIO_SET_PIO_MODE)
2503ULONG_IOCTL(HDIO_SET_NICE)
2504ULONG_IOCTL(HDIO_SET_WCACHE)
2505ULONG_IOCTL(HDIO_SET_ACOUSTIC)
2506ULONG_IOCTL(HDIO_SET_BUSSTATE)
2507ULONG_IOCTL(HDIO_SET_ADDRESS)
2508COMPATIBLE_IOCTL(HDIO_SCAN_HWIF)
2509/* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */
2510COMPATIBLE_IOCTL(0x330)
2511/* 0x02 -- Floppy ioctls */
2512COMPATIBLE_IOCTL(FDMSGON)
2513COMPATIBLE_IOCTL(FDMSGOFF)
2514COMPATIBLE_IOCTL(FDSETEMSGTRESH)
2515COMPATIBLE_IOCTL(FDFLUSH)
2516COMPATIBLE_IOCTL(FDWERRORCLR)
2517COMPATIBLE_IOCTL(FDSETMAXERRS)
2518COMPATIBLE_IOCTL(FDGETMAXERRS)
2519COMPATIBLE_IOCTL(FDGETDRVTYP)
2520COMPATIBLE_IOCTL(FDEJECT)
2521COMPATIBLE_IOCTL(FDCLRPRM)
2522COMPATIBLE_IOCTL(FDFMTBEG)
2523COMPATIBLE_IOCTL(FDFMTEND)
2524COMPATIBLE_IOCTL(FDRESET)
2525COMPATIBLE_IOCTL(FDTWADDLE)
2526COMPATIBLE_IOCTL(FDFMTTRK)
2527COMPATIBLE_IOCTL(FDRAWCMD)
2528/* 0x12 */
2529#ifdef CONFIG_BLOCK
2530COMPATIBLE_IOCTL(BLKRASET)
2531COMPATIBLE_IOCTL(BLKROSET)
2532COMPATIBLE_IOCTL(BLKROGET)
2533COMPATIBLE_IOCTL(BLKRRPART)
2534COMPATIBLE_IOCTL(BLKFLSBUF)
2535COMPATIBLE_IOCTL(BLKSECTSET)
2536COMPATIBLE_IOCTL(BLKSSZGET)
2537COMPATIBLE_IOCTL(BLKTRACESTART)
2538COMPATIBLE_IOCTL(BLKTRACESTOP)
2539COMPATIBLE_IOCTL(BLKTRACESETUP)
2540COMPATIBLE_IOCTL(BLKTRACETEARDOWN)
2541ULONG_IOCTL(BLKRASET)
2542ULONG_IOCTL(BLKFRASET)
2543#endif
2544/* RAID */
2545COMPATIBLE_IOCTL(RAID_VERSION)
2546COMPATIBLE_IOCTL(GET_ARRAY_INFO)
2547COMPATIBLE_IOCTL(GET_DISK_INFO)
2548COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
2549COMPATIBLE_IOCTL(RAID_AUTORUN)
2550COMPATIBLE_IOCTL(CLEAR_ARRAY)
2551COMPATIBLE_IOCTL(ADD_NEW_DISK)
2552ULONG_IOCTL(HOT_REMOVE_DISK)
2553COMPATIBLE_IOCTL(SET_ARRAY_INFO)
2554COMPATIBLE_IOCTL(SET_DISK_INFO)
2555COMPATIBLE_IOCTL(WRITE_RAID_INFO)
2556COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
2557COMPATIBLE_IOCTL(PROTECT_ARRAY)
2558ULONG_IOCTL(HOT_ADD_DISK)
2559ULONG_IOCTL(SET_DISK_FAULTY)
2560COMPATIBLE_IOCTL(RUN_ARRAY)
2561COMPATIBLE_IOCTL(STOP_ARRAY)
2562COMPATIBLE_IOCTL(STOP_ARRAY_RO)
2563COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
2564COMPATIBLE_IOCTL(GET_BITMAP_FILE)
2565ULONG_IOCTL(SET_BITMAP_FILE)
2566/* DM */
2567COMPATIBLE_IOCTL(DM_VERSION_32)
2568COMPATIBLE_IOCTL(DM_REMOVE_ALL_32)
2569COMPATIBLE_IOCTL(DM_LIST_DEVICES_32)
2570COMPATIBLE_IOCTL(DM_DEV_CREATE_32)
2571COMPATIBLE_IOCTL(DM_DEV_REMOVE_32)
2572COMPATIBLE_IOCTL(DM_DEV_RENAME_32)
2573COMPATIBLE_IOCTL(DM_DEV_SUSPEND_32)
2574COMPATIBLE_IOCTL(DM_DEV_STATUS_32)
2575COMPATIBLE_IOCTL(DM_DEV_WAIT_32)
2576COMPATIBLE_IOCTL(DM_TABLE_LOAD_32)
2577COMPATIBLE_IOCTL(DM_TABLE_CLEAR_32)
2578COMPATIBLE_IOCTL(DM_TABLE_DEPS_32)
2579COMPATIBLE_IOCTL(DM_TABLE_STATUS_32)
2580COMPATIBLE_IOCTL(DM_LIST_VERSIONS_32)
2581COMPATIBLE_IOCTL(DM_TARGET_MSG_32)
2582COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY_32)
2583COMPATIBLE_IOCTL(DM_VERSION)
2584COMPATIBLE_IOCTL(DM_REMOVE_ALL)
2585COMPATIBLE_IOCTL(DM_LIST_DEVICES)
2586COMPATIBLE_IOCTL(DM_DEV_CREATE)
2587COMPATIBLE_IOCTL(DM_DEV_REMOVE)
2588COMPATIBLE_IOCTL(DM_DEV_RENAME)
2589COMPATIBLE_IOCTL(DM_DEV_SUSPEND)
2590COMPATIBLE_IOCTL(DM_DEV_STATUS)
2591COMPATIBLE_IOCTL(DM_DEV_WAIT)
2592COMPATIBLE_IOCTL(DM_TABLE_LOAD)
2593COMPATIBLE_IOCTL(DM_TABLE_CLEAR)
2594COMPATIBLE_IOCTL(DM_TABLE_DEPS)
2595COMPATIBLE_IOCTL(DM_TABLE_STATUS)
2596COMPATIBLE_IOCTL(DM_LIST_VERSIONS)
2597COMPATIBLE_IOCTL(DM_TARGET_MSG)
2598COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY)
2599/* Big K */
2600COMPATIBLE_IOCTL(PIO_FONT)
2601COMPATIBLE_IOCTL(GIO_FONT)
2602ULONG_IOCTL(KDSIGACCEPT)
2603COMPATIBLE_IOCTL(KDGETKEYCODE)
2604COMPATIBLE_IOCTL(KDSETKEYCODE)
2605ULONG_IOCTL(KIOCSOUND)
2606ULONG_IOCTL(KDMKTONE)
2607COMPATIBLE_IOCTL(KDGKBTYPE)
2608ULONG_IOCTL(KDSETMODE)
2609COMPATIBLE_IOCTL(KDGETMODE)
2610ULONG_IOCTL(KDSKBMODE)
2611COMPATIBLE_IOCTL(KDGKBMODE)
2612ULONG_IOCTL(KDSKBMETA)
2613COMPATIBLE_IOCTL(KDGKBMETA)
2614COMPATIBLE_IOCTL(KDGKBENT)
2615COMPATIBLE_IOCTL(KDSKBENT)
2616COMPATIBLE_IOCTL(KDGKBSENT)
2617COMPATIBLE_IOCTL(KDSKBSENT)
2618COMPATIBLE_IOCTL(KDGKBDIACR)
2619COMPATIBLE_IOCTL(KDSKBDIACR)
2620COMPATIBLE_IOCTL(KDKBDREP)
2621COMPATIBLE_IOCTL(KDGKBLED)
2622ULONG_IOCTL(KDSKBLED)
2623COMPATIBLE_IOCTL(KDGETLED)
2624ULONG_IOCTL(KDSETLED)
2625COMPATIBLE_IOCTL(GIO_SCRNMAP)
2626COMPATIBLE_IOCTL(PIO_SCRNMAP)
2627COMPATIBLE_IOCTL(GIO_UNISCRNMAP)
2628COMPATIBLE_IOCTL(PIO_UNISCRNMAP)
2629COMPATIBLE_IOCTL(PIO_FONTRESET)
2630COMPATIBLE_IOCTL(PIO_UNIMAPCLR)
2631/* Big S */
2632COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
2633COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
2634COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
2635COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
2636COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
2637COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
2638COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
2639COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
2640/* Big T */
2641COMPATIBLE_IOCTL(TUNSETNOCSUM)
2642COMPATIBLE_IOCTL(TUNSETDEBUG)
2643COMPATIBLE_IOCTL(TUNSETPERSIST)
2644COMPATIBLE_IOCTL(TUNSETOWNER)
2645/* Big V */
2646COMPATIBLE_IOCTL(VT_SETMODE)
2647COMPATIBLE_IOCTL(VT_GETMODE)
2648COMPATIBLE_IOCTL(VT_GETSTATE)
2649COMPATIBLE_IOCTL(VT_OPENQRY)
2650ULONG_IOCTL(VT_ACTIVATE)
2651ULONG_IOCTL(VT_WAITACTIVE)
2652ULONG_IOCTL(VT_RELDISP)
2653ULONG_IOCTL(VT_DISALLOCATE)
2654COMPATIBLE_IOCTL(VT_RESIZE)
2655COMPATIBLE_IOCTL(VT_RESIZEX)
2656COMPATIBLE_IOCTL(VT_LOCKSWITCH)
2657COMPATIBLE_IOCTL(VT_UNLOCKSWITCH)
2658COMPATIBLE_IOCTL(VT_GETHIFONTMASK)
2659/* Little p (/dev/rtc, /dev/envctrl, etc.) */
2660COMPATIBLE_IOCTL(RTC_AIE_ON)
2661COMPATIBLE_IOCTL(RTC_AIE_OFF)
2662COMPATIBLE_IOCTL(RTC_UIE_ON)
2663COMPATIBLE_IOCTL(RTC_UIE_OFF)
2664COMPATIBLE_IOCTL(RTC_PIE_ON)
2665COMPATIBLE_IOCTL(RTC_PIE_OFF)
2666COMPATIBLE_IOCTL(RTC_WIE_ON)
2667COMPATIBLE_IOCTL(RTC_WIE_OFF)
2668COMPATIBLE_IOCTL(RTC_ALM_SET)
2669COMPATIBLE_IOCTL(RTC_ALM_READ)
2670COMPATIBLE_IOCTL(RTC_RD_TIME)
2671COMPATIBLE_IOCTL(RTC_SET_TIME)
2672COMPATIBLE_IOCTL(RTC_WKALM_SET)
2673COMPATIBLE_IOCTL(RTC_WKALM_RD)
2674/*
2675 * These two are only for the sbus rtc driver, but
2676 * hwclock tries them on every rtc device first when
2677 * running on sparc. On other architectures the entries
2678 * are useless but harmless.
2679 */
2680COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
2681COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
2682/* Little m */
2683COMPATIBLE_IOCTL(MTIOCTOP)
2684/* Socket level stuff */
2685COMPATIBLE_IOCTL(FIOQSIZE)
2686COMPATIBLE_IOCTL(FIOSETOWN)
2687COMPATIBLE_IOCTL(SIOCSPGRP)
2688COMPATIBLE_IOCTL(FIOGETOWN)
2689COMPATIBLE_IOCTL(SIOCGPGRP)
2690COMPATIBLE_IOCTL(SIOCATMARK)
2691COMPATIBLE_IOCTL(SIOCSIFLINK)
2692COMPATIBLE_IOCTL(SIOCSIFENCAP)
2693COMPATIBLE_IOCTL(SIOCGIFENCAP)
2694COMPATIBLE_IOCTL(SIOCSIFNAME)
2695COMPATIBLE_IOCTL(SIOCSARP)
2696COMPATIBLE_IOCTL(SIOCGARP)
2697COMPATIBLE_IOCTL(SIOCDARP)
2698COMPATIBLE_IOCTL(SIOCSRARP)
2699COMPATIBLE_IOCTL(SIOCGRARP)
2700COMPATIBLE_IOCTL(SIOCDRARP)
2701COMPATIBLE_IOCTL(SIOCADDDLCI)
2702COMPATIBLE_IOCTL(SIOCDELDLCI)
2703COMPATIBLE_IOCTL(SIOCGMIIPHY)
2704COMPATIBLE_IOCTL(SIOCGMIIREG)
2705COMPATIBLE_IOCTL(SIOCSMIIREG)
2706COMPATIBLE_IOCTL(SIOCGIFVLAN)
2707COMPATIBLE_IOCTL(SIOCSIFVLAN)
2708COMPATIBLE_IOCTL(SIOCBRADDBR)
2709COMPATIBLE_IOCTL(SIOCBRDELBR)
2710/* SG stuff */
2711COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
2712COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
2713COMPATIBLE_IOCTL(SG_EMULATED_HOST)
2714ULONG_IOCTL(SG_SET_TRANSFORM)
2715COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
2716COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
2717COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
2718COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
2719COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
2720COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
2721COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
2722COMPATIBLE_IOCTL(SG_GET_PACK_ID)
2723COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
2724COMPATIBLE_IOCTL(SG_SET_DEBUG)
2725COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
2726COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
2727COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
2728COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
2729COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
2730COMPATIBLE_IOCTL(SG_SCSI_RESET)
2731COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
2732COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
2733COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
2734/* PPP stuff */
2735COMPATIBLE_IOCTL(PPPIOCGFLAGS)
2736COMPATIBLE_IOCTL(PPPIOCSFLAGS)
2737COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
2738COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
2739COMPATIBLE_IOCTL(PPPIOCGUNIT)
2740COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
2741COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
2742COMPATIBLE_IOCTL(PPPIOCGMRU)
2743COMPATIBLE_IOCTL(PPPIOCSMRU)
2744COMPATIBLE_IOCTL(PPPIOCSMAXCID)
2745COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
2746COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
2747COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
2748/* PPPIOCSCOMPRESS is translated */
2749COMPATIBLE_IOCTL(PPPIOCGNPMODE)
2750COMPATIBLE_IOCTL(PPPIOCSNPMODE)
2751COMPATIBLE_IOCTL(PPPIOCGDEBUG)
2752COMPATIBLE_IOCTL(PPPIOCSDEBUG)
2753/* PPPIOCSPASS is translated */
2754/* PPPIOCSACTIVE is translated */
2755/* PPPIOCGIDLE is translated */
2756COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
2757COMPATIBLE_IOCTL(PPPIOCATTACH)
2758COMPATIBLE_IOCTL(PPPIOCDETACH)
2759COMPATIBLE_IOCTL(PPPIOCSMRRU)
2760COMPATIBLE_IOCTL(PPPIOCCONNECT)
2761COMPATIBLE_IOCTL(PPPIOCDISCONN)
2762COMPATIBLE_IOCTL(PPPIOCATTCHAN)
2763COMPATIBLE_IOCTL(PPPIOCGCHAN)
2764/* PPPOX */
2765COMPATIBLE_IOCTL(PPPOEIOCSFWD)
2766COMPATIBLE_IOCTL(PPPOEIOCDFWD)
2767/* LP */
2768COMPATIBLE_IOCTL(LPGETSTATUS)
2769/* ppdev */
2770COMPATIBLE_IOCTL(PPSETMODE)
2771COMPATIBLE_IOCTL(PPRSTATUS)
2772COMPATIBLE_IOCTL(PPRCONTROL)
2773COMPATIBLE_IOCTL(PPWCONTROL)
2774COMPATIBLE_IOCTL(PPFCONTROL)
2775COMPATIBLE_IOCTL(PPRDATA)
2776COMPATIBLE_IOCTL(PPWDATA)
2777COMPATIBLE_IOCTL(PPCLAIM)
2778COMPATIBLE_IOCTL(PPRELEASE)
2779COMPATIBLE_IOCTL(PPYIELD)
2780COMPATIBLE_IOCTL(PPEXCL)
2781COMPATIBLE_IOCTL(PPDATADIR)
2782COMPATIBLE_IOCTL(PPNEGOT)
2783COMPATIBLE_IOCTL(PPWCTLONIRQ)
2784COMPATIBLE_IOCTL(PPCLRIRQ)
2785COMPATIBLE_IOCTL(PPSETPHASE)
2786COMPATIBLE_IOCTL(PPGETMODES)
2787COMPATIBLE_IOCTL(PPGETMODE)
2788COMPATIBLE_IOCTL(PPGETPHASE)
2789COMPATIBLE_IOCTL(PPGETFLAGS)
2790COMPATIBLE_IOCTL(PPSETFLAGS)
2791/* CDROM stuff */
2792COMPATIBLE_IOCTL(CDROMPAUSE)
2793COMPATIBLE_IOCTL(CDROMRESUME)
2794COMPATIBLE_IOCTL(CDROMPLAYMSF)
2795COMPATIBLE_IOCTL(CDROMPLAYTRKIND)
2796COMPATIBLE_IOCTL(CDROMREADTOCHDR)
2797COMPATIBLE_IOCTL(CDROMREADTOCENTRY)
2798COMPATIBLE_IOCTL(CDROMSTOP)
2799COMPATIBLE_IOCTL(CDROMSTART)
2800COMPATIBLE_IOCTL(CDROMEJECT)
2801COMPATIBLE_IOCTL(CDROMVOLCTRL)
2802COMPATIBLE_IOCTL(CDROMSUBCHNL)
2803ULONG_IOCTL(CDROMEJECT_SW)
2804COMPATIBLE_IOCTL(CDROMMULTISESSION)
2805COMPATIBLE_IOCTL(CDROM_GET_MCN)
2806COMPATIBLE_IOCTL(CDROMRESET)
2807COMPATIBLE_IOCTL(CDROMVOLREAD)
2808COMPATIBLE_IOCTL(CDROMSEEK)
2809COMPATIBLE_IOCTL(CDROMPLAYBLK)
2810COMPATIBLE_IOCTL(CDROMCLOSETRAY)
2811ULONG_IOCTL(CDROM_SET_OPTIONS)
2812ULONG_IOCTL(CDROM_CLEAR_OPTIONS)
2813ULONG_IOCTL(CDROM_SELECT_SPEED)
2814ULONG_IOCTL(CDROM_SELECT_DISC)
2815ULONG_IOCTL(CDROM_MEDIA_CHANGED)
2816ULONG_IOCTL(CDROM_DRIVE_STATUS)
2817COMPATIBLE_IOCTL(CDROM_DISC_STATUS)
2818COMPATIBLE_IOCTL(CDROM_CHANGER_NSLOTS)
2819ULONG_IOCTL(CDROM_LOCKDOOR)
2820ULONG_IOCTL(CDROM_DEBUG)
2821COMPATIBLE_IOCTL(CDROM_GET_CAPABILITY)
2822/* Ignore cdrom.h about these next 5 ioctls, they absolutely do
2823 * not take a struct cdrom_read, instead they take a struct cdrom_msf
2824 * which is compatible.
2825 */
2826COMPATIBLE_IOCTL(CDROMREADMODE2)
2827COMPATIBLE_IOCTL(CDROMREADMODE1)
2828COMPATIBLE_IOCTL(CDROMREADRAW)
2829COMPATIBLE_IOCTL(CDROMREADCOOKED)
2830COMPATIBLE_IOCTL(CDROMREADALL)
2831/* DVD ioctls */
2832COMPATIBLE_IOCTL(DVD_READ_STRUCT)
2833COMPATIBLE_IOCTL(DVD_WRITE_STRUCT)
2834COMPATIBLE_IOCTL(DVD_AUTH)
2835/* pktcdvd */
2836COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
2837/* Big A */
2838/* sparc only */
2839/* Big Q for sound/OSS */
2840COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
2841COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
2842COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
2843COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
2844COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
2845COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
2846COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
2847COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
2848COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
2849COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
2850COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
2851COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
2852COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
2853COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
2854COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
2855COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
2856COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
2857COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
2858COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
2859COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
2860COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
2861COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
2862/* Big T for sound/OSS */
2863COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
2864COMPATIBLE_IOCTL(SNDCTL_TMR_START)
2865COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
2866COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
2867COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
2868COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
2869COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
2870COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
2871/* Little m for sound/OSS */
2872COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
2873COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
2874COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
2875/* Big P for sound/OSS */
2876COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
2877COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
2878COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
2879COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
2880COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
2881COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
2882COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
2883COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
2884COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
2885COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
2886COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
2887COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
2888COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
2889COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
2890COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
2891COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
2892COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
2893COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
2894COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
2895COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
2896/* SNDCTL_DSP_MAPINBUF, XXX needs translation */
2897/* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */
2898COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
2899COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
2900COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
2901COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
2902COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
2903COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
2904COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
2905COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
2906/* Big C for sound/OSS */
2907COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
2908COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
2909COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
2910COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
2911COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
2912COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
2913COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
2914COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
2915COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
2916COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
2917/* Big M for sound/OSS */
2918COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
2919COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
2920COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
2921COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
2922COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
2923COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
2924COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
2925COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
2926COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
2927COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
2928COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
2929COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
2930COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
2931COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
2932COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
2933COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
2934COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
2935COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
2936COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
2937COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
2938COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
2939COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
2940COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
2941COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
2942COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
2943COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
2944/* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */
2945/* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */
2946COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
2947COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
2948COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
2949COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
2950COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
2951COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
2952COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
2953COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
2954COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
2955COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
2956COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
2957COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
2958COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
2959COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
2960COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
2961COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
2962COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
2963COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
2964COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
2965COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
2966COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
2967COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
2968COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
2969COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
2970COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
2971COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
2972COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
2973COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
2974COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
2975COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
2976COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
2977/* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */
2978/* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */
2979COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
2980COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
2981COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
2982COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
2983COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
2984COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
2985COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
2986COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
2987COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
2988COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
2989COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
2990COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
2991COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
2992COMPATIBLE_IOCTL(OSS_GETVERSION)
2993/* AUTOFS */
2994ULONG_IOCTL(AUTOFS_IOC_READY)
2995ULONG_IOCTL(AUTOFS_IOC_FAIL)
2996COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
2997COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
2998COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
2999COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
3000COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
3001COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
3002COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
3003COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
3004/* Raw devices */
3005COMPATIBLE_IOCTL(RAW_SETBIND)
3006COMPATIBLE_IOCTL(RAW_GETBIND)
3007/* SMB ioctls which do not need any translations */
3008COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
3009/* Little a */
3010COMPATIBLE_IOCTL(ATMSIGD_CTRL)
3011COMPATIBLE_IOCTL(ATMARPD_CTRL)
3012COMPATIBLE_IOCTL(ATMLEC_CTRL)
3013COMPATIBLE_IOCTL(ATMLEC_MCAST)
3014COMPATIBLE_IOCTL(ATMLEC_DATA)
3015COMPATIBLE_IOCTL(ATM_SETSC)
3016COMPATIBLE_IOCTL(SIOCSIFATMTCP)
3017COMPATIBLE_IOCTL(SIOCMKCLIP)
3018COMPATIBLE_IOCTL(ATMARP_MKIP)
3019COMPATIBLE_IOCTL(ATMARP_SETENTRY)
3020COMPATIBLE_IOCTL(ATMARP_ENCAP)
3021COMPATIBLE_IOCTL(ATMTCP_CREATE)
3022COMPATIBLE_IOCTL(ATMTCP_REMOVE)
3023COMPATIBLE_IOCTL(ATMMPC_CTRL)
3024COMPATIBLE_IOCTL(ATMMPC_DATA)
3025/* Watchdog */
3026COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
3027COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
3028COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
3029COMPATIBLE_IOCTL(WDIOC_GETTEMP)
3030COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
3031COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
3032COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
3033COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
3034/* Big R */
3035COMPATIBLE_IOCTL(RNDGETENTCNT)
3036COMPATIBLE_IOCTL(RNDADDTOENTCNT)
3037COMPATIBLE_IOCTL(RNDGETPOOL)
3038COMPATIBLE_IOCTL(RNDADDENTROPY)
3039COMPATIBLE_IOCTL(RNDZAPENTCNT)
3040COMPATIBLE_IOCTL(RNDCLEARPOOL)
3041/* Bluetooth */
3042COMPATIBLE_IOCTL(HCIDEVUP)
3043COMPATIBLE_IOCTL(HCIDEVDOWN)
3044COMPATIBLE_IOCTL(HCIDEVRESET)
3045COMPATIBLE_IOCTL(HCIDEVRESTAT)
3046COMPATIBLE_IOCTL(HCIGETDEVLIST)
3047COMPATIBLE_IOCTL(HCIGETDEVINFO)
3048COMPATIBLE_IOCTL(HCIGETCONNLIST)
3049COMPATIBLE_IOCTL(HCIGETCONNINFO)
3050COMPATIBLE_IOCTL(HCISETRAW)
3051COMPATIBLE_IOCTL(HCISETSCAN)
3052COMPATIBLE_IOCTL(HCISETAUTH)
3053COMPATIBLE_IOCTL(HCISETENCRYPT)
3054COMPATIBLE_IOCTL(HCISETPTYPE)
3055COMPATIBLE_IOCTL(HCISETLINKPOL)
3056COMPATIBLE_IOCTL(HCISETLINKMODE)
3057COMPATIBLE_IOCTL(HCISETACLMTU)
3058COMPATIBLE_IOCTL(HCISETSCOMTU)
3059COMPATIBLE_IOCTL(HCIINQUIRY)
3060COMPATIBLE_IOCTL(HCIUARTSETPROTO)
3061COMPATIBLE_IOCTL(HCIUARTGETPROTO)
3062COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
3063COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
3064COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
3065COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
3066COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
3067COMPATIBLE_IOCTL(BNEPCONNADD)
3068COMPATIBLE_IOCTL(BNEPCONNDEL)
3069COMPATIBLE_IOCTL(BNEPGETCONNLIST)
3070COMPATIBLE_IOCTL(BNEPGETCONNINFO)
3071COMPATIBLE_IOCTL(CMTPCONNADD)
3072COMPATIBLE_IOCTL(CMTPCONNDEL)
3073COMPATIBLE_IOCTL(CMTPGETCONNLIST)
3074COMPATIBLE_IOCTL(CMTPGETCONNINFO)
3075COMPATIBLE_IOCTL(HIDPCONNADD)
3076COMPATIBLE_IOCTL(HIDPCONNDEL)
3077COMPATIBLE_IOCTL(HIDPGETCONNLIST)
3078COMPATIBLE_IOCTL(HIDPGETCONNINFO)
3079/* CAPI */
3080COMPATIBLE_IOCTL(CAPI_REGISTER)
3081COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
3082COMPATIBLE_IOCTL(CAPI_GET_VERSION)
3083COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
3084COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
3085COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
3086COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
3087COMPATIBLE_IOCTL(CAPI_INSTALLED)
3088COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
3089COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
3090COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
3091COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
3092COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
3093/* Siemens Gigaset */
3094COMPATIBLE_IOCTL(GIGASET_REDIR)
3095COMPATIBLE_IOCTL(GIGASET_CONFIG)
3096COMPATIBLE_IOCTL(GIGASET_BRKCHARS)
3097COMPATIBLE_IOCTL(GIGASET_VERSION)
3098/* Misc. */
3099COMPATIBLE_IOCTL(0x41545900) /* ATYIO_CLKR */
3100COMPATIBLE_IOCTL(0x41545901) /* ATYIO_CLKW */
3101COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
3102COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
3103COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
3104COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
3105/* USB */
3106COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
3107COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
3108COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
3109COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
3110COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
3111COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
3112COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
3113COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
3114COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
3115COMPATIBLE_IOCTL(USBDEVFS_RESET)
3116COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
3117COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
3118COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
3119COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
3120/* MTD */
3121COMPATIBLE_IOCTL(MEMGETINFO)
3122COMPATIBLE_IOCTL(MEMERASE)
3123COMPATIBLE_IOCTL(MEMLOCK)
3124COMPATIBLE_IOCTL(MEMUNLOCK)
3125COMPATIBLE_IOCTL(MEMGETREGIONCOUNT)
3126COMPATIBLE_IOCTL(MEMGETREGIONINFO)
3127COMPATIBLE_IOCTL(MEMGETBADBLOCK)
3128COMPATIBLE_IOCTL(MEMSETBADBLOCK)
3129/* NBD */
3130ULONG_IOCTL(NBD_SET_SOCK)
3131ULONG_IOCTL(NBD_SET_BLKSIZE)
3132ULONG_IOCTL(NBD_SET_SIZE)
3133COMPATIBLE_IOCTL(NBD_DO_IT)
3134COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
3135COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
3136COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
3137ULONG_IOCTL(NBD_SET_SIZE_BLOCKS)
3138COMPATIBLE_IOCTL(NBD_DISCONNECT)
3139/* i2c */
3140COMPATIBLE_IOCTL(I2C_SLAVE)
3141COMPATIBLE_IOCTL(I2C_SLAVE_FORCE)
3142COMPATIBLE_IOCTL(I2C_TENBIT)
3143COMPATIBLE_IOCTL(I2C_PEC)
3144COMPATIBLE_IOCTL(I2C_RETRIES)
3145COMPATIBLE_IOCTL(I2C_TIMEOUT)
3146/* wireless */
3147COMPATIBLE_IOCTL(SIOCSIWCOMMIT)
3148COMPATIBLE_IOCTL(SIOCGIWNAME)
3149COMPATIBLE_IOCTL(SIOCSIWNWID)
3150COMPATIBLE_IOCTL(SIOCGIWNWID)
3151COMPATIBLE_IOCTL(SIOCSIWFREQ)
3152COMPATIBLE_IOCTL(SIOCGIWFREQ)
3153COMPATIBLE_IOCTL(SIOCSIWMODE)
3154COMPATIBLE_IOCTL(SIOCGIWMODE)
3155COMPATIBLE_IOCTL(SIOCSIWSENS)
3156COMPATIBLE_IOCTL(SIOCGIWSENS)
3157COMPATIBLE_IOCTL(SIOCSIWRANGE)
3158COMPATIBLE_IOCTL(SIOCSIWPRIV)
3159COMPATIBLE_IOCTL(SIOCGIWPRIV)
3160COMPATIBLE_IOCTL(SIOCSIWSTATS)
3161COMPATIBLE_IOCTL(SIOCGIWSTATS)
3162COMPATIBLE_IOCTL(SIOCSIWAP)
3163COMPATIBLE_IOCTL(SIOCGIWAP)
3164COMPATIBLE_IOCTL(SIOCSIWSCAN)
3165COMPATIBLE_IOCTL(SIOCSIWRATE)
3166COMPATIBLE_IOCTL(SIOCGIWRATE)
3167COMPATIBLE_IOCTL(SIOCSIWRTS)
3168COMPATIBLE_IOCTL(SIOCGIWRTS)
3169COMPATIBLE_IOCTL(SIOCSIWFRAG)
3170COMPATIBLE_IOCTL(SIOCGIWFRAG)
3171COMPATIBLE_IOCTL(SIOCSIWTXPOW)
3172COMPATIBLE_IOCTL(SIOCGIWTXPOW)
3173COMPATIBLE_IOCTL(SIOCSIWRETRY)
3174COMPATIBLE_IOCTL(SIOCGIWRETRY)
3175COMPATIBLE_IOCTL(SIOCSIWPOWER)
3176COMPATIBLE_IOCTL(SIOCGIWPOWER)
3177/* hiddev */
3178COMPATIBLE_IOCTL(HIDIOCGVERSION)
3179COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
3180COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
3181COMPATIBLE_IOCTL(HIDIOCGSTRING)
3182COMPATIBLE_IOCTL(HIDIOCINITREPORT)
3183COMPATIBLE_IOCTL(HIDIOCGREPORT)
3184COMPATIBLE_IOCTL(HIDIOCSREPORT)
3185COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
3186COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
3187COMPATIBLE_IOCTL(HIDIOCGUSAGE)
3188COMPATIBLE_IOCTL(HIDIOCSUSAGE)
3189COMPATIBLE_IOCTL(HIDIOCGUCODE)
3190COMPATIBLE_IOCTL(HIDIOCGFLAG)
3191COMPATIBLE_IOCTL(HIDIOCSFLAG)
3192COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
3193COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
3194/* dvb */
3195COMPATIBLE_IOCTL(AUDIO_STOP)
3196COMPATIBLE_IOCTL(AUDIO_PLAY)
3197COMPATIBLE_IOCTL(AUDIO_PAUSE)
3198COMPATIBLE_IOCTL(AUDIO_CONTINUE)
3199COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
3200COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
3201COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
3202COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
3203COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
3204COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
3205COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
3206COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
3207COMPATIBLE_IOCTL(AUDIO_SET_ID)
3208COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
3209COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
3210COMPATIBLE_IOCTL(AUDIO_SET_EXT_ID)
3211COMPATIBLE_IOCTL(AUDIO_SET_ATTRIBUTES)
3212COMPATIBLE_IOCTL(AUDIO_SET_KARAOKE)
3213COMPATIBLE_IOCTL(DMX_START)
3214COMPATIBLE_IOCTL(DMX_STOP)
3215COMPATIBLE_IOCTL(DMX_SET_FILTER)
3216COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
3217COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
3218COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
3219COMPATIBLE_IOCTL(DMX_GET_CAPS)
3220COMPATIBLE_IOCTL(DMX_SET_SOURCE)
3221COMPATIBLE_IOCTL(DMX_GET_STC)
3222COMPATIBLE_IOCTL(FE_GET_INFO)
3223COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
3224COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
3225COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
3226COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
3227COMPATIBLE_IOCTL(FE_SET_TONE)
3228COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
3229COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
3230COMPATIBLE_IOCTL(FE_READ_STATUS)
3231COMPATIBLE_IOCTL(FE_READ_BER)
3232COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
3233COMPATIBLE_IOCTL(FE_READ_SNR)
3234COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
3235COMPATIBLE_IOCTL(FE_SET_FRONTEND)
3236COMPATIBLE_IOCTL(FE_GET_FRONTEND)
3237COMPATIBLE_IOCTL(FE_GET_EVENT)
3238COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
3239COMPATIBLE_IOCTL(VIDEO_STOP)
3240COMPATIBLE_IOCTL(VIDEO_PLAY)
3241COMPATIBLE_IOCTL(VIDEO_FREEZE)
3242COMPATIBLE_IOCTL(VIDEO_CONTINUE)
3243COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
3244COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
3245COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
3246COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
3247COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
3248COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
3249COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
3250COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
3251COMPATIBLE_IOCTL(VIDEO_SET_ID)
3252COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
3253COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
3254COMPATIBLE_IOCTL(VIDEO_SET_SYSTEM)
3255COMPATIBLE_IOCTL(VIDEO_SET_HIGHLIGHT)
3256COMPATIBLE_IOCTL(VIDEO_SET_SPU)
3257COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
3258COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
3259COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
3260COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
3261
3262/* now things that need handlers */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
3264HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
3265#ifdef CONFIG_NET
3266HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
3267HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
3268HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
3269HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
3270HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
3271HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
3272HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
3273HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
3274HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
3275HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
3276HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
3277HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
3278HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
3279HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
3280HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
3281HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
3282HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
3283HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
3284HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
Andi Kleen67fd44f2006-12-07 02:14:03 +01003285HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
3287/* ioctls used by appletalk ddp.c */
3288HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
3289HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
3290HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
3291HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
3292
3293HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
3294HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
3295HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
3296HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
3297HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
3298HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
3299HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
3300HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
3301HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
3302HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
3303HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
3304HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
3305HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
3306HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
3307HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
3308HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
3309HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
3310HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
3311HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
3312HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
3313HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
3314HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
3315/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
3316HANDLE_IOCTL(SIOCRTMSG, ret_einval)
3317HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
Eric Dumazetae40eb12007-03-18 17:33:16 -07003318HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319#endif
David Howells93614012006-09-30 20:45:40 +02003320#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
3322HANDLE_IOCTL(BLKRAGET, w_long)
3323HANDLE_IOCTL(BLKGETSIZE, w_long)
3324HANDLE_IOCTL(0x1260, broken_blkgetsize)
3325HANDLE_IOCTL(BLKFRAGET, w_long)
3326HANDLE_IOCTL(BLKSECTGET, w_long)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
Maciej W. Rozycki39484e52006-10-11 01:21:54 -07003330HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
3331HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
Maciej W. Rozycki39484e52006-10-11 01:21:54 -07003333HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
Maciej W. Rozycki39484e52006-10-11 01:21:54 -07003335HANDLE_IOCTL(HDIO_GET_WCACHE, hdio_ioctl_trans)
3336HANDLE_IOCTL(HDIO_GET_ACOUSTIC, hdio_ioctl_trans)
3337HANDLE_IOCTL(HDIO_GET_ADDRESS, hdio_ioctl_trans)
3338HANDLE_IOCTL(HDIO_GET_BUSSTATE, hdio_ioctl_trans)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
3340HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
3341HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
3342HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
3343HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
3344HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
3345HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
3346HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
3347HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
3348HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
Andi Kleen29663872006-01-11 22:44:03 +01003349HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
David Howells93614012006-09-30 20:45:40 +02003350#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
3352HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
3353HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
3354HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
David Howells93614012006-09-30 20:45:40 +02003355#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
3357HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
3358HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
3359HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
David Howells93614012006-09-30 20:45:40 +02003360#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
3362HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
3363#ifdef CONFIG_VT
3364HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
3365HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
3366HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
3367HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
3368HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
3369#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370/* One SMB ioctl needs translations. */
3371#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
3372HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
3373HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
3374HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
3375HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
3376HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
3377HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
3378HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
3379HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
3380HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
3381HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
3382HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
3383HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
3384HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
3385HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
3386HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
3387HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
3388HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
3389HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
3390HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
3391HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
3392HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
3393HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
3394HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
3395HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
3396HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3397HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3398/* block stuff */
David Howells93614012006-09-30 20:45:40 +02003399#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
3401HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
3402HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403/* Raw devices */
3404HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
3405HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
David Howells93614012006-09-30 20:45:40 +02003406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407/* Serial */
3408HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
3409HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
Christoph Hellwig9c0cbd52005-10-30 15:01:41 -08003410#ifdef TIOCGLTC
3411COMPATIBLE_IOCTL(TIOCGLTC)
3412COMPATIBLE_IOCTL(TIOCSLTC)
3413#endif
Christoph Hellwig7a81e312005-11-08 21:35:07 -08003414#ifdef TIOCSTART
3415/*
3416 * For these two we have defintions in ioctls.h and/or termios.h on
3417 * some architectures but no actual implemention. Some applications
3418 * like bash call them if they are defined in the headers, so we provide
3419 * entries here to avoid syslog message spew.
3420 */
3421COMPATIBLE_IOCTL(TIOCSTART)
3422COMPATIBLE_IOCTL(TIOCSTOP)
3423#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424/* Usbdevfs */
3425HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
3426HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
3427HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
Pete Zaitcevc36fc882005-10-17 18:15:54 -07003428COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429/* i2c */
3430HANDLE_IOCTL(I2C_FUNCS, w_long)
3431HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
3432HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
3433/* wireless */
3434HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
Jean Tourrilhesed4bb102007-03-23 00:26:49 +00003435HANDLE_IOCTL(SIOCGIWPRIV, do_wireless_ioctl)
3436HANDLE_IOCTL(SIOCGIWSTATS, do_wireless_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
3438HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
3439HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
3440HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
Jean Tourrilhesed4bb102007-03-23 00:26:49 +00003441HANDLE_IOCTL(SIOCSIWMLME, do_wireless_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
Jean Tourrilhesed4bb102007-03-23 00:26:49 +00003443HANDLE_IOCTL(SIOCSIWSCAN, do_wireless_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
3445HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
3446HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
3447HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
3448HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
3449HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
3450HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
Jean Tourrilhesed4bb102007-03-23 00:26:49 +00003451HANDLE_IOCTL(SIOCSIWGENIE, do_wireless_ioctl)
3452HANDLE_IOCTL(SIOCGIWGENIE, do_wireless_ioctl)
3453HANDLE_IOCTL(SIOCSIWENCODEEXT, do_wireless_ioctl)
3454HANDLE_IOCTL(SIOCGIWENCODEEXT, do_wireless_ioctl)
3455HANDLE_IOCTL(SIOCSIWPMKSA, do_wireless_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
3457HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
Andi Kleen9d016dd2007-05-02 19:27:20 +02003458/* Not implemented in the native kernel */
3459IGNORE_IOCTL(SIOCGIFCOUNT)
Christoph Hellwigec3cad92006-01-09 20:52:11 -08003460HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
3461HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
3462HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
3463HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
David S. Miller6e87abd2005-11-16 00:52:57 -08003465/* dvb */
David S. Miller6e87abd2005-11-16 00:52:57 -08003466HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
3467HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
3468HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
Andi Kleenc6b44d12006-01-12 01:05:26 -08003469
3470/* parport */
3471COMPATIBLE_IOCTL(LPTIME)
3472COMPATIBLE_IOCTL(LPCHAR)
3473COMPATIBLE_IOCTL(LPABORTOPEN)
3474COMPATIBLE_IOCTL(LPCAREFUL)
3475COMPATIBLE_IOCTL(LPWAIT)
3476COMPATIBLE_IOCTL(LPSETIRQ)
3477COMPATIBLE_IOCTL(LPGETSTATUS)
3478COMPATIBLE_IOCTL(LPGETSTATUS)
3479COMPATIBLE_IOCTL(LPRESET)
3480/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
3481COMPATIBLE_IOCTL(LPGETFLAGS)
3482HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
Andi Kleen2724b6d2007-05-02 19:27:21 +02003483
3484/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
3485 but we don't want warnings on other file systems. So declare
3486 them as compatible here. */
3487#define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
3488#define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
3489
3490IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
3491IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08003492};
David S. Miller6e87abd2005-11-16 00:52:57 -08003493
Christoph Hellwig6272e262007-05-08 00:29:21 -07003494#define IOCTL_HASHSIZE 256
3495static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
3496
3497static inline unsigned long ioctl32_hash(unsigned long cmd)
3498{
3499 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
3500}
3501
3502static void compat_ioctl_error(struct file *filp, unsigned int fd,
3503 unsigned int cmd, unsigned long arg)
3504{
3505 char buf[10];
3506 char *fn = "?";
3507 char *path;
3508
3509 /* find the name of the device. */
3510 path = (char *)__get_free_page(GFP_KERNEL);
3511 if (path) {
3512 fn = d_path(filp->f_path.dentry, filp->f_path.mnt, path, PAGE_SIZE);
3513 if (IS_ERR(fn))
3514 fn = "?";
3515 }
3516
3517 sprintf(buf,"'%c'", (cmd>>_IOC_TYPESHIFT) & _IOC_TYPEMASK);
3518 if (!isprint(buf[1]))
3519 sprintf(buf, "%02x", buf[1]);
3520 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
3521 "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
3522 current->comm, current->pid,
3523 (int)fd, (unsigned int)cmd, buf,
3524 (cmd >> _IOC_SIZESHIFT) & _IOC_SIZEMASK,
3525 (unsigned int)arg, fn);
3526
3527 if (path)
3528 free_page((unsigned long)path);
3529}
3530
3531asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
3532 unsigned long arg)
3533{
3534 struct file *filp;
3535 int error = -EBADF;
3536 struct ioctl_trans *t;
3537 int fput_needed;
3538
3539 filp = fget_light(fd, &fput_needed);
3540 if (!filp)
3541 goto out;
3542
3543 /* RED-PEN how should LSM module know it's handling 32bit? */
3544 error = security_file_ioctl(filp, cmd, arg);
3545 if (error)
3546 goto out_fput;
3547
3548 /*
3549 * To allow the compat_ioctl handlers to be self contained
3550 * we need to check the common ioctls here first.
3551 * Just handle them with the standard handlers below.
3552 */
3553 switch (cmd) {
3554 case FIOCLEX:
3555 case FIONCLEX:
3556 case FIONBIO:
3557 case FIOASYNC:
3558 case FIOQSIZE:
3559 break;
3560
3561 case FIBMAP:
3562 case FIGETBSZ:
3563 case FIONREAD:
3564 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
3565 break;
3566 /*FALL THROUGH*/
3567
3568 default:
3569 if (filp->f_op && filp->f_op->compat_ioctl) {
3570 error = filp->f_op->compat_ioctl(filp, cmd, arg);
3571 if (error != -ENOIOCTLCMD)
3572 goto out_fput;
3573 }
3574
3575 if (!filp->f_op ||
3576 (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
3577 goto do_ioctl;
3578 break;
3579 }
3580
3581 for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
3582 if (t->cmd == cmd)
3583 goto found_handler;
3584 }
3585
Simon Hormand9de2622007-05-10 11:51:11 -07003586#ifdef CONFIG_NET
Christoph Hellwig6272e262007-05-08 00:29:21 -07003587 if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) &&
3588 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
3589 error = siocdevprivate_ioctl(fd, cmd, arg);
Simon Hormand9de2622007-05-10 11:51:11 -07003590 } else
3591#endif
3592 {
Christoph Hellwig6272e262007-05-08 00:29:21 -07003593 static int count;
3594
3595 if (++count <= 50)
3596 compat_ioctl_error(filp, fd, cmd, arg);
3597 error = -EINVAL;
3598 }
3599
3600 goto out_fput;
3601
3602 found_handler:
3603 if (t->handler) {
3604 lock_kernel();
3605 error = t->handler(fd, cmd, arg, filp);
3606 unlock_kernel();
3607 goto out_fput;
3608 }
3609
3610 do_ioctl:
3611 error = vfs_ioctl(filp, fd, cmd, arg);
3612 out_fput:
3613 fput_light(filp, fput_needed);
3614 out:
3615 return error;
3616}
3617
3618static void ioctl32_insert_translation(struct ioctl_trans *trans)
3619{
3620 unsigned long hash;
3621 struct ioctl_trans *t;
3622
3623 hash = ioctl32_hash (trans->cmd);
3624 if (!ioctl32_hash_table[hash])
3625 ioctl32_hash_table[hash] = trans;
3626 else {
3627 t = ioctl32_hash_table[hash];
3628 while (t->next)
3629 t = t->next;
3630 trans->next = NULL;
3631 t->next = trans;
3632 }
3633}
3634
3635static int __init init_sys32_ioctl(void)
3636{
3637 int i;
3638
3639 for (i = 0; i < ARRAY_SIZE(ioctl_start); i++) {
3640 if (ioctl_start[i].next != 0) {
3641 printk("ioctl translation %d bad\n",i);
3642 return -1;
3643 }
3644
3645 ioctl32_insert_translation(&ioctl_start[i]);
3646 }
3647 return 0;
3648}
3649__initcall(init_sys32_ioctl);