13 #include <linux/joystick.h>
15 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/capability.h>
19 #include <linux/compiler.h>
20 #include <linux/sched.h>
24 #include <linux/if_bridge.h>
25 #include <linux/raid/md_u.h>
28 #include <linux/in6.h>
29 #include <linux/ipv6_route.h>
31 #include <linux/netlink.h>
33 #include <linux/falloc.h>
36 #include <linux/ppp_defs.h>
38 #include <linux/if_pppox.h>
40 #include <linux/auto_fs.h>
42 #include <linux/tty.h>
45 #include <linux/videodev2.h>
46 #include <linux/netdevice.h>
50 #include <linux/rtc.h>
51 #include <linux/pci.h>
52 #include <linux/serial.h>
53 #include <linux/if_tun.h>
54 #include <linux/ctype.h>
56 #include <linux/i2c.h>
57 #include <linux/i2c-dev.h>
58 #include <linux/atalk.h>
69 #include <linux/loop.h>
70 #include <linux/cdrom.h>
72 #include <scsi/scsi.h>
77 #include <asm/uaccess.h>
78 #include <linux/ethtool.h>
79 #include <linux/mii.h>
81 #include <linux/watchdog.h>
83 #include <linux/soundcard.h>
87 #include <linux/atm.h>
90 #include <linux/atmdev.h>
95 #include <linux/atm_tcp.h>
96 #include <linux/sonet.h>
100 #include <linux/usbdevice_fs.h>
101 #include <linux/nbd.h>
102 #include <linux/random.h>
103 #include <linux/filter.h>
105 #include <linux/hiddev.h>
109 #include <linux/dvb/dmx.h>
111 #include <linux/dvb/video.h>
116 #include <asm/fbio.h>
119 static int w_long(
unsigned int fd,
unsigned int cmd,
127 err =
sys_ioctl(fd, cmd, (
unsigned long)&val);
143 static int do_video_get_event(
unsigned int fd,
unsigned int cmd,
151 err =
sys_ioctl(fd, cmd, (
unsigned long) &kevent);
155 err =
put_user(kevent.type, &up->type);
156 err |=
put_user(kevent.timestamp, &up->timestamp);
157 err |=
put_user(kevent.u.size.w, &up->u.size.w);
158 err |=
put_user(kevent.u.size.h, &up->u.size.h);
159 err |=
put_user(kevent.u.size.aspect_ratio,
160 &up->u.size.aspect_ratio);
173 static int do_video_stillpicture(
unsigned int fd,
unsigned int cmd,
194 err =
sys_ioctl(fd, cmd, (
unsigned long) up_native);
204 static int do_video_set_spu_palette(
unsigned int fd,
unsigned int cmd,
212 err |=
get_user(length, &up->length);
222 err =
sys_ioctl(fd, cmd, (
unsigned long) up_native);
228 typedef struct sg_io_hdr32 {
232 unsigned char mx_sb_len;
233 unsigned short iovec_count;
244 unsigned char masked_status;
245 unsigned char msg_status;
246 unsigned char sb_len_wr;
248 unsigned short driver_status;
254 typedef struct sg_iovec32 {
259 static int sg_build_iovec(
sg_io_hdr_t __user *sgio,
void __user *dxferp,
u16 iovec_count)
262 sg_iovec32_t
__user *iov32 = dxferp;
265 for (i = 0; i < iovec_count; i++) {
268 if (
get_user(base, &iov32[i].iov_base) ||
270 put_user(compat_ptr(base), &iov[i].iov_base) ||
280 static int sg_ioctl_trans(
unsigned int fd,
unsigned int cmd,
281 sg_io_hdr32_t __user *sgio32)
290 if (
get_user(interface_id, &sgio32->interface_id))
292 if (interface_id !=
'S')
293 return sys_ioctl(fd, cmd, (
unsigned long)sgio32);
295 if (
get_user(iovec_count, &sgio32->iovec_count))
309 if (
copy_in_user(&sgio->interface_id, &sgio32->interface_id,
311 (2 *
sizeof(
unsigned char)) +
312 (1 *
sizeof(
unsigned short)) +
313 (1 *
sizeof(
unsigned int))))
316 if (
get_user(data, &sgio32->dxferp))
318 dxferp = compat_ptr(data);
320 if (sg_build_iovec(sgio, dxferp, iovec_count))
323 if (
put_user(dxferp, &sgio->dxferp))
328 unsigned char __user *cmdp;
329 unsigned char __user *sbp;
333 cmdp = compat_ptr(data);
337 sbp = compat_ptr(data);
348 if (
get_user(data, &sgio32->usr_ptr))
350 if (
put_user(compat_ptr(data), &sgio->usr_ptr))
353 err =
sys_ioctl(fd, cmd, (
unsigned long) sgio);
364 (4 *
sizeof(
unsigned char)) +
365 (2 *
sizeof(
unsigned short)) +
373 struct compat_sg_req_info {
384 static int sg_grt_trans(
unsigned int fd,
unsigned int cmd,
struct
385 compat_sg_req_info __user *o)
390 err =
sys_ioctl(fd,cmd,(
unsigned long)r);
400 put_user((
u32)(
unsigned long)(ptr), &o[i].usr_ptr) ||
413 #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
414 #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
416 static int ppp_sock_fprog_ioctl_trans(
unsigned int fd,
unsigned int cmd,
424 if (
get_user(flen, &u_fprog32->len) ||
425 get_user(fptr32, &u_fprog32->filter))
428 fptr64 = compat_ptr(fptr32);
439 return sys_ioctl(fd, cmd, (
unsigned long) u_fprog64);
447 #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
453 #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
455 static int ppp_gidle(
unsigned int fd,
unsigned int cmd,
467 if (
get_user(xmit, &idle->xmit_idle) ||
469 put_user(xmit, &idle32->xmit_idle) ||
476 static int ppp_scompress(
unsigned int fd,
unsigned int cmd,
488 datap = compat_ptr(data);
493 sizeof(
__u32) +
sizeof(
int)))
509 #define MTIOCGET32 _IOR('m', 2, struct mtget32)
514 #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
516 static int mt_ioctl_trans(
unsigned int fd,
unsigned int cmd,
void __user *
argp)
520 struct mtget32 __user *umget32;
522 struct mtpos32 __user *upos32;
538 err =
sys_ioctl (fd, kcmd, (
unsigned long)karg);
549 err =
__put_user(
get.mt_type, &umget32->mt_type);
550 err |=
__put_user(
get.mt_resid, &umget32->mt_resid);
551 err |=
__put_user(
get.mt_dsreg, &umget32->mt_dsreg);
552 err |=
__put_user(
get.mt_gstat, &umget32->mt_gstat);
553 err |=
__put_user(
get.mt_erreg, &umget32->mt_erreg);
554 err |=
__put_user(
get.mt_fileno, &umget32->mt_fileno);
555 err |=
__put_user(
get.mt_blkno, &umget32->mt_blkno);
564 #define HCIUARTSETPROTO _IOW('U', 200, int)
565 #define HCIUARTGETPROTO _IOR('U', 201, int)
566 #define HCIUARTGETDEVICE _IOR('U', 202, int)
567 #define HCIUARTSETFLAGS _IOW('U', 203, int)
568 #define HCIUARTGETFLAGS _IOR('U', 204, int)
570 #define BNEPCONNADD _IOW('B', 200, int)
571 #define BNEPCONNDEL _IOW('B', 201, int)
572 #define BNEPGETCONNLIST _IOR('B', 210, int)
573 #define BNEPGETCONNINFO _IOR('B', 211, int)
575 #define CMTPCONNADD _IOW('C', 200, int)
576 #define CMTPCONNDEL _IOW('C', 201, int)
577 #define CMTPGETCONNLIST _IOR('C', 210, int)
578 #define CMTPGETCONNINFO _IOR('C', 211, int)
580 #define HIDPCONNADD _IOW('H', 200, int)
581 #define HIDPCONNDEL _IOW('H', 201, int)
582 #define HIDPGETCONNLIST _IOR('H', 210, int)
583 #define HIDPGETCONNINFO _IOR('H', 211, int)
608 static int serial_struct_ioctl(
unsigned fd,
unsigned cmd,
633 err =
sys_ioctl(fd,cmd,(
unsigned long)(&ss));
678 static int do_i2c_rdwr_ioctl(
unsigned int fd,
unsigned int cmd,
694 umsgs = compat_ptr(datap);
697 nmsgs *
sizeof(
struct i2c_msg));
698 tmsgs = &tdata->
msgs[0];
704 for (i = 0; i < nmsgs; i++) {
708 put_user(compat_ptr(datap), &tmsgs[i].buf))
711 return sys_ioctl(fd, cmd, (
unsigned long)tdata);
714 static int do_i2c_smbus_ioctl(
unsigned int fd,
unsigned int cmd,
737 return sys_ioctl(fd, cmd, (
unsigned long)tdata);
740 #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
741 #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
742 #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
743 #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
745 static int rtc_ioctl(
unsigned fd,
unsigned cmd,
void __user *argp)
758 (
unsigned long)&kval);
763 return put_user(val32, (
unsigned int __user *)argp);
774 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
775 struct space_resv_32 {
786 #define FS_IOC_RESVSP_32 _IOW ('X', 40, struct space_resv_32)
787 #define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32)
790 static int compat_ioctl_preallocate(
struct file *
file,
791 struct space_resv_32 __user *p32)
812 #define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
814 #define COMPATIBLE_IOCTL(cmd) XFORM(cmd),
822 #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
824 static unsigned int ioctl_pointer[] = {
1406 #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2])
1407 #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2])
1436 static long do_ioctl_trans(
int fd,
unsigned int cmd,
1437 unsigned long arg,
struct file *file)
1439 void __user *argp = compat_ptr(arg);
1443 return ppp_gidle(fd, cmd, argp);
1445 return ppp_scompress(fd, cmd, argp);
1448 return ppp_sock_fprog_ioctl_trans(fd, cmd, argp);
1451 return sg_ioctl_trans(fd, cmd, argp);
1453 return sg_grt_trans(fd, cmd, argp);
1456 return mt_ioctl_trans(fd, cmd, argp);
1461 return serial_struct_ioctl(fd, cmd, argp);
1464 return w_long(fd, cmd, argp);
1466 return do_i2c_rdwr_ioctl(fd, cmd, argp);
1468 return do_i2c_smbus_ioctl(fd, cmd, argp);
1474 return rtc_ioctl(fd, cmd, argp);
1478 return do_video_get_event(fd, cmd, argp);
1480 return do_video_stillpicture(fd, cmd, argp);
1482 return do_video_set_spu_palette(fd, cmd, argp);
1519 static int compat_ioctl_check_table(
unsigned int xcmd)
1528 i = ((xcmd >> 16) * max) >> 16;
1531 while (ioctl_pointer[i] < xcmd && i < max)
1535 while (ioctl_pointer[i] > xcmd && i > 0)
1538 return ioctl_pointer[
i] == xcmd;
1544 struct fd f = fdget(fd);
1567 #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
1568 case FS_IOC_RESVSP_32:
1569 case FS_IOC_RESVSP64_32:
1570 error = compat_ioctl_preallocate(f.
file, compat_ptr(arg));
1582 if (
S_ISREG(f.
file->f_path.dentry->d_inode->i_mode))
1587 if (f.
file->f_op && f.
file->f_op->compat_ioctl) {
1588 error = f.
file->f_op->compat_ioctl(f.
file, cmd, arg);
1593 if (!f.
file->f_op || !f.
file->f_op->unlocked_ioctl)
1598 if (compat_ioctl_check_table(
XFORM(cmd)))
1601 error = do_ioctl_trans(fd, cmd, arg, f.
file);
1608 arg = (
unsigned long)compat_ptr(arg);
1617 static int __init init_sys32_ioctl_cmp(
const void *p,
const void *
q)
1620 a = *(
unsigned int *)p;
1621 b = *(
unsigned int *)q;
1629 static int __init init_sys32_ioctl(
void)
1631 sort(ioctl_pointer,
ARRAY_SIZE(ioctl_pointer),
sizeof(*ioctl_pointer),
1632 init_sys32_ioctl_cmp,
NULL);