blob: c135202c38b3667b30698114d13d8f49cc076ab2 [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
Akos Maroy3fee37c2008-01-06 11:15:55 +010013#include <linux/joystick.h>
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/types.h>
16#include <linux/compat.h>
17#include <linux/kernel.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080018#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/compiler.h>
20#include <linux/sched.h>
21#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/ioctl.h>
23#include <linux/if.h>
24#include <linux/if_bridge.h>
25#include <linux/slab.h>
NeilBrownbff61972009-03-31 14:33:13 +110026#include <linux/raid/md_u.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/kd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/ppp_defs.h>
37#include <linux/if_ppp.h>
38#include <linux/if_pppox.h>
39#include <linux/mtio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/auto_fs.h>
41#include <linux/auto_fs4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/tty.h>
43#include <linux/vt_kern.h>
44#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/videodev.h>
46#include <linux/netdevice.h>
47#include <linux/raw.h>
48#include <linux/smb_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/blkdev.h>
50#include <linux/elevator.h>
51#include <linux/rtc.h>
52#include <linux/pci.h>
53#include <linux/module.h>
54#include <linux/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/if_tun.h>
56#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#include <linux/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/i2c.h>
59#include <linux/i2c-dev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <linux/atalk.h>
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include <net/bluetooth/bluetooth.h>
63#include <net/bluetooth/hci.h>
64#include <net/bluetooth/rfcomm.h>
65
66#include <linux/capi.h>
Hansjoerg Lipp5024ad42006-06-26 00:25:35 -070067#include <linux/gigaset_dev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Randy Dunlap3c3622d2008-07-16 08:52:00 -050069#ifdef CONFIG_BLOCK
Alexander Beregalov1ba0c7d2009-04-20 12:23:02 +040070#include <linux/loop.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <scsi/scsi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <scsi/scsi_ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <scsi/sg.h>
Randy Dunlap3c3622d2008-07-16 08:52:00 -050074#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include <asm/uaccess.h>
77#include <linux/ethtool.h>
78#include <linux/mii.h>
79#include <linux/if_bonding.h>
80#include <linux/watchdog.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include <linux/soundcard.h>
83#include <linux/lp.h>
84#include <linux/ppdev.h>
85
86#include <linux/atm.h>
87#include <linux/atmarp.h>
88#include <linux/atmclip.h>
89#include <linux/atmdev.h>
90#include <linux/atmioc.h>
91#include <linux/atmlec.h>
92#include <linux/atmmpc.h>
93#include <linux/atmsvc.h>
94#include <linux/atm_tcp.h>
95#include <linux/sonet.h>
96#include <linux/atm_suni.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98#include <linux/usb.h>
99#include <linux/usbdevice_fs.h>
100#include <linux/nbd.h>
101#include <linux/random.h>
102#include <linux/filter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#include <linux/pktcdvd.h>
104
105#include <linux/hiddev.h>
106
David S. Miller6e87abd2005-11-16 00:52:57 -0800107#include <linux/dvb/audio.h>
108#include <linux/dvb/dmx.h>
109#include <linux/dvb/frontend.h>
110#include <linux/dvb/video.h>
111
David S. Miller81639042007-07-29 00:50:42 -0700112#ifdef CONFIG_SPARC
113#include <asm/fbio.h>
114#endif
115
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -0800116static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
117 unsigned long arg, struct file *f)
118{
119 return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
123{
124 mm_segment_t old_fs = get_fs();
125 int err;
126 unsigned long val;
127
128 set_fs (KERNEL_DS);
129 err = sys_ioctl(fd, cmd, (unsigned long)&val);
130 set_fs (old_fs);
131 if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
132 return -EFAULT;
133 return err;
134}
135
136static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
137{
138 mm_segment_t old_fs = get_fs();
139 u32 __user *argptr = compat_ptr(arg);
140 int err;
141 unsigned long val;
142
143 if(get_user(val, argptr))
144 return -EFAULT;
145 set_fs (KERNEL_DS);
146 err = sys_ioctl(fd, cmd, (unsigned long)&val);
147 set_fs (old_fs);
148 if (!err && put_user(val, argptr))
149 return -EFAULT;
150 return err;
151}
152
David S. Miller6e87abd2005-11-16 00:52:57 -0800153struct compat_video_event {
154 int32_t type;
155 compat_time_t timestamp;
156 union {
157 video_size_t size;
158 unsigned int frame_rate;
159 } u;
160};
161
162static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
163{
164 struct video_event kevent;
165 mm_segment_t old_fs = get_fs();
166 int err;
167
168 set_fs(KERNEL_DS);
169 err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
170 set_fs(old_fs);
171
172 if (!err) {
173 struct compat_video_event __user *up = compat_ptr(arg);
174
175 err = put_user(kevent.type, &up->type);
176 err |= put_user(kevent.timestamp, &up->timestamp);
177 err |= put_user(kevent.u.size.w, &up->u.size.w);
178 err |= put_user(kevent.u.size.h, &up->u.size.h);
179 err |= put_user(kevent.u.size.aspect_ratio,
180 &up->u.size.aspect_ratio);
181 if (err)
182 err = -EFAULT;
183 }
184
185 return err;
186}
187
188struct compat_video_still_picture {
189 compat_uptr_t iFrame;
190 int32_t size;
191};
192
193static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
194{
195 struct compat_video_still_picture __user *up;
196 struct video_still_picture __user *up_native;
197 compat_uptr_t fp;
198 int32_t size;
199 int err;
200
201 up = (struct compat_video_still_picture __user *) arg;
202 err = get_user(fp, &up->iFrame);
203 err |= get_user(size, &up->size);
204 if (err)
205 return -EFAULT;
206
207 up_native =
208 compat_alloc_user_space(sizeof(struct video_still_picture));
209
Heiko Carstens7116e992006-12-06 20:36:36 -0800210 err = put_user(compat_ptr(fp), &up_native->iFrame);
211 err |= put_user(size, &up_native->size);
212 if (err)
213 return -EFAULT;
David S. Miller6e87abd2005-11-16 00:52:57 -0800214
215 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
216
217 return err;
218}
219
220struct compat_video_spu_palette {
221 int length;
222 compat_uptr_t palette;
223};
224
225static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
226{
227 struct compat_video_spu_palette __user *up;
228 struct video_spu_palette __user *up_native;
229 compat_uptr_t palp;
230 int length, err;
231
232 up = (struct compat_video_spu_palette __user *) arg;
233 err = get_user(palp, &up->palette);
234 err |= get_user(length, &up->length);
235
236 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
Heiko Carstens7116e992006-12-06 20:36:36 -0800237 err = put_user(compat_ptr(palp), &up_native->palette);
238 err |= put_user(length, &up_native->length);
239 if (err)
240 return -EFAULT;
David S. Miller6e87abd2005-11-16 00:52:57 -0800241
242 err = sys_ioctl(fd, cmd, (unsigned long) up_native);
243
244 return err;
245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#ifdef CONFIG_NET
248static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
249{
250 struct compat_timeval __user *up = compat_ptr(arg);
251 struct timeval ktv;
252 mm_segment_t old_fs = get_fs();
253 int err;
254
255 set_fs(KERNEL_DS);
256 err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
257 set_fs(old_fs);
258 if(!err) {
259 err = put_user(ktv.tv_sec, &up->tv_sec);
260 err |= __put_user(ktv.tv_usec, &up->tv_usec);
261 }
262 return err;
263}
264
Eric Dumazetae40eb12007-03-18 17:33:16 -0700265static int do_siocgstampns(unsigned int fd, unsigned int cmd, unsigned long arg)
266{
267 struct compat_timespec __user *up = compat_ptr(arg);
268 struct timespec kts;
269 mm_segment_t old_fs = get_fs();
270 int err;
271
272 set_fs(KERNEL_DS);
273 err = sys_ioctl(fd, cmd, (unsigned long)&kts);
274 set_fs(old_fs);
275 if (!err) {
276 err = put_user(kts.tv_sec, &up->tv_sec);
277 err |= __put_user(kts.tv_nsec, &up->tv_nsec);
278 }
279 return err;
280}
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282struct ifmap32 {
283 compat_ulong_t mem_start;
284 compat_ulong_t mem_end;
285 unsigned short base_addr;
286 unsigned char irq;
287 unsigned char dma;
288 unsigned char port;
289};
290
291struct ifreq32 {
292#define IFHWADDRLEN 6
293#define IFNAMSIZ 16
294 union {
295 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
296 } ifr_ifrn;
297 union {
298 struct sockaddr ifru_addr;
299 struct sockaddr ifru_dstaddr;
300 struct sockaddr ifru_broadaddr;
301 struct sockaddr ifru_netmask;
302 struct sockaddr ifru_hwaddr;
303 short ifru_flags;
304 compat_int_t ifru_ivalue;
305 compat_int_t ifru_mtu;
306 struct ifmap32 ifru_map;
307 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
308 char ifru_newname[IFNAMSIZ];
309 compat_caddr_t ifru_data;
310 /* XXXX? ifru_settings should be here */
311 } ifr_ifru;
312};
313
314struct ifconf32 {
315 compat_int_t ifc_len; /* size of buffer */
316 compat_caddr_t ifcbuf;
317};
318
319static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
320{
Eric W. Biederman32da4772007-09-12 11:37:03 +0200321 struct ifreq __user *uifr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 int err;
323
Eric W. Biederman32da4772007-09-12 11:37:03 +0200324 uifr = compat_alloc_user_space(sizeof(struct ifreq));
Benjamin Herrenschmidtbe48be02007-10-30 20:40:45 -0700325 if (copy_in_user(uifr, compat_ptr(arg), sizeof(struct ifreq32)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 return -EFAULT;
327
Eric W. Biederman32da4772007-09-12 11:37:03 +0200328 err = sys_ioctl(fd, SIOCGIFNAME, (unsigned long)uifr);
329 if (err)
330 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Eric W. Biederman32da4772007-09-12 11:37:03 +0200332 if (copy_in_user(compat_ptr(arg), uifr, sizeof(struct ifreq32)))
333 return -EFAULT;
334
335 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
339{
340 struct ifconf32 ifc32;
341 struct ifconf ifc;
342 struct ifconf __user *uifc;
343 struct ifreq32 __user *ifr32;
344 struct ifreq __user *ifr;
345 unsigned int i, j;
346 int err;
347
348 if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
349 return -EFAULT;
350
351 if (ifc32.ifcbuf == 0) {
352 ifc32.ifc_len = 0;
353 ifc.ifc_len = 0;
354 ifc.ifc_req = NULL;
355 uifc = compat_alloc_user_space(sizeof(struct ifconf));
356 } else {
357 size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
358 sizeof (struct ifreq);
359 uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
360 ifc.ifc_len = len;
361 ifr = ifc.ifc_req = (void __user *)(uifc + 1);
362 ifr32 = compat_ptr(ifc32.ifcbuf);
363 for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
364 if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
365 return -EFAULT;
366 ifr++;
367 ifr32++;
368 }
369 }
370 if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
371 return -EFAULT;
372
373 err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
374 if (err)
375 return err;
376
377 if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
378 return -EFAULT;
379
380 ifr = ifc.ifc_req;
381 ifr32 = compat_ptr(ifc32.ifcbuf);
Alexandra Kossovsky49097242005-11-20 13:41:59 -0800382 for (i = 0, j = 0;
Randy Dunlap1efa3c02006-03-08 16:46:08 -0800383 i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
385 if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
386 return -EFAULT;
387 ifr32++;
388 ifr++;
389 }
390
391 if (ifc32.ifcbuf == 0) {
392 /* Translate from 64-bit structure multiple to
393 * a 32-bit one.
394 */
395 i = ifc.ifc_len;
396 i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
397 ifc32.ifc_len = i;
398 } else {
Alexandra Kossovsky49097242005-11-20 13:41:59 -0800399 ifc32.ifc_len = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401 if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
402 return -EFAULT;
403
404 return 0;
405}
406
407static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
408{
409 struct ifreq __user *ifr;
410 struct ifreq32 __user *ifr32;
411 u32 data;
412 void __user *datap;
413
414 ifr = compat_alloc_user_space(sizeof(*ifr));
415 ifr32 = compat_ptr(arg);
416
417 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
418 return -EFAULT;
419
420 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
421 return -EFAULT;
422
423 datap = compat_ptr(data);
424 if (put_user(datap, &ifr->ifr_ifru.ifru_data))
425 return -EFAULT;
426
427 return sys_ioctl(fd, cmd, (unsigned long) ifr);
428}
429
430static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
431{
432 struct ifreq kifr;
433 struct ifreq __user *uifr;
434 struct ifreq32 __user *ifr32 = compat_ptr(arg);
435 mm_segment_t old_fs;
436 int err;
437 u32 data;
438 void __user *datap;
439
440 switch (cmd) {
441 case SIOCBONDENSLAVE:
442 case SIOCBONDRELEASE:
443 case SIOCBONDSETHWADDR:
444 case SIOCBONDCHANGEACTIVE:
445 if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
446 return -EFAULT;
447
448 old_fs = get_fs();
449 set_fs (KERNEL_DS);
450 err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
451 set_fs (old_fs);
452
453 return err;
454 case SIOCBONDSLAVEINFOQUERY:
455 case SIOCBONDINFOQUERY:
456 uifr = compat_alloc_user_space(sizeof(*uifr));
457 if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
458 return -EFAULT;
459
460 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
461 return -EFAULT;
462
463 datap = compat_ptr(data);
464 if (put_user(datap, &uifr->ifr_ifru.ifru_data))
465 return -EFAULT;
466
467 return sys_ioctl (fd, cmd, (unsigned long)uifr);
468 default:
469 return -EINVAL;
470 };
471}
472
Christoph Hellwig6272e262007-05-08 00:29:21 -0700473static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 struct ifreq __user *u_ifreq64;
476 struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
477 char tmp_buf[IFNAMSIZ];
478 void __user *data64;
479 u32 data32;
480
481 if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
482 IFNAMSIZ))
483 return -EFAULT;
484 if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
485 return -EFAULT;
486 data64 = compat_ptr(data32);
487
488 u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
489
490 /* Don't check these user accesses, just let that get trapped
491 * in the ioctl handler instead.
492 */
493 if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
494 IFNAMSIZ))
495 return -EFAULT;
496 if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
497 return -EFAULT;
498
499 return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
500}
501
502static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
503{
504 struct ifreq ifr;
505 struct ifreq32 __user *uifr32;
506 struct ifmap32 __user *uifmap32;
507 mm_segment_t old_fs;
508 int err;
509
510 uifr32 = compat_ptr(arg);
511 uifmap32 = &uifr32->ifr_ifru.ifru_map;
512 switch (cmd) {
513 case SIOCSIFMAP:
514 err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
515 err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
516 err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
517 err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
518 err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
519 err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
520 err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
521 if (err)
522 return -EFAULT;
523 break;
Patrick Ohlyd24fff22009-02-12 05:03:40 +0000524 case SIOCSHWTSTAMP:
525 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
526 return -EFAULT;
527 ifr.ifr_data = compat_ptr(uifr32->ifr_ifru.ifru_data);
528 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 default:
530 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
531 return -EFAULT;
532 break;
533 }
534 old_fs = get_fs();
535 set_fs (KERNEL_DS);
536 err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
537 set_fs (old_fs);
538 if (!err) {
539 switch (cmd) {
540 /* TUNSETIFF is defined as _IOW, it should be _IORW
541 * as the data is copied back to user space, but that
542 * cannot be fixed without breaking all existing apps.
543 */
544 case TUNSETIFF:
David S. Millerdf1c46b2009-01-29 16:53:35 -0800545 case TUNGETIFF:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 case SIOCGIFFLAGS:
547 case SIOCGIFMETRIC:
548 case SIOCGIFMTU:
549 case SIOCGIFMEM:
550 case SIOCGIFHWADDR:
551 case SIOCGIFINDEX:
552 case SIOCGIFADDR:
553 case SIOCGIFBRDADDR:
554 case SIOCGIFDSTADDR:
555 case SIOCGIFNETMASK:
556 case SIOCGIFTXQLEN:
557 if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
558 return -EFAULT;
559 break;
560 case SIOCGIFMAP:
561 err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
562 err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
563 err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
564 err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
565 err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
566 err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
567 err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
568 if (err)
569 err = -EFAULT;
570 break;
571 }
572 }
573 return err;
574}
575
576struct rtentry32 {
577 u32 rt_pad1;
578 struct sockaddr rt_dst; /* target address */
579 struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
580 struct sockaddr rt_genmask; /* target network mask (IP) */
581 unsigned short rt_flags;
582 short rt_pad2;
583 u32 rt_pad3;
584 unsigned char rt_tos;
585 unsigned char rt_class;
586 short rt_pad4;
587 short rt_metric; /* +1 for binary compatibility! */
588 /* char * */ u32 rt_dev; /* forcing the device at add */
589 u32 rt_mtu; /* per route MTU/Window */
590 u32 rt_window; /* Window clamping */
591 unsigned short rt_irtt; /* Initial RTT */
592
593};
594
595struct in6_rtmsg32 {
596 struct in6_addr rtmsg_dst;
597 struct in6_addr rtmsg_src;
598 struct in6_addr rtmsg_gateway;
599 u32 rtmsg_type;
600 u16 rtmsg_dst_len;
601 u16 rtmsg_src_len;
602 u32 rtmsg_metric;
603 u32 rtmsg_info;
604 u32 rtmsg_flags;
605 s32 rtmsg_ifindex;
606};
607
608static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
609{
610 int ret;
611 void *r = NULL;
612 struct in6_rtmsg r6;
613 struct rtentry r4;
614 char devname[16];
615 u32 rtdev;
616 mm_segment_t old_fs = get_fs();
617
618 struct socket *mysock = sockfd_lookup(fd, &ret);
619
620 if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
621 struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
622 ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
623 3 * sizeof(struct in6_addr));
624 ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
625 ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
626 ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
627 ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
628 ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
629 ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
630 ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
631
632 r = (void *) &r6;
633 } else { /* ipv4 */
634 struct rtentry32 __user *ur4 = compat_ptr(arg);
635 ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
636 3 * sizeof(struct sockaddr));
637 ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
638 ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
639 ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
640 ret |= __get_user (r4.rt_window, &(ur4->rt_window));
641 ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
642 ret |= __get_user (rtdev, &(ur4->rt_dev));
643 if (rtdev) {
644 ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
645 r4.rt_dev = devname; devname[15] = 0;
646 } else
647 r4.rt_dev = NULL;
648
649 r = (void *) &r4;
650 }
651
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400652 if (ret) {
653 ret = -EFAULT;
654 goto out;
655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 set_fs (KERNEL_DS);
658 ret = sys_ioctl (fd, cmd, (unsigned long) r);
659 set_fs (old_fs);
660
Kirill Korotaevd99901d2005-09-09 13:59:48 +0400661out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 if (mysock)
663 sockfd_put(mysock);
664
665 return ret;
666}
667#endif
668
David Howells93614012006-09-30 20:45:40 +0200669#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670typedef struct sg_io_hdr32 {
671 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
672 compat_int_t dxfer_direction; /* [i] data transfer direction */
673 unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
674 unsigned char mx_sb_len; /* [i] max length to write to sbp */
675 unsigned short iovec_count; /* [i] 0 implies no scatter gather */
676 compat_uint_t dxfer_len; /* [i] byte count of data transfer */
677 compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
678 or scatter gather list */
679 compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
680 compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
681 compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
682 compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
683 compat_int_t pack_id; /* [i->o] unused internally (normally) */
684 compat_uptr_t usr_ptr; /* [i->o] unused internally */
685 unsigned char status; /* [o] scsi status */
686 unsigned char masked_status; /* [o] shifted, masked scsi status */
687 unsigned char msg_status; /* [o] messaging level data (optional) */
688 unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
689 unsigned short host_status; /* [o] errors from host adapter */
690 unsigned short driver_status; /* [o] errors from software driver */
691 compat_int_t resid; /* [o] dxfer_len - actual_transferred */
692 compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
693 compat_uint_t info; /* [o] auxiliary information */
694} sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
695
696typedef struct sg_iovec32 {
697 compat_uint_t iov_base;
698 compat_uint_t iov_len;
699} sg_iovec32_t;
700
701static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
702{
703 sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
704 sg_iovec32_t __user *iov32 = dxferp;
705 int i;
706
707 for (i = 0; i < iovec_count; i++) {
708 u32 base, len;
709
710 if (get_user(base, &iov32[i].iov_base) ||
711 get_user(len, &iov32[i].iov_len) ||
712 put_user(compat_ptr(base), &iov[i].iov_base) ||
713 put_user(len, &iov[i].iov_len))
714 return -EFAULT;
715 }
716
717 if (put_user(iov, &sgio->dxferp))
718 return -EFAULT;
719 return 0;
720}
721
722static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
723{
724 sg_io_hdr_t __user *sgio;
725 sg_io_hdr32_t __user *sgio32;
726 u16 iovec_count;
727 u32 data;
728 void __user *dxferp;
729 int err;
730
731 sgio32 = compat_ptr(arg);
732 if (get_user(iovec_count, &sgio32->iovec_count))
733 return -EFAULT;
734
735 {
736 void __user *top = compat_alloc_user_space(0);
737 void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
738 (iovec_count * sizeof(sg_iovec_t)));
739 if (new > top)
740 return -EINVAL;
741
742 sgio = new;
743 }
744
745 /* Ok, now construct. */
746 if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
747 (2 * sizeof(int)) +
748 (2 * sizeof(unsigned char)) +
749 (1 * sizeof(unsigned short)) +
750 (1 * sizeof(unsigned int))))
751 return -EFAULT;
752
753 if (get_user(data, &sgio32->dxferp))
754 return -EFAULT;
755 dxferp = compat_ptr(data);
756 if (iovec_count) {
757 if (sg_build_iovec(sgio, dxferp, iovec_count))
758 return -EFAULT;
759 } else {
760 if (put_user(dxferp, &sgio->dxferp))
761 return -EFAULT;
762 }
763
764 {
765 unsigned char __user *cmdp;
766 unsigned char __user *sbp;
767
768 if (get_user(data, &sgio32->cmdp))
769 return -EFAULT;
770 cmdp = compat_ptr(data);
771
772 if (get_user(data, &sgio32->sbp))
773 return -EFAULT;
774 sbp = compat_ptr(data);
775
776 if (put_user(cmdp, &sgio->cmdp) ||
777 put_user(sbp, &sgio->sbp))
778 return -EFAULT;
779 }
780
781 if (copy_in_user(&sgio->timeout, &sgio32->timeout,
782 3 * sizeof(int)))
783 return -EFAULT;
784
785 if (get_user(data, &sgio32->usr_ptr))
786 return -EFAULT;
787 if (put_user(compat_ptr(data), &sgio->usr_ptr))
788 return -EFAULT;
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 err = sys_ioctl(fd, cmd, (unsigned long) sgio);
791
792 if (err >= 0) {
793 void __user *datap;
794
795 if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
796 sizeof(int)) ||
797 get_user(datap, &sgio->usr_ptr) ||
798 put_user((u32)(unsigned long)datap,
799 &sgio32->usr_ptr) ||
800 copy_in_user(&sgio32->status, &sgio->status,
801 (4 * sizeof(unsigned char)) +
802 (2 * sizeof(unsigned short)) +
803 (3 * sizeof(int))))
804 err = -EFAULT;
805 }
806
807 return err;
808}
809
Andi Kleen29663872006-01-11 22:44:03 +0100810struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
811 char req_state;
812 char orphan;
813 char sg_io_owned;
814 char problem;
815 int pack_id;
816 compat_uptr_t usr_ptr;
817 unsigned int duration;
818 int unused;
819};
820
821static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
822{
823 int err, i;
Al Viro6b2b4e52006-02-01 06:33:33 -0500824 sg_req_info_t __user *r;
825 struct compat_sg_req_info __user *o = (void __user *)arg;
Andi Kleen29663872006-01-11 22:44:03 +0100826 r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
827 err = sys_ioctl(fd,cmd,(unsigned long)r);
828 if (err < 0)
829 return err;
830 for (i = 0; i < SG_MAX_QUEUE; i++) {
831 void __user *ptr;
832 int d;
833
834 if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
835 get_user(ptr, &r[i].usr_ptr) ||
836 get_user(d, &r[i].duration) ||
837 put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
838 put_user(d, &o[i].duration))
839 return -EFAULT;
840 }
841 return err;
842}
David Howells93614012006-09-30 20:45:40 +0200843#endif /* CONFIG_BLOCK */
Andi Kleen29663872006-01-11 22:44:03 +0100844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845struct sock_fprog32 {
846 unsigned short len;
847 compat_caddr_t filter;
848};
849
850#define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
851#define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
852
853static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
854{
855 struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
856 struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
857 void __user *fptr64;
858 u32 fptr32;
859 u16 flen;
860
861 if (get_user(flen, &u_fprog32->len) ||
862 get_user(fptr32, &u_fprog32->filter))
863 return -EFAULT;
864
865 fptr64 = compat_ptr(fptr32);
866
867 if (put_user(flen, &u_fprog64->len) ||
868 put_user(fptr64, &u_fprog64->filter))
869 return -EFAULT;
870
871 if (cmd == PPPIOCSPASS32)
872 cmd = PPPIOCSPASS;
873 else
874 cmd = PPPIOCSACTIVE;
875
876 return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
877}
878
879struct ppp_option_data32 {
880 compat_caddr_t ptr;
881 u32 length;
882 compat_int_t transmit;
883};
884#define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
885
886struct ppp_idle32 {
887 compat_time_t xmit_idle;
888 compat_time_t recv_idle;
889};
890#define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
891
892static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
893{
894 struct ppp_idle __user *idle;
895 struct ppp_idle32 __user *idle32;
896 __kernel_time_t xmit, recv;
897 int err;
898
899 idle = compat_alloc_user_space(sizeof(*idle));
900 idle32 = compat_ptr(arg);
901
902 err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
903
904 if (!err) {
905 if (get_user(xmit, &idle->xmit_idle) ||
906 get_user(recv, &idle->recv_idle) ||
907 put_user(xmit, &idle32->xmit_idle) ||
908 put_user(recv, &idle32->recv_idle))
909 err = -EFAULT;
910 }
911 return err;
912}
913
914static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
915{
916 struct ppp_option_data __user *odata;
917 struct ppp_option_data32 __user *odata32;
918 __u32 data;
919 void __user *datap;
920
921 odata = compat_alloc_user_space(sizeof(*odata));
922 odata32 = compat_ptr(arg);
923
924 if (get_user(data, &odata32->ptr))
925 return -EFAULT;
926
927 datap = compat_ptr(data);
928 if (put_user(datap, &odata->ptr))
929 return -EFAULT;
930
931 if (copy_in_user(&odata->length, &odata32->length,
932 sizeof(__u32) + sizeof(int)))
933 return -EFAULT;
934
935 return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
936}
937
938static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
939{
940 int err;
941
942 switch (cmd) {
943 case PPPIOCGIDLE32:
944 err = ppp_gidle(fd, cmd, arg);
945 break;
946
947 case PPPIOCSCOMPRESS32:
948 err = ppp_scompress(fd, cmd, arg);
949 break;
950
951 default:
952 do {
953 static int count;
954 if (++count <= 20)
955 printk("ppp_ioctl: Unknown cmd fd(%d) "
956 "cmd(%08x) arg(%08x)\n",
957 (int)fd, (unsigned int)cmd, (unsigned int)arg);
958 } while(0);
959 err = -EINVAL;
960 break;
961 };
962
963 return err;
964}
965
966
David Howells93614012006-09-30 20:45:40 +0200967#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968struct mtget32 {
969 compat_long_t mt_type;
970 compat_long_t mt_resid;
971 compat_long_t mt_dsreg;
972 compat_long_t mt_gstat;
973 compat_long_t mt_erreg;
974 compat_daddr_t mt_fileno;
975 compat_daddr_t mt_blkno;
976};
977#define MTIOCGET32 _IOR('m', 2, struct mtget32)
978
979struct mtpos32 {
980 compat_long_t mt_blkno;
981};
982#define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
983
984static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
985{
986 mm_segment_t old_fs = get_fs();
987 struct mtget get;
988 struct mtget32 __user *umget32;
989 struct mtpos pos;
990 struct mtpos32 __user *upos32;
991 unsigned long kcmd;
992 void *karg;
993 int err = 0;
994
995 switch(cmd) {
996 case MTIOCPOS32:
997 kcmd = MTIOCPOS;
998 karg = &pos;
999 break;
1000 case MTIOCGET32:
1001 kcmd = MTIOCGET;
1002 karg = &get;
1003 break;
1004 default:
1005 do {
1006 static int count;
1007 if (++count <= 20)
1008 printk("mt_ioctl: Unknown cmd fd(%d) "
1009 "cmd(%08x) arg(%08x)\n",
1010 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1011 } while(0);
1012 return -EINVAL;
1013 }
1014 set_fs (KERNEL_DS);
1015 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1016 set_fs (old_fs);
1017 if (err)
1018 return err;
1019 switch (cmd) {
1020 case MTIOCPOS32:
1021 upos32 = compat_ptr(arg);
1022 err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
1023 break;
1024 case MTIOCGET32:
1025 umget32 = compat_ptr(arg);
1026 err = __put_user(get.mt_type, &umget32->mt_type);
1027 err |= __put_user(get.mt_resid, &umget32->mt_resid);
1028 err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
1029 err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
1030 err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
1031 err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
1032 err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
1033 break;
1034 }
1035 return err ? -EFAULT: 0;
1036}
1037
David Howells93614012006-09-30 20:45:40 +02001038#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040#ifdef CONFIG_VT
1041
1042static int vt_check(struct file *file)
1043{
1044 struct tty_struct *tty;
Josef "Jeff" Sipek0f7fc9e2006-12-08 02:36:35 -08001045 struct inode *inode = file->f_path.dentry->d_inode;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001046 struct vc_data *vc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Alan Cox04f378b2008-04-30 00:53:29 -07001048 if (file->f_op->unlocked_ioctl != tty_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 return -EINVAL;
1050
1051 tty = (struct tty_struct *)file->private_data;
1052 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1053 return -EINVAL;
1054
Alan Coxf34d7a52008-04-30 00:54:13 -07001055 if (tty->ops->ioctl != vt_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 return -EINVAL;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001057
1058 vc = (struct vc_data *)tty->driver_data;
1059 if (!vc_cons_allocated(vc->vc_num)) /* impossible? */
1060 return -ENOIOCTLCMD;
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 /*
1063 * To have permissions to do most of the vt ioctls, we either have
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001064 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 */
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001066 if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 return 1;
1068 return 0;
1069}
1070
1071struct consolefontdesc32 {
1072 unsigned short charcount; /* characters in font (256 or 512) */
1073 unsigned short charheight; /* scan lines per character (1-32) */
1074 compat_caddr_t chardata; /* font data in expanded form */
1075};
1076
1077static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1078{
1079 struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
1080 struct console_font_op op;
1081 compat_caddr_t data;
1082 int i, perm;
1083
1084 perm = vt_check(file);
1085 if (perm < 0) return perm;
1086
1087 switch (cmd) {
1088 case PIO_FONTX:
1089 if (!perm)
1090 return -EPERM;
1091 op.op = KD_FONT_OP_SET;
1092 op.flags = 0;
1093 op.width = 8;
1094 if (get_user(op.height, &user_cfd->charheight) ||
1095 get_user(op.charcount, &user_cfd->charcount) ||
1096 get_user(data, &user_cfd->chardata))
1097 return -EFAULT;
1098 op.data = compat_ptr(data);
1099 return con_font_op(vc_cons[fg_console].d, &op);
1100 case GIO_FONTX:
1101 op.op = KD_FONT_OP_GET;
1102 op.flags = 0;
1103 op.width = 8;
1104 if (get_user(op.height, &user_cfd->charheight) ||
1105 get_user(op.charcount, &user_cfd->charcount) ||
1106 get_user(data, &user_cfd->chardata))
1107 return -EFAULT;
1108 if (!data)
1109 return 0;
1110 op.data = compat_ptr(data);
1111 i = con_font_op(vc_cons[fg_console].d, &op);
1112 if (i)
1113 return i;
1114 if (put_user(op.height, &user_cfd->charheight) ||
1115 put_user(op.charcount, &user_cfd->charcount) ||
1116 put_user((compat_caddr_t)(unsigned long)op.data,
1117 &user_cfd->chardata))
1118 return -EFAULT;
1119 return 0;
1120 }
1121 return -EINVAL;
1122}
1123
1124struct console_font_op32 {
1125 compat_uint_t op; /* operation code KD_FONT_OP_* */
1126 compat_uint_t flags; /* KD_FONT_FLAG_* */
1127 compat_uint_t width, height; /* font size */
1128 compat_uint_t charcount;
1129 compat_caddr_t data; /* font data with height fixed to 32 */
1130};
1131
1132static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1133{
1134 struct console_font_op op;
1135 struct console_font_op32 __user *fontop = compat_ptr(arg);
1136 int perm = vt_check(file), i;
1137 struct vc_data *vc;
1138
1139 if (perm < 0) return perm;
1140
1141 if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
1142 return -EFAULT;
1143 if (!perm && op.op != KD_FONT_OP_GET)
1144 return -EPERM;
1145 op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
1146 op.flags |= KD_FONT_FLAG_OLD;
1147 vc = ((struct tty_struct *)file->private_data)->driver_data;
1148 i = con_font_op(vc, &op);
1149 if (i)
1150 return i;
1151 ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
1152 if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
1153 return -EFAULT;
1154 return 0;
1155}
1156
1157struct unimapdesc32 {
1158 unsigned short entry_ct;
1159 compat_caddr_t entries;
1160};
1161
1162static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
1163{
1164 struct unimapdesc32 tmp;
1165 struct unimapdesc32 __user *user_ud = compat_ptr(arg);
1166 int perm = vt_check(file);
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001167 struct vc_data *vc;
1168
1169 if (perm < 0)
1170 return perm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 if (copy_from_user(&tmp, user_ud, sizeof tmp))
1172 return -EFAULT;
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001173 if (tmp.entries)
1174 if (!access_ok(VERIFY_WRITE, compat_ptr(tmp.entries),
1175 tmp.entry_ct*sizeof(struct unipair)))
1176 return -EFAULT;
1177 vc = ((struct tty_struct *)file->private_data)->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 switch (cmd) {
1179 case PIO_UNIMAP:
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001180 if (!perm)
1181 return -EPERM;
1182 return con_set_unimap(vc, tmp.entry_ct,
1183 compat_ptr(tmp.entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 case GIO_UNIMAP:
Hugh Dickinsf4d43bd2007-05-26 00:39:17 +01001185 if (!perm && fg_console != vc->vc_num)
1186 return -EPERM;
1187 return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct),
1188 compat_ptr(tmp.entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190 return 0;
1191}
1192
1193#endif /* CONFIG_VT */
1194
1195static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
1196{
1197 mm_segment_t old_fs = get_fs();
1198 __kernel_uid_t kuid;
1199 int err;
1200
1201 cmd = SMB_IOC_GETMOUNTUID;
1202
1203 set_fs(KERNEL_DS);
1204 err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
1205 set_fs(old_fs);
1206
1207 if (err >= 0)
1208 err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
1209
1210 return err;
1211}
1212
1213struct atmif_sioc32 {
1214 compat_int_t number;
1215 compat_int_t length;
1216 compat_caddr_t arg;
1217};
1218
1219struct atm_iobuf32 {
1220 compat_int_t length;
1221 compat_caddr_t buffer;
1222};
1223
1224#define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
1225#define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
1226#define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
1227#define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
1228#define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
1229#define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
1230#define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
1231#define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
1232#define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
1233#define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
1234#define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
1235#define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
1236#define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
1237#define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
1238#define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
1239#define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
1240#define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
1241
1242static struct {
1243 unsigned int cmd32;
1244 unsigned int cmd;
1245} atm_ioctl_map[] = {
1246 { ATM_GETLINKRATE32, ATM_GETLINKRATE },
1247 { ATM_GETNAMES32, ATM_GETNAMES },
1248 { ATM_GETTYPE32, ATM_GETTYPE },
1249 { ATM_GETESI32, ATM_GETESI },
1250 { ATM_GETADDR32, ATM_GETADDR },
1251 { ATM_RSTADDR32, ATM_RSTADDR },
1252 { ATM_ADDADDR32, ATM_ADDADDR },
1253 { ATM_DELADDR32, ATM_DELADDR },
1254 { ATM_GETCIRANGE32, ATM_GETCIRANGE },
1255 { ATM_SETCIRANGE32, ATM_SETCIRANGE },
1256 { ATM_SETESI32, ATM_SETESI },
1257 { ATM_SETESIF32, ATM_SETESIF },
1258 { ATM_GETSTAT32, ATM_GETSTAT },
1259 { ATM_GETSTATZ32, ATM_GETSTATZ },
1260 { ATM_GETLOOP32, ATM_GETLOOP },
1261 { ATM_SETLOOP32, ATM_SETLOOP },
1262 { ATM_QUERYLOOP32, ATM_QUERYLOOP }
1263};
1264
Tobias Klausere8c96f82006-03-24 03:15:34 -08001265#define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
1268{
1269 struct atm_iobuf __user *iobuf;
1270 struct atm_iobuf32 __user *iobuf32;
1271 u32 data;
1272 void __user *datap;
1273 int len, err;
1274
1275 iobuf = compat_alloc_user_space(sizeof(*iobuf));
1276 iobuf32 = compat_ptr(arg);
1277
1278 if (get_user(len, &iobuf32->length) ||
1279 get_user(data, &iobuf32->buffer))
1280 return -EFAULT;
1281 datap = compat_ptr(data);
1282 if (put_user(len, &iobuf->length) ||
1283 put_user(datap, &iobuf->buffer))
1284 return -EFAULT;
1285
1286 err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
1287
1288 if (!err) {
1289 if (copy_in_user(&iobuf32->length, &iobuf->length,
1290 sizeof(int)))
1291 err = -EFAULT;
1292 }
1293
1294 return err;
1295}
1296
1297static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
1298{
1299 struct atmif_sioc __user *sioc;
1300 struct atmif_sioc32 __user *sioc32;
1301 u32 data;
1302 void __user *datap;
1303 int err;
1304
1305 sioc = compat_alloc_user_space(sizeof(*sioc));
1306 sioc32 = compat_ptr(arg);
1307
1308 if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
1309 get_user(data, &sioc32->arg))
1310 return -EFAULT;
1311 datap = compat_ptr(data);
1312 if (put_user(datap, &sioc->arg))
1313 return -EFAULT;
1314
1315 err = sys_ioctl(fd, cmd, (unsigned long) sioc);
1316
1317 if (!err) {
1318 if (copy_in_user(&sioc32->length, &sioc->length,
1319 sizeof(int)))
1320 err = -EFAULT;
1321 }
1322 return err;
1323}
1324
1325static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
1326{
1327 int i;
1328 unsigned int cmd = 0;
1329
1330 switch (cmd32) {
1331 case SONET_GETSTAT:
1332 case SONET_GETSTATZ:
1333 case SONET_GETDIAG:
1334 case SONET_SETDIAG:
1335 case SONET_CLRDIAG:
1336 case SONET_SETFRAMING:
1337 case SONET_GETFRAMING:
1338 case SONET_GETFRSENSE:
1339 return do_atmif_sioc(fd, cmd32, arg);
1340 }
1341
1342 for (i = 0; i < NR_ATM_IOCTL; i++) {
1343 if (cmd32 == atm_ioctl_map[i].cmd32) {
1344 cmd = atm_ioctl_map[i].cmd;
1345 break;
1346 }
1347 }
1348 if (i == NR_ATM_IOCTL)
1349 return -EINVAL;
1350
1351 switch (cmd) {
1352 case ATM_GETNAMES:
1353 return do_atm_iobuf(fd, cmd, arg);
1354
1355 case ATM_GETLINKRATE:
1356 case ATM_GETTYPE:
1357 case ATM_GETESI:
1358 case ATM_GETADDR:
1359 case ATM_RSTADDR:
1360 case ATM_ADDADDR:
1361 case ATM_DELADDR:
1362 case ATM_GETCIRANGE:
1363 case ATM_SETCIRANGE:
1364 case ATM_SETESI:
1365 case ATM_SETESIF:
1366 case ATM_GETSTAT:
1367 case ATM_GETSTATZ:
1368 case ATM_GETLOOP:
1369 case ATM_SETLOOP:
1370 case ATM_QUERYLOOP:
1371 return do_atmif_sioc(fd, cmd, arg);
1372 }
1373
1374 return -EINVAL;
1375}
1376
Adrian Bunk3ff6eec2008-01-24 22:16:20 +01001377static __used int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1379{
1380 return -EINVAL;
1381}
1382
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1384{
1385 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1386}
1387
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388/* Bluetooth ioctls */
1389#define HCIUARTSETPROTO _IOW('U', 200, int)
1390#define HCIUARTGETPROTO _IOR('U', 201, int)
1391
1392#define BNEPCONNADD _IOW('B', 200, int)
1393#define BNEPCONNDEL _IOW('B', 201, int)
1394#define BNEPGETCONNLIST _IOR('B', 210, int)
1395#define BNEPGETCONNINFO _IOR('B', 211, int)
1396
1397#define CMTPCONNADD _IOW('C', 200, int)
1398#define CMTPCONNDEL _IOW('C', 201, int)
1399#define CMTPGETCONNLIST _IOR('C', 210, int)
1400#define CMTPGETCONNINFO _IOR('C', 211, int)
1401
1402#define HIDPCONNADD _IOW('H', 200, int)
1403#define HIDPCONNDEL _IOW('H', 201, int)
1404#define HIDPGETCONNLIST _IOR('H', 210, int)
1405#define HIDPGETCONNINFO _IOR('H', 211, int)
1406
David Howells93614012006-09-30 20:45:40 +02001407#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408struct raw32_config_request
1409{
1410 compat_int_t raw_minor;
1411 __u64 block_major;
1412 __u64 block_minor;
1413} __attribute__((packed));
1414
1415static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1416{
1417 int ret;
1418
1419 if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
1420 return -EFAULT;
1421
1422 ret = __get_user(req->raw_minor, &user_req->raw_minor);
1423 ret |= __get_user(req->block_major, &user_req->block_major);
1424 ret |= __get_user(req->block_minor, &user_req->block_minor);
1425
1426 return ret ? -EFAULT : 0;
1427}
1428
1429static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
1430{
1431 int ret;
1432
1433 if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
1434 return -EFAULT;
1435
1436 ret = __put_user(req->raw_minor, &user_req->raw_minor);
1437 ret |= __put_user(req->block_major, &user_req->block_major);
1438 ret |= __put_user(req->block_minor, &user_req->block_minor);
1439
1440 return ret ? -EFAULT : 0;
1441}
1442
1443static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1444{
1445 int ret;
1446
1447 switch (cmd) {
1448 case RAW_SETBIND:
1449 case RAW_GETBIND: {
1450 struct raw_config_request req;
1451 struct raw32_config_request __user *user_req = compat_ptr(arg);
1452 mm_segment_t oldfs = get_fs();
1453
1454 if ((ret = get_raw32_request(&req, user_req)))
1455 return ret;
1456
1457 set_fs(KERNEL_DS);
1458 ret = sys_ioctl(fd,cmd,(unsigned long)&req);
1459 set_fs(oldfs);
1460
1461 if ((!ret) && (cmd == RAW_GETBIND)) {
1462 ret = set_raw32_request(&req, user_req);
1463 }
1464 break;
1465 }
1466 default:
1467 ret = sys_ioctl(fd, cmd, arg);
1468 break;
1469 }
1470 return ret;
1471}
David Howells93614012006-09-30 20:45:40 +02001472#endif /* CONFIG_BLOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474struct serial_struct32 {
1475 compat_int_t type;
1476 compat_int_t line;
1477 compat_uint_t port;
1478 compat_int_t irq;
1479 compat_int_t flags;
1480 compat_int_t xmit_fifo_size;
1481 compat_int_t custom_divisor;
1482 compat_int_t baud_base;
1483 unsigned short close_delay;
1484 char io_type;
1485 char reserved_char[1];
1486 compat_int_t hub6;
1487 unsigned short closing_wait; /* time to wait before closing */
1488 unsigned short closing_wait2; /* no longer used... */
1489 compat_uint_t iomem_base;
1490 unsigned short iomem_reg_shift;
1491 unsigned int port_high;
1492 /* compat_ulong_t iomap_base FIXME */
1493 compat_int_t reserved[1];
1494};
1495
1496static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1497{
1498 typedef struct serial_struct SS;
1499 typedef struct serial_struct32 SS32;
1500 struct serial_struct32 __user *ss32 = compat_ptr(arg);
1501 int err;
1502 struct serial_struct ss;
1503 mm_segment_t oldseg = get_fs();
1504 __u32 udata;
Heiko Carstens7116e992006-12-06 20:36:36 -08001505 unsigned int base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507 if (cmd == TIOCSSERIAL) {
1508 if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
1509 return -EFAULT;
1510 if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
1511 return -EFAULT;
Heiko Carstens7116e992006-12-06 20:36:36 -08001512 if (__get_user(udata, &ss32->iomem_base))
1513 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 ss.iomem_base = compat_ptr(udata);
Heiko Carstens7116e992006-12-06 20:36:36 -08001515 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
1516 __get_user(ss.port_high, &ss32->port_high))
1517 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 ss.iomap_base = 0UL;
1519 }
1520 set_fs(KERNEL_DS);
1521 err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
1522 set_fs(oldseg);
1523 if (cmd == TIOCGSERIAL && err >= 0) {
1524 if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
1525 return -EFAULT;
1526 if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
1527 return -EFAULT;
Heiko Carstens7116e992006-12-06 20:36:36 -08001528 base = (unsigned long)ss.iomem_base >> 32 ?
1529 0xffffffff : (unsigned)(unsigned long)ss.iomem_base;
1530 if (__put_user(base, &ss32->iomem_base) ||
1531 __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
1532 __put_user(ss.port_high, &ss32->port_high))
1533 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 }
1535 return err;
1536}
1537
1538struct usbdevfs_ctrltransfer32 {
1539 u8 bRequestType;
1540 u8 bRequest;
1541 u16 wValue;
1542 u16 wIndex;
1543 u16 wLength;
1544 u32 timeout; /* in milliseconds */
1545 compat_caddr_t data;
1546};
1547
1548#define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
1549
1550static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
1551{
1552 struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
1553 struct usbdevfs_ctrltransfer __user *p;
1554 __u32 udata;
1555 p = compat_alloc_user_space(sizeof(*p));
1556 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
1557 get_user(udata, &p32->data) ||
1558 put_user(compat_ptr(udata), &p->data))
1559 return -EFAULT;
1560 return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
1561}
1562
1563
1564struct usbdevfs_bulktransfer32 {
1565 compat_uint_t ep;
1566 compat_uint_t len;
1567 compat_uint_t timeout; /* in milliseconds */
1568 compat_caddr_t data;
1569};
1570
1571#define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
1572
1573static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
1574{
1575 struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
1576 struct usbdevfs_bulktransfer __user *p;
1577 compat_uint_t n;
1578 compat_caddr_t addr;
1579
1580 p = compat_alloc_user_space(sizeof(*p));
1581
1582 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
1583 get_user(n, &p32->len) || put_user(n, &p->len) ||
1584 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
1585 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
1586 return -EFAULT;
1587
1588 return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
1589}
1590
1591
1592/*
1593 * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
1594 * are handled in usbdevfs core. -Christopher Li
1595 */
1596
1597struct usbdevfs_disconnectsignal32 {
1598 compat_int_t signr;
1599 compat_caddr_t context;
1600};
1601
1602#define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
1603
1604static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
1605{
1606 struct usbdevfs_disconnectsignal kdis;
1607 struct usbdevfs_disconnectsignal32 __user *udis;
1608 mm_segment_t old_fs;
1609 u32 uctx;
1610 int err;
1611
1612 udis = compat_ptr(arg);
1613
1614 if (get_user(kdis.signr, &udis->signr) ||
1615 __get_user(uctx, &udis->context))
1616 return -EFAULT;
1617
1618 kdis.context = compat_ptr(uctx);
1619
1620 old_fs = get_fs();
1621 set_fs(KERNEL_DS);
1622 err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
1623 set_fs(old_fs);
1624
1625 return err;
1626}
1627
1628/*
1629 * I2C layer ioctls
1630 */
1631
1632struct i2c_msg32 {
1633 u16 addr;
1634 u16 flags;
1635 u16 len;
1636 compat_caddr_t buf;
1637};
1638
1639struct i2c_rdwr_ioctl_data32 {
1640 compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
1641 u32 nmsgs;
1642};
1643
1644struct i2c_smbus_ioctl_data32 {
1645 u8 read_write;
1646 u8 command;
1647 u32 size;
1648 compat_caddr_t data; /* union i2c_smbus_data *data */
1649};
1650
1651struct i2c_rdwr_aligned {
1652 struct i2c_rdwr_ioctl_data cmd;
1653 struct i2c_msg msgs[0];
1654};
1655
1656static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
1657{
1658 struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
1659 struct i2c_rdwr_aligned __user *tdata;
1660 struct i2c_msg __user *tmsgs;
1661 struct i2c_msg32 __user *umsgs;
1662 compat_caddr_t datap;
1663 int nmsgs, i;
1664
1665 if (get_user(nmsgs, &udata->nmsgs))
1666 return -EFAULT;
1667 if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
1668 return -EINVAL;
1669
1670 if (get_user(datap, &udata->msgs))
1671 return -EFAULT;
1672 umsgs = compat_ptr(datap);
1673
1674 tdata = compat_alloc_user_space(sizeof(*tdata) +
1675 nmsgs * sizeof(struct i2c_msg));
1676 tmsgs = &tdata->msgs[0];
1677
1678 if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
1679 put_user(tmsgs, &tdata->cmd.msgs))
1680 return -EFAULT;
1681
1682 for (i = 0; i < nmsgs; i++) {
1683 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
1684 return -EFAULT;
1685 if (get_user(datap, &umsgs[i].buf) ||
1686 put_user(compat_ptr(datap), &tmsgs[i].buf))
1687 return -EFAULT;
1688 }
1689 return sys_ioctl(fd, cmd, (unsigned long)tdata);
1690}
1691
1692static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
1693{
1694 struct i2c_smbus_ioctl_data __user *tdata;
1695 struct i2c_smbus_ioctl_data32 __user *udata;
1696 compat_caddr_t datap;
1697
1698 tdata = compat_alloc_user_space(sizeof(*tdata));
1699 if (tdata == NULL)
1700 return -ENOMEM;
1701 if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
1702 return -EFAULT;
1703
1704 udata = compat_ptr(arg);
1705 if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
1706 return -EFAULT;
1707
1708 if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
1709 return -EFAULT;
1710 if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
1711 return -EFAULT;
1712 if (__get_user(datap, &udata->data) ||
1713 __put_user(compat_ptr(datap), &tdata->data))
1714 return -EFAULT;
1715
1716 return sys_ioctl(fd, cmd, (unsigned long)tdata);
1717}
1718
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
1720 * for some operations; this forces use of the newer bridge-utils that
Thadeu Lima de Souza Cascardoab2274a2009-04-17 08:14:23 -03001721 * use compatible ioctls
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 */
1723static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
1724{
1725 u32 tmp;
1726
1727 if (get_user(tmp, (u32 __user *) arg))
1728 return -EFAULT;
1729 if (tmp == BRCTL_GET_VERSION)
1730 return BRCTL_VERSION + 1;
1731 return -EINVAL;
1732}
1733
Christoph Hellwigec3cad92006-01-09 20:52:11 -08001734#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
1735#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
1736#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
1737#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
1738
1739static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
1740{
1741 mm_segment_t oldfs = get_fs();
1742 compat_ulong_t val32;
1743 unsigned long kval;
1744 int ret;
1745
1746 switch (cmd) {
1747 case RTC_IRQP_READ32:
1748 case RTC_EPOCH_READ32:
1749 set_fs(KERNEL_DS);
1750 ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
1751 RTC_IRQP_READ : RTC_EPOCH_READ,
1752 (unsigned long)&kval);
1753 set_fs(oldfs);
1754 if (ret)
1755 return ret;
1756 val32 = kval;
1757 return put_user(val32, (unsigned int __user *)arg);
1758 case RTC_IRQP_SET32:
Andi Kleenfc5870f2006-02-26 04:18:55 +01001759 return sys_ioctl(fd, RTC_IRQP_SET, arg);
Christoph Hellwigec3cad92006-01-09 20:52:11 -08001760 case RTC_EPOCH_SET32:
Andi Kleenfc5870f2006-02-26 04:18:55 +01001761 return sys_ioctl(fd, RTC_EPOCH_SET, arg);
Christoph Hellwigec3cad92006-01-09 20:52:11 -08001762 default:
1763 /* unreached */
1764 return -ENOIOCTLCMD;
1765 }
1766}
1767
Andi Kleenc6b44d12006-01-12 01:05:26 -08001768static int
1769lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1770{
Al Viro6b2b4e52006-02-01 06:33:33 -05001771 struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
1772 struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
Andi Kleenc6b44d12006-01-12 01:05:26 -08001773 struct timeval ts;
1774 if (get_user(ts.tv_sec, &tc->tv_sec) ||
1775 get_user(ts.tv_usec, &tc->tv_usec) ||
1776 put_user(ts.tv_sec, &tn->tv_sec) ||
1777 put_user(ts.tv_usec, &tn->tv_usec))
1778 return -EFAULT;
1779 return sys_ioctl(fd, cmd, (unsigned long)tn);
1780}
1781
Christoph Hellwig6272e262007-05-08 00:29:21 -07001782
1783typedef int (*ioctl_trans_handler_t)(unsigned int, unsigned int,
1784 unsigned long, struct file *);
1785
1786struct ioctl_trans {
1787 unsigned long cmd;
1788 ioctl_trans_handler_t handler;
1789 struct ioctl_trans *next;
1790};
1791
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08001792#define HANDLE_IOCTL(cmd,handler) \
1793 { (cmd), (ioctl_trans_handler_t)(handler) },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08001795/* pointer to compatible structure or no argument */
1796#define COMPATIBLE_IOCTL(cmd) \
1797 { (cmd), do_ioctl32_pointer },
1798
1799/* argument is an unsigned long integer, not a pointer */
1800#define ULONG_IOCTL(cmd) \
1801 { (cmd), (ioctl_trans_handler_t)sys_ioctl },
1802
Andi Kleen421f0282007-05-02 19:27:20 +02001803/* ioctl should not be warned about even if it's not implemented.
1804 Valid reasons to use this:
1805 - It is implemented with ->compat_ioctl on some device, but programs
1806 call it on others too.
1807 - The ioctl is not implemented in the native kernel, but programs
1808 call it commonly anyways.
1809 Most other reasons are not valid. */
1810#define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08001811
Christoph Hellwig6272e262007-05-08 00:29:21 -07001812static struct ioctl_trans ioctl_start[] = {
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001813/* compatible ioctls first */
1814COMPATIBLE_IOCTL(0x4B50) /* KDGHWCLK - not in the kernel, but don't complain */
1815COMPATIBLE_IOCTL(0x4B51) /* KDSHWCLK - not in the kernel, but don't complain */
1816
1817/* Big T */
1818COMPATIBLE_IOCTL(TCGETA)
1819COMPATIBLE_IOCTL(TCSETA)
1820COMPATIBLE_IOCTL(TCSETAW)
1821COMPATIBLE_IOCTL(TCSETAF)
1822COMPATIBLE_IOCTL(TCSBRK)
1823ULONG_IOCTL(TCSBRKP)
1824COMPATIBLE_IOCTL(TCXONC)
1825COMPATIBLE_IOCTL(TCFLSH)
1826COMPATIBLE_IOCTL(TCGETS)
1827COMPATIBLE_IOCTL(TCSETS)
1828COMPATIBLE_IOCTL(TCSETSW)
1829COMPATIBLE_IOCTL(TCSETSF)
1830COMPATIBLE_IOCTL(TIOCLINUX)
1831COMPATIBLE_IOCTL(TIOCSBRK)
1832COMPATIBLE_IOCTL(TIOCCBRK)
1833ULONG_IOCTL(TIOCMIWAIT)
1834COMPATIBLE_IOCTL(TIOCGICOUNT)
1835/* Little t */
1836COMPATIBLE_IOCTL(TIOCGETD)
1837COMPATIBLE_IOCTL(TIOCSETD)
1838COMPATIBLE_IOCTL(TIOCEXCL)
1839COMPATIBLE_IOCTL(TIOCNXCL)
1840COMPATIBLE_IOCTL(TIOCCONS)
1841COMPATIBLE_IOCTL(TIOCGSOFTCAR)
1842COMPATIBLE_IOCTL(TIOCSSOFTCAR)
1843COMPATIBLE_IOCTL(TIOCSWINSZ)
1844COMPATIBLE_IOCTL(TIOCGWINSZ)
1845COMPATIBLE_IOCTL(TIOCMGET)
1846COMPATIBLE_IOCTL(TIOCMBIC)
1847COMPATIBLE_IOCTL(TIOCMBIS)
1848COMPATIBLE_IOCTL(TIOCMSET)
1849COMPATIBLE_IOCTL(TIOCPKT)
1850COMPATIBLE_IOCTL(TIOCNOTTY)
1851COMPATIBLE_IOCTL(TIOCSTI)
1852COMPATIBLE_IOCTL(TIOCOUTQ)
1853COMPATIBLE_IOCTL(TIOCSPGRP)
1854COMPATIBLE_IOCTL(TIOCGPGRP)
1855ULONG_IOCTL(TIOCSCTTY)
1856COMPATIBLE_IOCTL(TIOCGPTN)
1857COMPATIBLE_IOCTL(TIOCSPTLCK)
1858COMPATIBLE_IOCTL(TIOCSERGETLSR)
Heiko Carstens81257de2007-11-28 16:22:07 -08001859#ifdef TCGETS2
1860COMPATIBLE_IOCTL(TCGETS2)
1861COMPATIBLE_IOCTL(TCSETS2)
1862COMPATIBLE_IOCTL(TCSETSW2)
1863COMPATIBLE_IOCTL(TCSETSF2)
1864#endif
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001865/* Little f */
1866COMPATIBLE_IOCTL(FIOCLEX)
1867COMPATIBLE_IOCTL(FIONCLEX)
1868COMPATIBLE_IOCTL(FIOASYNC)
1869COMPATIBLE_IOCTL(FIONBIO)
1870COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */
1871/* 0x00 */
1872COMPATIBLE_IOCTL(FIBMAP)
1873COMPATIBLE_IOCTL(FIGETBSZ)
Christoph Hellwig5cf8cf42009-02-26 21:32:51 +01001874/* 'X' - originally XFS but some now in the VFS */
1875COMPATIBLE_IOCTL(FIFREEZE)
1876COMPATIBLE_IOCTL(FITHAW)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001877/* RAID */
1878COMPATIBLE_IOCTL(RAID_VERSION)
1879COMPATIBLE_IOCTL(GET_ARRAY_INFO)
1880COMPATIBLE_IOCTL(GET_DISK_INFO)
1881COMPATIBLE_IOCTL(PRINT_RAID_DEBUG)
1882COMPATIBLE_IOCTL(RAID_AUTORUN)
1883COMPATIBLE_IOCTL(CLEAR_ARRAY)
1884COMPATIBLE_IOCTL(ADD_NEW_DISK)
1885ULONG_IOCTL(HOT_REMOVE_DISK)
1886COMPATIBLE_IOCTL(SET_ARRAY_INFO)
1887COMPATIBLE_IOCTL(SET_DISK_INFO)
1888COMPATIBLE_IOCTL(WRITE_RAID_INFO)
1889COMPATIBLE_IOCTL(UNPROTECT_ARRAY)
1890COMPATIBLE_IOCTL(PROTECT_ARRAY)
1891ULONG_IOCTL(HOT_ADD_DISK)
1892ULONG_IOCTL(SET_DISK_FAULTY)
1893COMPATIBLE_IOCTL(RUN_ARRAY)
1894COMPATIBLE_IOCTL(STOP_ARRAY)
1895COMPATIBLE_IOCTL(STOP_ARRAY_RO)
1896COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
1897COMPATIBLE_IOCTL(GET_BITMAP_FILE)
1898ULONG_IOCTL(SET_BITMAP_FILE)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001899/* Big K */
1900COMPATIBLE_IOCTL(PIO_FONT)
1901COMPATIBLE_IOCTL(GIO_FONT)
Bill Nottingham2db69a92009-02-18 14:48:39 -08001902COMPATIBLE_IOCTL(PIO_CMAP)
1903COMPATIBLE_IOCTL(GIO_CMAP)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001904ULONG_IOCTL(KDSIGACCEPT)
1905COMPATIBLE_IOCTL(KDGETKEYCODE)
1906COMPATIBLE_IOCTL(KDSETKEYCODE)
1907ULONG_IOCTL(KIOCSOUND)
1908ULONG_IOCTL(KDMKTONE)
1909COMPATIBLE_IOCTL(KDGKBTYPE)
1910ULONG_IOCTL(KDSETMODE)
1911COMPATIBLE_IOCTL(KDGETMODE)
1912ULONG_IOCTL(KDSKBMODE)
1913COMPATIBLE_IOCTL(KDGKBMODE)
1914ULONG_IOCTL(KDSKBMETA)
1915COMPATIBLE_IOCTL(KDGKBMETA)
1916COMPATIBLE_IOCTL(KDGKBENT)
1917COMPATIBLE_IOCTL(KDSKBENT)
1918COMPATIBLE_IOCTL(KDGKBSENT)
1919COMPATIBLE_IOCTL(KDSKBSENT)
1920COMPATIBLE_IOCTL(KDGKBDIACR)
1921COMPATIBLE_IOCTL(KDSKBDIACR)
1922COMPATIBLE_IOCTL(KDKBDREP)
1923COMPATIBLE_IOCTL(KDGKBLED)
1924ULONG_IOCTL(KDSKBLED)
1925COMPATIBLE_IOCTL(KDGETLED)
1926ULONG_IOCTL(KDSETLED)
1927COMPATIBLE_IOCTL(GIO_SCRNMAP)
1928COMPATIBLE_IOCTL(PIO_SCRNMAP)
1929COMPATIBLE_IOCTL(GIO_UNISCRNMAP)
1930COMPATIBLE_IOCTL(PIO_UNISCRNMAP)
1931COMPATIBLE_IOCTL(PIO_FONTRESET)
1932COMPATIBLE_IOCTL(PIO_UNIMAPCLR)
Randy Dunlap3c3622d2008-07-16 08:52:00 -05001933#ifdef CONFIG_BLOCK
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001934/* Big S */
1935COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
1936COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
1937COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
1938COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
1939COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
1940COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
1941COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
1942COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
Randy Dunlap3c3622d2008-07-16 08:52:00 -05001943#endif
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001944/* Big T */
1945COMPATIBLE_IOCTL(TUNSETNOCSUM)
1946COMPATIBLE_IOCTL(TUNSETDEBUG)
1947COMPATIBLE_IOCTL(TUNSETPERSIST)
1948COMPATIBLE_IOCTL(TUNSETOWNER)
David S. Millerdf1c46b2009-01-29 16:53:35 -08001949COMPATIBLE_IOCTL(TUNSETLINK)
1950COMPATIBLE_IOCTL(TUNSETGROUP)
1951COMPATIBLE_IOCTL(TUNGETFEATURES)
1952COMPATIBLE_IOCTL(TUNSETOFFLOAD)
1953COMPATIBLE_IOCTL(TUNSETTXFILTER)
Herbert Xu33dccbb2009-02-05 21:25:32 -08001954COMPATIBLE_IOCTL(TUNGETSNDBUF)
1955COMPATIBLE_IOCTL(TUNSETSNDBUF)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07001956/* Big V */
1957COMPATIBLE_IOCTL(VT_SETMODE)
1958COMPATIBLE_IOCTL(VT_GETMODE)
1959COMPATIBLE_IOCTL(VT_GETSTATE)
1960COMPATIBLE_IOCTL(VT_OPENQRY)
1961ULONG_IOCTL(VT_ACTIVATE)
1962ULONG_IOCTL(VT_WAITACTIVE)
1963ULONG_IOCTL(VT_RELDISP)
1964ULONG_IOCTL(VT_DISALLOCATE)
1965COMPATIBLE_IOCTL(VT_RESIZE)
1966COMPATIBLE_IOCTL(VT_RESIZEX)
1967COMPATIBLE_IOCTL(VT_LOCKSWITCH)
1968COMPATIBLE_IOCTL(VT_UNLOCKSWITCH)
1969COMPATIBLE_IOCTL(VT_GETHIFONTMASK)
1970/* Little p (/dev/rtc, /dev/envctrl, etc.) */
1971COMPATIBLE_IOCTL(RTC_AIE_ON)
1972COMPATIBLE_IOCTL(RTC_AIE_OFF)
1973COMPATIBLE_IOCTL(RTC_UIE_ON)
1974COMPATIBLE_IOCTL(RTC_UIE_OFF)
1975COMPATIBLE_IOCTL(RTC_PIE_ON)
1976COMPATIBLE_IOCTL(RTC_PIE_OFF)
1977COMPATIBLE_IOCTL(RTC_WIE_ON)
1978COMPATIBLE_IOCTL(RTC_WIE_OFF)
1979COMPATIBLE_IOCTL(RTC_ALM_SET)
1980COMPATIBLE_IOCTL(RTC_ALM_READ)
1981COMPATIBLE_IOCTL(RTC_RD_TIME)
1982COMPATIBLE_IOCTL(RTC_SET_TIME)
1983COMPATIBLE_IOCTL(RTC_WKALM_SET)
1984COMPATIBLE_IOCTL(RTC_WKALM_RD)
1985/*
1986 * These two are only for the sbus rtc driver, but
1987 * hwclock tries them on every rtc device first when
1988 * running on sparc. On other architectures the entries
1989 * are useless but harmless.
1990 */
1991COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
1992COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
1993/* Little m */
1994COMPATIBLE_IOCTL(MTIOCTOP)
1995/* Socket level stuff */
1996COMPATIBLE_IOCTL(FIOQSIZE)
1997COMPATIBLE_IOCTL(FIOSETOWN)
1998COMPATIBLE_IOCTL(SIOCSPGRP)
1999COMPATIBLE_IOCTL(FIOGETOWN)
2000COMPATIBLE_IOCTL(SIOCGPGRP)
2001COMPATIBLE_IOCTL(SIOCATMARK)
2002COMPATIBLE_IOCTL(SIOCSIFLINK)
2003COMPATIBLE_IOCTL(SIOCSIFENCAP)
2004COMPATIBLE_IOCTL(SIOCGIFENCAP)
2005COMPATIBLE_IOCTL(SIOCSIFNAME)
2006COMPATIBLE_IOCTL(SIOCSARP)
2007COMPATIBLE_IOCTL(SIOCGARP)
2008COMPATIBLE_IOCTL(SIOCDARP)
2009COMPATIBLE_IOCTL(SIOCSRARP)
2010COMPATIBLE_IOCTL(SIOCGRARP)
2011COMPATIBLE_IOCTL(SIOCDRARP)
2012COMPATIBLE_IOCTL(SIOCADDDLCI)
2013COMPATIBLE_IOCTL(SIOCDELDLCI)
2014COMPATIBLE_IOCTL(SIOCGMIIPHY)
2015COMPATIBLE_IOCTL(SIOCGMIIREG)
2016COMPATIBLE_IOCTL(SIOCSMIIREG)
2017COMPATIBLE_IOCTL(SIOCGIFVLAN)
2018COMPATIBLE_IOCTL(SIOCSIFVLAN)
2019COMPATIBLE_IOCTL(SIOCBRADDBR)
2020COMPATIBLE_IOCTL(SIOCBRDELBR)
Randy Dunlap3c3622d2008-07-16 08:52:00 -05002021#ifdef CONFIG_BLOCK
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002022/* SG stuff */
2023COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
2024COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
2025COMPATIBLE_IOCTL(SG_EMULATED_HOST)
2026ULONG_IOCTL(SG_SET_TRANSFORM)
2027COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
2028COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
2029COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
2030COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
2031COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
2032COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
2033COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
2034COMPATIBLE_IOCTL(SG_GET_PACK_ID)
2035COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
2036COMPATIBLE_IOCTL(SG_SET_DEBUG)
2037COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
2038COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
2039COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
2040COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
2041COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
2042COMPATIBLE_IOCTL(SG_SCSI_RESET)
2043COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
2044COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
2045COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
Randy Dunlap3c3622d2008-07-16 08:52:00 -05002046#endif
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002047/* PPP stuff */
2048COMPATIBLE_IOCTL(PPPIOCGFLAGS)
2049COMPATIBLE_IOCTL(PPPIOCSFLAGS)
2050COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
2051COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
2052COMPATIBLE_IOCTL(PPPIOCGUNIT)
2053COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
2054COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
2055COMPATIBLE_IOCTL(PPPIOCGMRU)
2056COMPATIBLE_IOCTL(PPPIOCSMRU)
2057COMPATIBLE_IOCTL(PPPIOCSMAXCID)
2058COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
2059COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
2060COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
2061/* PPPIOCSCOMPRESS is translated */
2062COMPATIBLE_IOCTL(PPPIOCGNPMODE)
2063COMPATIBLE_IOCTL(PPPIOCSNPMODE)
2064COMPATIBLE_IOCTL(PPPIOCGDEBUG)
2065COMPATIBLE_IOCTL(PPPIOCSDEBUG)
2066/* PPPIOCSPASS is translated */
2067/* PPPIOCSACTIVE is translated */
2068/* PPPIOCGIDLE is translated */
2069COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
2070COMPATIBLE_IOCTL(PPPIOCATTACH)
2071COMPATIBLE_IOCTL(PPPIOCDETACH)
2072COMPATIBLE_IOCTL(PPPIOCSMRRU)
2073COMPATIBLE_IOCTL(PPPIOCCONNECT)
2074COMPATIBLE_IOCTL(PPPIOCDISCONN)
2075COMPATIBLE_IOCTL(PPPIOCATTCHAN)
2076COMPATIBLE_IOCTL(PPPIOCGCHAN)
2077/* PPPOX */
2078COMPATIBLE_IOCTL(PPPOEIOCSFWD)
2079COMPATIBLE_IOCTL(PPPOEIOCDFWD)
2080/* LP */
2081COMPATIBLE_IOCTL(LPGETSTATUS)
2082/* ppdev */
2083COMPATIBLE_IOCTL(PPSETMODE)
2084COMPATIBLE_IOCTL(PPRSTATUS)
2085COMPATIBLE_IOCTL(PPRCONTROL)
2086COMPATIBLE_IOCTL(PPWCONTROL)
2087COMPATIBLE_IOCTL(PPFCONTROL)
2088COMPATIBLE_IOCTL(PPRDATA)
2089COMPATIBLE_IOCTL(PPWDATA)
2090COMPATIBLE_IOCTL(PPCLAIM)
2091COMPATIBLE_IOCTL(PPRELEASE)
2092COMPATIBLE_IOCTL(PPYIELD)
2093COMPATIBLE_IOCTL(PPEXCL)
2094COMPATIBLE_IOCTL(PPDATADIR)
2095COMPATIBLE_IOCTL(PPNEGOT)
2096COMPATIBLE_IOCTL(PPWCTLONIRQ)
2097COMPATIBLE_IOCTL(PPCLRIRQ)
2098COMPATIBLE_IOCTL(PPSETPHASE)
2099COMPATIBLE_IOCTL(PPGETMODES)
2100COMPATIBLE_IOCTL(PPGETMODE)
2101COMPATIBLE_IOCTL(PPGETPHASE)
2102COMPATIBLE_IOCTL(PPGETFLAGS)
2103COMPATIBLE_IOCTL(PPSETFLAGS)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002104/* pktcdvd */
2105COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
2106/* Big A */
2107/* sparc only */
2108/* Big Q for sound/OSS */
2109COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
2110COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
2111COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
2112COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
2113COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
2114COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
2115COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
2116COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
2117COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
2118COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
2119COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
2120COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
2121COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
2122COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
2123COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
2124COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
2125COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
2126COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
2127COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
2128COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
2129COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
2130COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
2131/* Big T for sound/OSS */
2132COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
2133COMPATIBLE_IOCTL(SNDCTL_TMR_START)
2134COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
2135COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
2136COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
2137COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
2138COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
2139COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
2140/* Little m for sound/OSS */
2141COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
2142COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
2143COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
2144/* Big P for sound/OSS */
2145COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
2146COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
2147COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
2148COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
2149COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
2150COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
2151COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
2152COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
2153COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
2154COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
2155COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
2156COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
2157COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
2158COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
2159COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
2160COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
2161COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
2162COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
2163COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
2164COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
2165/* SNDCTL_DSP_MAPINBUF, XXX needs translation */
2166/* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */
2167COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
2168COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
2169COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
2170COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
2171COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
2172COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
2173COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
2174COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
2175/* Big C for sound/OSS */
2176COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
2177COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
2178COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
2179COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
2180COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
2181COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
2182COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
2183COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
2184COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
2185COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
2186/* Big M for sound/OSS */
2187COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
2188COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
2189COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
2190COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
2191COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
2192COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
2193COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
2194COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
2195COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
2196COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
2197COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
2198COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
2199COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
2200COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
2201COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
2202COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
2203COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
2204COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
2205COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
2206COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
2207COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
2208COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
2209COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
2210COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
2211COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
2212COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
2213/* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */
2214/* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */
2215COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
2216COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
2217COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
2218COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
2219COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
2220COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
2221COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
2222COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
2223COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
2224COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
2225COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
2226COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
2227COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
2228COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
2229COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
2230COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
2231COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
2232COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
2233COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
2234COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
2235COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
2236COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
2237COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
2238COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
2239COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
2240COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
2241COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
2242COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
2243COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
2244COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
2245COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
2246/* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */
2247/* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */
2248COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
2249COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
2250COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
2251COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
2252COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
2253COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
2254COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
2255COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
2256COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
2257COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
2258COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
2259COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
2260COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
2261COMPATIBLE_IOCTL(OSS_GETVERSION)
2262/* AUTOFS */
2263ULONG_IOCTL(AUTOFS_IOC_READY)
2264ULONG_IOCTL(AUTOFS_IOC_FAIL)
2265COMPATIBLE_IOCTL(AUTOFS_IOC_CATATONIC)
2266COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
2267COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
2268COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
2269COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002270COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
2271/* Raw devices */
2272COMPATIBLE_IOCTL(RAW_SETBIND)
2273COMPATIBLE_IOCTL(RAW_GETBIND)
2274/* SMB ioctls which do not need any translations */
2275COMPATIBLE_IOCTL(SMB_IOC_NEWCONN)
2276/* Little a */
2277COMPATIBLE_IOCTL(ATMSIGD_CTRL)
2278COMPATIBLE_IOCTL(ATMARPD_CTRL)
2279COMPATIBLE_IOCTL(ATMLEC_CTRL)
2280COMPATIBLE_IOCTL(ATMLEC_MCAST)
2281COMPATIBLE_IOCTL(ATMLEC_DATA)
2282COMPATIBLE_IOCTL(ATM_SETSC)
2283COMPATIBLE_IOCTL(SIOCSIFATMTCP)
2284COMPATIBLE_IOCTL(SIOCMKCLIP)
2285COMPATIBLE_IOCTL(ATMARP_MKIP)
2286COMPATIBLE_IOCTL(ATMARP_SETENTRY)
2287COMPATIBLE_IOCTL(ATMARP_ENCAP)
2288COMPATIBLE_IOCTL(ATMTCP_CREATE)
2289COMPATIBLE_IOCTL(ATMTCP_REMOVE)
2290COMPATIBLE_IOCTL(ATMMPC_CTRL)
2291COMPATIBLE_IOCTL(ATMMPC_DATA)
2292/* Watchdog */
2293COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
2294COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
2295COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
2296COMPATIBLE_IOCTL(WDIOC_GETTEMP)
2297COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
2298COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
2299COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
2300COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
2301/* Big R */
2302COMPATIBLE_IOCTL(RNDGETENTCNT)
2303COMPATIBLE_IOCTL(RNDADDTOENTCNT)
2304COMPATIBLE_IOCTL(RNDGETPOOL)
2305COMPATIBLE_IOCTL(RNDADDENTROPY)
2306COMPATIBLE_IOCTL(RNDZAPENTCNT)
2307COMPATIBLE_IOCTL(RNDCLEARPOOL)
2308/* Bluetooth */
2309COMPATIBLE_IOCTL(HCIDEVUP)
2310COMPATIBLE_IOCTL(HCIDEVDOWN)
2311COMPATIBLE_IOCTL(HCIDEVRESET)
2312COMPATIBLE_IOCTL(HCIDEVRESTAT)
2313COMPATIBLE_IOCTL(HCIGETDEVLIST)
2314COMPATIBLE_IOCTL(HCIGETDEVINFO)
2315COMPATIBLE_IOCTL(HCIGETCONNLIST)
2316COMPATIBLE_IOCTL(HCIGETCONNINFO)
Marcel Holtmann40be4922008-07-14 20:13:50 +02002317COMPATIBLE_IOCTL(HCIGETAUTHINFO)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002318COMPATIBLE_IOCTL(HCISETRAW)
2319COMPATIBLE_IOCTL(HCISETSCAN)
2320COMPATIBLE_IOCTL(HCISETAUTH)
2321COMPATIBLE_IOCTL(HCISETENCRYPT)
2322COMPATIBLE_IOCTL(HCISETPTYPE)
2323COMPATIBLE_IOCTL(HCISETLINKPOL)
2324COMPATIBLE_IOCTL(HCISETLINKMODE)
2325COMPATIBLE_IOCTL(HCISETACLMTU)
2326COMPATIBLE_IOCTL(HCISETSCOMTU)
2327COMPATIBLE_IOCTL(HCIINQUIRY)
2328COMPATIBLE_IOCTL(HCIUARTSETPROTO)
2329COMPATIBLE_IOCTL(HCIUARTGETPROTO)
2330COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
2331COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
2332COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
2333COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
2334COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
2335COMPATIBLE_IOCTL(BNEPCONNADD)
2336COMPATIBLE_IOCTL(BNEPCONNDEL)
2337COMPATIBLE_IOCTL(BNEPGETCONNLIST)
2338COMPATIBLE_IOCTL(BNEPGETCONNINFO)
2339COMPATIBLE_IOCTL(CMTPCONNADD)
2340COMPATIBLE_IOCTL(CMTPCONNDEL)
2341COMPATIBLE_IOCTL(CMTPGETCONNLIST)
2342COMPATIBLE_IOCTL(CMTPGETCONNINFO)
2343COMPATIBLE_IOCTL(HIDPCONNADD)
2344COMPATIBLE_IOCTL(HIDPCONNDEL)
2345COMPATIBLE_IOCTL(HIDPGETCONNLIST)
2346COMPATIBLE_IOCTL(HIDPGETCONNINFO)
2347/* CAPI */
2348COMPATIBLE_IOCTL(CAPI_REGISTER)
2349COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
2350COMPATIBLE_IOCTL(CAPI_GET_VERSION)
2351COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
2352COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
2353COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
2354COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
2355COMPATIBLE_IOCTL(CAPI_INSTALLED)
2356COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
2357COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
2358COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
2359COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
2360COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
2361/* Siemens Gigaset */
2362COMPATIBLE_IOCTL(GIGASET_REDIR)
2363COMPATIBLE_IOCTL(GIGASET_CONFIG)
2364COMPATIBLE_IOCTL(GIGASET_BRKCHARS)
2365COMPATIBLE_IOCTL(GIGASET_VERSION)
2366/* Misc. */
2367COMPATIBLE_IOCTL(0x41545900) /* ATYIO_CLKR */
2368COMPATIBLE_IOCTL(0x41545901) /* ATYIO_CLKW */
2369COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
2370COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
2371COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
2372COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
2373/* USB */
2374COMPATIBLE_IOCTL(USBDEVFS_RESETEP)
2375COMPATIBLE_IOCTL(USBDEVFS_SETINTERFACE)
2376COMPATIBLE_IOCTL(USBDEVFS_SETCONFIGURATION)
2377COMPATIBLE_IOCTL(USBDEVFS_GETDRIVER)
2378COMPATIBLE_IOCTL(USBDEVFS_DISCARDURB)
2379COMPATIBLE_IOCTL(USBDEVFS_CLAIMINTERFACE)
2380COMPATIBLE_IOCTL(USBDEVFS_RELEASEINTERFACE)
2381COMPATIBLE_IOCTL(USBDEVFS_CONNECTINFO)
2382COMPATIBLE_IOCTL(USBDEVFS_HUB_PORTINFO)
2383COMPATIBLE_IOCTL(USBDEVFS_RESET)
2384COMPATIBLE_IOCTL(USBDEVFS_SUBMITURB32)
2385COMPATIBLE_IOCTL(USBDEVFS_REAPURB32)
2386COMPATIBLE_IOCTL(USBDEVFS_REAPURBNDELAY32)
2387COMPATIBLE_IOCTL(USBDEVFS_CLEAR_HALT)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002388/* NBD */
2389ULONG_IOCTL(NBD_SET_SOCK)
2390ULONG_IOCTL(NBD_SET_BLKSIZE)
2391ULONG_IOCTL(NBD_SET_SIZE)
2392COMPATIBLE_IOCTL(NBD_DO_IT)
2393COMPATIBLE_IOCTL(NBD_CLEAR_SOCK)
2394COMPATIBLE_IOCTL(NBD_CLEAR_QUE)
2395COMPATIBLE_IOCTL(NBD_PRINT_DEBUG)
2396ULONG_IOCTL(NBD_SET_SIZE_BLOCKS)
2397COMPATIBLE_IOCTL(NBD_DISCONNECT)
2398/* i2c */
2399COMPATIBLE_IOCTL(I2C_SLAVE)
2400COMPATIBLE_IOCTL(I2C_SLAVE_FORCE)
2401COMPATIBLE_IOCTL(I2C_TENBIT)
2402COMPATIBLE_IOCTL(I2C_PEC)
2403COMPATIBLE_IOCTL(I2C_RETRIES)
2404COMPATIBLE_IOCTL(I2C_TIMEOUT)
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002405/* hiddev */
2406COMPATIBLE_IOCTL(HIDIOCGVERSION)
2407COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
2408COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
2409COMPATIBLE_IOCTL(HIDIOCGSTRING)
2410COMPATIBLE_IOCTL(HIDIOCINITREPORT)
2411COMPATIBLE_IOCTL(HIDIOCGREPORT)
2412COMPATIBLE_IOCTL(HIDIOCSREPORT)
2413COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
2414COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
2415COMPATIBLE_IOCTL(HIDIOCGUSAGE)
2416COMPATIBLE_IOCTL(HIDIOCSUSAGE)
2417COMPATIBLE_IOCTL(HIDIOCGUCODE)
2418COMPATIBLE_IOCTL(HIDIOCGFLAG)
2419COMPATIBLE_IOCTL(HIDIOCSFLAG)
2420COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
2421COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
2422/* dvb */
2423COMPATIBLE_IOCTL(AUDIO_STOP)
2424COMPATIBLE_IOCTL(AUDIO_PLAY)
2425COMPATIBLE_IOCTL(AUDIO_PAUSE)
2426COMPATIBLE_IOCTL(AUDIO_CONTINUE)
2427COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
2428COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
2429COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
2430COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
2431COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
2432COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
2433COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
2434COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
2435COMPATIBLE_IOCTL(AUDIO_SET_ID)
2436COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
2437COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
2438COMPATIBLE_IOCTL(AUDIO_SET_EXT_ID)
2439COMPATIBLE_IOCTL(AUDIO_SET_ATTRIBUTES)
2440COMPATIBLE_IOCTL(AUDIO_SET_KARAOKE)
2441COMPATIBLE_IOCTL(DMX_START)
2442COMPATIBLE_IOCTL(DMX_STOP)
2443COMPATIBLE_IOCTL(DMX_SET_FILTER)
2444COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
2445COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
2446COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
2447COMPATIBLE_IOCTL(DMX_GET_CAPS)
2448COMPATIBLE_IOCTL(DMX_SET_SOURCE)
2449COMPATIBLE_IOCTL(DMX_GET_STC)
2450COMPATIBLE_IOCTL(FE_GET_INFO)
2451COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
2452COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
2453COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
2454COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
2455COMPATIBLE_IOCTL(FE_SET_TONE)
2456COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
2457COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
2458COMPATIBLE_IOCTL(FE_READ_STATUS)
2459COMPATIBLE_IOCTL(FE_READ_BER)
2460COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
2461COMPATIBLE_IOCTL(FE_READ_SNR)
2462COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
2463COMPATIBLE_IOCTL(FE_SET_FRONTEND)
2464COMPATIBLE_IOCTL(FE_GET_FRONTEND)
2465COMPATIBLE_IOCTL(FE_GET_EVENT)
2466COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
2467COMPATIBLE_IOCTL(VIDEO_STOP)
2468COMPATIBLE_IOCTL(VIDEO_PLAY)
2469COMPATIBLE_IOCTL(VIDEO_FREEZE)
2470COMPATIBLE_IOCTL(VIDEO_CONTINUE)
2471COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
2472COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
2473COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
2474COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
2475COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
2476COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
2477COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
2478COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
2479COMPATIBLE_IOCTL(VIDEO_SET_ID)
2480COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
2481COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
2482COMPATIBLE_IOCTL(VIDEO_SET_SYSTEM)
2483COMPATIBLE_IOCTL(VIDEO_SET_HIGHLIGHT)
2484COMPATIBLE_IOCTL(VIDEO_SET_SPU)
2485COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
2486COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
2487COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
2488COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
2489
Akos Maroy3fee37c2008-01-06 11:15:55 +01002490/* joystick */
2491COMPATIBLE_IOCTL(JSIOCGVERSION)
2492COMPATIBLE_IOCTL(JSIOCGAXES)
2493COMPATIBLE_IOCTL(JSIOCGBUTTONS)
2494COMPATIBLE_IOCTL(JSIOCGNAME(0))
2495
Christoph Hellwig644fd4f2007-05-08 00:29:07 -07002496/* now things that need handlers */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497#ifdef CONFIG_NET
2498HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
2499HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
2500HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
2501HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
2502HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
2503HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
2504HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
2505HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
2506HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
2507HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
2508HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
2509HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
2510HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
2511HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
2512HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
2513HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
2514HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2515HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2516HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
Andi Kleen67fd44f2006-12-07 02:14:03 +01002517HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
Patrick Ohlyd24fff22009-02-12 05:03:40 +00002518HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
2520/* ioctls used by appletalk ddp.c */
2521HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
2522HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
2523HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
2524HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
2525
2526HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
2527HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
2528HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
2529HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
2530HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
2531HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
2532HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
2533HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
2534HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
2535HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
2536HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
David S. Millerdf1c46b2009-01-29 16:53:35 -08002537HANDLE_IOCTL(TUNGETIFF, dev_ifsioc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
2539HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
2540HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
2541HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
2542HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
2543HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
2544HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
2545HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
2546HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
2547HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
2548HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
2549/* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
2550HANDLE_IOCTL(SIOCRTMSG, ret_einval)
2551HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
Eric Dumazetae40eb12007-03-18 17:33:16 -07002552HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553#endif
David Howells93614012006-09-30 20:45:40 +02002554#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
Andi Kleen29663872006-01-11 22:44:03 +01002556HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
David Howells93614012006-09-30 20:45:40 +02002557#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
2559HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
2560HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
2561HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
David Howells93614012006-09-30 20:45:40 +02002562#ifdef CONFIG_BLOCK
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
2564HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
David Howells93614012006-09-30 20:45:40 +02002565#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
2567HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
2568#ifdef CONFIG_VT
2569HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
2570HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
2571HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
2572HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
2573HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
2574#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575/* One SMB ioctl needs translations. */
2576#define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
2577HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
2578HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
2579HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
2580HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
2581HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
2582HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
2583HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
2584HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
2585HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
2586HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
2587HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
2588HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
2589HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
2590HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
2591HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
2592HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
2593HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
2594HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
2595HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
2596HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
2597HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
2598HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
2599HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
2600HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
2601HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
2602HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
2603/* block stuff */
David Howells93614012006-09-30 20:45:40 +02002604#ifdef CONFIG_BLOCK
Alexander Beregalov1ba0c7d2009-04-20 12:23:02 +04002605/* loop */
2606IGNORE_IOCTL(LOOP_CLR_FD)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607/* Raw devices */
2608HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
2609HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
David Howells93614012006-09-30 20:45:40 +02002610#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611/* Serial */
2612HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
2613HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
Christoph Hellwig9c0cbd52005-10-30 15:01:41 -08002614#ifdef TIOCGLTC
2615COMPATIBLE_IOCTL(TIOCGLTC)
2616COMPATIBLE_IOCTL(TIOCSLTC)
2617#endif
Christoph Hellwig7a81e312005-11-08 21:35:07 -08002618#ifdef TIOCSTART
2619/*
2620 * For these two we have defintions in ioctls.h and/or termios.h on
2621 * some architectures but no actual implemention. Some applications
2622 * like bash call them if they are defined in the headers, so we provide
2623 * entries here to avoid syslog message spew.
2624 */
2625COMPATIBLE_IOCTL(TIOCSTART)
2626COMPATIBLE_IOCTL(TIOCSTOP)
2627#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628/* Usbdevfs */
2629HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
2630HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
2631HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
Pete Zaitcevc36fc882005-10-17 18:15:54 -07002632COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633/* i2c */
2634HANDLE_IOCTL(I2C_FUNCS, w_long)
2635HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
2636HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
David S. Miller169a3ec2007-12-21 03:55:13 -08002637/* bridge */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
2639HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
Andi Kleen9d016dd2007-05-02 19:27:20 +02002640/* Not implemented in the native kernel */
2641IGNORE_IOCTL(SIOCGIFCOUNT)
Christoph Hellwigec3cad92006-01-09 20:52:11 -08002642HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
2643HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
2644HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
2645HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
David S. Miller6e87abd2005-11-16 00:52:57 -08002647/* dvb */
David S. Miller6e87abd2005-11-16 00:52:57 -08002648HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
2649HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
2650HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
Andi Kleenc6b44d12006-01-12 01:05:26 -08002651
2652/* parport */
2653COMPATIBLE_IOCTL(LPTIME)
2654COMPATIBLE_IOCTL(LPCHAR)
2655COMPATIBLE_IOCTL(LPABORTOPEN)
2656COMPATIBLE_IOCTL(LPCAREFUL)
2657COMPATIBLE_IOCTL(LPWAIT)
2658COMPATIBLE_IOCTL(LPSETIRQ)
2659COMPATIBLE_IOCTL(LPGETSTATUS)
2660COMPATIBLE_IOCTL(LPGETSTATUS)
2661COMPATIBLE_IOCTL(LPRESET)
2662/*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
2663COMPATIBLE_IOCTL(LPGETFLAGS)
2664HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
Andi Kleen2724b6d2007-05-02 19:27:21 +02002665
2666/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
2667 but we don't want warnings on other file systems. So declare
2668 them as compatible here. */
2669#define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
2670#define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
2671
2672IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
2673IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
Geert Uytterhoeven98701dc2007-07-15 23:42:01 -07002674
David S. Miller81639042007-07-29 00:50:42 -07002675#ifdef CONFIG_SPARC
2676/* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
2677IGNORE_IOCTL(FBIOGTYPE)
2678IGNORE_IOCTL(FBIOSATTR)
2679IGNORE_IOCTL(FBIOGATTR)
2680IGNORE_IOCTL(FBIOSVIDEO)
2681IGNORE_IOCTL(FBIOGVIDEO)
2682IGNORE_IOCTL(FBIOSCURPOS)
2683IGNORE_IOCTL(FBIOGCURPOS)
2684IGNORE_IOCTL(FBIOGCURMAX)
2685IGNORE_IOCTL(FBIOPUTCMAP32)
2686IGNORE_IOCTL(FBIOGETCMAP32)
2687IGNORE_IOCTL(FBIOSCURSOR32)
2688IGNORE_IOCTL(FBIOGCURSOR32)
2689#endif
Christoph Hellwige6a6d2e2006-01-09 20:52:14 -08002690};
David S. Miller6e87abd2005-11-16 00:52:57 -08002691
Christoph Hellwig6272e262007-05-08 00:29:21 -07002692#define IOCTL_HASHSIZE 256
2693static struct ioctl_trans *ioctl32_hash_table[IOCTL_HASHSIZE];
2694
2695static inline unsigned long ioctl32_hash(unsigned long cmd)
2696{
2697 return (((cmd >> 6) ^ (cmd >> 4) ^ cmd)) % IOCTL_HASHSIZE;
2698}
2699
2700static void compat_ioctl_error(struct file *filp, unsigned int fd,
2701 unsigned int cmd, unsigned long arg)
2702{
2703 char buf[10];
2704 char *fn = "?";
2705 char *path;
2706
2707 /* find the name of the device. */
2708 path = (char *)__get_free_page(GFP_KERNEL);
2709 if (path) {
Jan Blunckcf28b482008-02-14 19:38:44 -08002710 fn = d_path(&filp->f_path, path, PAGE_SIZE);
Christoph Hellwig6272e262007-05-08 00:29:21 -07002711 if (IS_ERR(fn))
2712 fn = "?";
2713 }
2714
2715 sprintf(buf,"'%c'", (cmd>>_IOC_TYPESHIFT) & _IOC_TYPEMASK);
2716 if (!isprint(buf[1]))
2717 sprintf(buf, "%02x", buf[1]);
2718 compat_printk("ioctl32(%s:%d): Unknown cmd fd(%d) "
2719 "cmd(%08x){t:%s;sz:%u} arg(%08x) on %s\n",
2720 current->comm, current->pid,
2721 (int)fd, (unsigned int)cmd, buf,
2722 (cmd >> _IOC_SIZESHIFT) & _IOC_SIZEMASK,
2723 (unsigned int)arg, fn);
2724
2725 if (path)
2726 free_page((unsigned long)path);
2727}
2728
2729asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
2730 unsigned long arg)
2731{
2732 struct file *filp;
2733 int error = -EBADF;
2734 struct ioctl_trans *t;
2735 int fput_needed;
2736
2737 filp = fget_light(fd, &fput_needed);
2738 if (!filp)
2739 goto out;
2740
2741 /* RED-PEN how should LSM module know it's handling 32bit? */
2742 error = security_file_ioctl(filp, cmd, arg);
2743 if (error)
2744 goto out_fput;
2745
2746 /*
2747 * To allow the compat_ioctl handlers to be self contained
2748 * we need to check the common ioctls here first.
2749 * Just handle them with the standard handlers below.
2750 */
2751 switch (cmd) {
2752 case FIOCLEX:
2753 case FIONCLEX:
2754 case FIONBIO:
2755 case FIOASYNC:
2756 case FIOQSIZE:
2757 break;
2758
2759 case FIBMAP:
2760 case FIGETBSZ:
2761 case FIONREAD:
2762 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
2763 break;
2764 /*FALL THROUGH*/
2765
2766 default:
2767 if (filp->f_op && filp->f_op->compat_ioctl) {
2768 error = filp->f_op->compat_ioctl(filp, cmd, arg);
2769 if (error != -ENOIOCTLCMD)
2770 goto out_fput;
2771 }
2772
2773 if (!filp->f_op ||
2774 (!filp->f_op->ioctl && !filp->f_op->unlocked_ioctl))
2775 goto do_ioctl;
2776 break;
2777 }
2778
2779 for (t = ioctl32_hash_table[ioctl32_hash(cmd)]; t; t = t->next) {
2780 if (t->cmd == cmd)
2781 goto found_handler;
2782 }
2783
Simon Hormand9de2622007-05-10 11:51:11 -07002784#ifdef CONFIG_NET
Christoph Hellwig6272e262007-05-08 00:29:21 -07002785 if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) &&
2786 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
2787 error = siocdevprivate_ioctl(fd, cmd, arg);
Simon Hormand9de2622007-05-10 11:51:11 -07002788 } else
2789#endif
2790 {
Christoph Hellwig6272e262007-05-08 00:29:21 -07002791 static int count;
2792
2793 if (++count <= 50)
2794 compat_ioctl_error(filp, fd, cmd, arg);
2795 error = -EINVAL;
2796 }
2797
2798 goto out_fput;
2799
2800 found_handler:
2801 if (t->handler) {
2802 lock_kernel();
2803 error = t->handler(fd, cmd, arg, filp);
2804 unlock_kernel();
2805 goto out_fput;
2806 }
2807
2808 do_ioctl:
Erez Zadokdeb21db2008-02-07 00:13:25 -08002809 error = do_vfs_ioctl(filp, fd, cmd, arg);
Christoph Hellwig6272e262007-05-08 00:29:21 -07002810 out_fput:
2811 fput_light(filp, fput_needed);
2812 out:
2813 return error;
2814}
2815
2816static void ioctl32_insert_translation(struct ioctl_trans *trans)
2817{
2818 unsigned long hash;
2819 struct ioctl_trans *t;
2820
2821 hash = ioctl32_hash (trans->cmd);
2822 if (!ioctl32_hash_table[hash])
2823 ioctl32_hash_table[hash] = trans;
2824 else {
2825 t = ioctl32_hash_table[hash];
2826 while (t->next)
2827 t = t->next;
2828 trans->next = NULL;
2829 t->next = trans;
2830 }
2831}
2832
2833static int __init init_sys32_ioctl(void)
2834{
2835 int i;
2836
2837 for (i = 0; i < ARRAY_SIZE(ioctl_start); i++) {
Stephen Hemmingerc80544d2007-10-18 03:07:05 -07002838 if (ioctl_start[i].next) {
Christoph Hellwig6272e262007-05-08 00:29:21 -07002839 printk("ioctl translation %d bad\n",i);
2840 return -1;
2841 }
2842
2843 ioctl32_insert_translation(&ioctl_start[i]);
2844 }
2845 return 0;
2846}
2847__initcall(init_sys32_ioctl);