Blame view

fs/compat_ioctl.c 45.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
  /*
   * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
   *
   * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
   * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
   * Copyright (C) 2001,2002  Andi Kleen, SuSE Labs 
a2531293d   Pavel Machek   update email address
7
   * Copyright (C) 2003       Pavel Machek (pavel@ucw.cz)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
   *
   * These routines maintain argument size conversion between 32bit and 64bit
   * ioctls.
   */
3fee37c1e   Akos Maroy   fix: using joysti...
12
  #include <linux/joystick.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
15
  #include <linux/types.h>
  #include <linux/compat.h>
  #include <linux/kernel.h>
16f7e0fe2   Randy Dunlap   [PATCH] capable/c...
16
  #include <linux/capability.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
  #include <linux/compiler.h>
  #include <linux/sched.h>
  #include <linux/smp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
  #include <linux/ioctl.h>
  #include <linux/if.h>
  #include <linux/if_bridge.h>
bff61975b   NeilBrown   md: move lots of ...
23
  #include <linux/raid/md_u.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  #include <linux/kd.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
30
  #include <linux/route.h>
  #include <linux/in6.h>
  #include <linux/ipv6_route.h>
  #include <linux/skbuff.h>
  #include <linux/netlink.h>
  #include <linux/vt.h>
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
31
  #include <linux/falloc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
  #include <linux/fs.h>
  #include <linux/file.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
  #include <linux/ppp_defs.h>
4b32da2bc   Paul Mackerras   ppp: Replace uses...
35
  #include <linux/ppp-ioctl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
  #include <linux/if_pppox.h>
  #include <linux/mtio.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
  #include <linux/auto_fs.h>
  #include <linux/auto_fs4.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
  #include <linux/tty.h>
  #include <linux/vt_kern.h>
  #include <linux/fb.h>
88ae7624a   Mauro Carvalho Chehab   [media] V4L1 remo...
43
  #include <linux/videodev2.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  #include <linux/netdevice.h>
  #include <linux/raw.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
49
  #include <linux/blkdev.h>
  #include <linux/elevator.h>
  #include <linux/rtc.h>
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  #include <linux/serial.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
  #include <linux/if_tun.h>
  #include <linux/ctype.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  #include <linux/syscalls.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
  #include <linux/i2c.h>
  #include <linux/i2c-dev.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
  #include <linux/atalk.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
57
  #include <linux/gfp.h>
594edf39c   Hans Verkuil   [media] cec: add ...
58
  #include <linux/cec.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59

66cf191f3   Al Viro   compat_ioctl: don...
60
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  #include <net/bluetooth/bluetooth.h>
f49daa819   Marcel Holtmann   Bluetooth: Move H...
62
  #include <net/bluetooth/hci_sock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
  #include <net/bluetooth/rfcomm.h>
  
  #include <linux/capi.h>
5024ad4af   Hansjoerg Lipp   [PATCH] i4l: Giga...
66
  #include <linux/gigaset_dev.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67

3c3622dcb   Randy Dunlap   Fix compile issue...
68
  #ifdef CONFIG_BLOCK
390192b30   Johannes Stezenbach   compat_ioctl: fix...
69
70
  #include <linux/cdrom.h>
  #include <linux/fd.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  #include <scsi/scsi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  #include <scsi/scsi_ioctl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  #include <scsi/sg.h>
3c3622dcb   Randy Dunlap   Fix compile issue...
74
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
77
78
79
80
  #include <asm/uaccess.h>
  #include <linux/ethtool.h>
  #include <linux/mii.h>
  #include <linux/if_bonding.h>
  #include <linux/watchdog.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  #include <linux/soundcard.h>
  #include <linux/lp.h>
  #include <linux/ppdev.h>
  
  #include <linux/atm.h>
  #include <linux/atmarp.h>
  #include <linux/atmclip.h>
  #include <linux/atmdev.h>
  #include <linux/atmioc.h>
  #include <linux/atmlec.h>
  #include <linux/atmmpc.h>
  #include <linux/atmsvc.h>
  #include <linux/atm_tcp.h>
  #include <linux/sonet.h>
  #include <linux/atm_suni.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
97
98
99
100
101
102
  
  #include <linux/usb.h>
  #include <linux/usbdevice_fs.h>
  #include <linux/nbd.h>
  #include <linux/random.h>
  #include <linux/filter.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
  
  #include <linux/hiddev.h>
e97a5d893   Mauro Carvalho Chehab   [media] fs/compat...
105
  #define __DVB_CORE__
6e87abd0b   David S. Miller   [DVB]: Add compat...
106
107
108
109
  #include <linux/dvb/audio.h>
  #include <linux/dvb/dmx.h>
  #include <linux/dvb/frontend.h>
  #include <linux/dvb/video.h>
661f627da   Arnd Bergmann   compat_ioctl: sim...
110
  #include <linux/sort.h>
8163904e6   David S. Miller   [SPARC]: Mark SBU...
111
112
113
  #ifdef CONFIG_SPARC
  #include <asm/fbio.h>
  #endif
a7f61e89a   Jann Horn   compat_ioctl: don...
114
115
116
117
118
119
  #define convert_in_user(srcptr, dstptr)			\
  ({							\
  	typeof(*srcptr) val;				\
  							\
  	get_user(val, srcptr) || put_user(val, dstptr);	\
  })
66cf191f3   Al Viro   compat_ioctl: don...
120
  static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
b43417216   Jann Horn   compat_ioctl: don...
121
122
123
124
125
126
  {
  	int err;
  
  	err = security_file_ioctl(file, cmd, arg);
  	if (err)
  		return err;
66cf191f3   Al Viro   compat_ioctl: don...
127
  	return vfs_ioctl(file, cmd, arg);
b43417216   Jann Horn   compat_ioctl: don...
128
  }
66cf191f3   Al Viro   compat_ioctl: don...
129
  static int w_long(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
130
  		unsigned int cmd, compat_ulong_t __user *argp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
  	int err;
a7f61e89a   Jann Horn   compat_ioctl: don...
133
  	unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp));
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
134

a7f61e89a   Jann Horn   compat_ioctl: don...
135
  	if (valp == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  		return -EFAULT;
a7f61e89a   Jann Horn   compat_ioctl: don...
137
138
139
140
141
142
  	err = do_ioctl(file, cmd, (unsigned long)valp);
  	if (err)
  		return err;
  	if (convert_in_user(valp, argp))
  		return -EFAULT;
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
  }
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
144

6e87abd0b   David S. Miller   [DVB]: Add compat...
145
146
147
148
149
150
151
152
  struct compat_video_event {
  	int32_t		type;
  	compat_time_t	timestamp;
  	union {
  	        video_size_t size;
  		unsigned int frame_rate;
  	} u;
  };
66cf191f3   Al Viro   compat_ioctl: don...
153
  static int do_video_get_event(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
154
  		unsigned int cmd, struct compat_video_event __user *up)
6e87abd0b   David S. Miller   [DVB]: Add compat...
155
  {
a7f61e89a   Jann Horn   compat_ioctl: don...
156
157
  	struct video_event __user *kevent =
  		compat_alloc_user_space(sizeof(*kevent));
6e87abd0b   David S. Miller   [DVB]: Add compat...
158
  	int err;
a7f61e89a   Jann Horn   compat_ioctl: don...
159
160
  	if (kevent == NULL)
  		return -EFAULT;
6e87abd0b   David S. Miller   [DVB]: Add compat...
161

a7f61e89a   Jann Horn   compat_ioctl: don...
162
  	err = do_ioctl(file, cmd, (unsigned long)kevent);
6e87abd0b   David S. Miller   [DVB]: Add compat...
163
  	if (!err) {
a7f61e89a   Jann Horn   compat_ioctl: don...
164
165
166
167
168
  		err  = convert_in_user(&kevent->type, &up->type);
  		err |= convert_in_user(&kevent->timestamp, &up->timestamp);
  		err |= convert_in_user(&kevent->u.size.w, &up->u.size.w);
  		err |= convert_in_user(&kevent->u.size.h, &up->u.size.h);
  		err |= convert_in_user(&kevent->u.size.aspect_ratio,
6e87abd0b   David S. Miller   [DVB]: Add compat...
169
170
171
172
173
174
175
176
177
178
179
180
  				&up->u.size.aspect_ratio);
  		if (err)
  			err = -EFAULT;
  	}
  
  	return err;
  }
  
  struct compat_video_still_picture {
          compat_uptr_t iFrame;
          int32_t size;
  };
66cf191f3   Al Viro   compat_ioctl: don...
181
  static int do_video_stillpicture(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
182
  		unsigned int cmd, struct compat_video_still_picture __user *up)
6e87abd0b   David S. Miller   [DVB]: Add compat...
183
  {
6e87abd0b   David S. Miller   [DVB]: Add compat...
184
185
186
187
  	struct video_still_picture __user *up_native;
  	compat_uptr_t fp;
  	int32_t size;
  	int err;
6e87abd0b   David S. Miller   [DVB]: Add compat...
188
189
190
191
192
193
194
  	err  = get_user(fp, &up->iFrame);
  	err |= get_user(size, &up->size);
  	if (err)
  		return -EFAULT;
  
  	up_native =
  		compat_alloc_user_space(sizeof(struct video_still_picture));
7116e994b   Heiko Carstens   [PATCH] compat: f...
195
196
197
198
  	err =  put_user(compat_ptr(fp), &up_native->iFrame);
  	err |= put_user(size, &up_native->size);
  	if (err)
  		return -EFAULT;
6e87abd0b   David S. Miller   [DVB]: Add compat...
199

66cf191f3   Al Viro   compat_ioctl: don...
200
  	err = do_ioctl(file, cmd, (unsigned long) up_native);
6e87abd0b   David S. Miller   [DVB]: Add compat...
201
202
203
204
205
206
207
208
  
  	return err;
  }
  
  struct compat_video_spu_palette {
  	int length;
  	compat_uptr_t palette;
  };
66cf191f3   Al Viro   compat_ioctl: don...
209
  static int do_video_set_spu_palette(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
210
  		unsigned int cmd, struct compat_video_spu_palette __user *up)
6e87abd0b   David S. Miller   [DVB]: Add compat...
211
  {
6e87abd0b   David S. Miller   [DVB]: Add compat...
212
213
214
  	struct video_spu_palette __user *up_native;
  	compat_uptr_t palp;
  	int length, err;
6e87abd0b   David S. Miller   [DVB]: Add compat...
215
216
  	err  = get_user(palp, &up->palette);
  	err |= get_user(length, &up->length);
121765033   Kees Cook   fs/compat_ioctl.c...
217
218
  	if (err)
  		return -EFAULT;
6e87abd0b   David S. Miller   [DVB]: Add compat...
219
220
  
  	up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
7116e994b   Heiko Carstens   [PATCH] compat: f...
221
222
223
224
  	err  = put_user(compat_ptr(palp), &up_native->palette);
  	err |= put_user(length, &up_native->length);
  	if (err)
  		return -EFAULT;
6e87abd0b   David S. Miller   [DVB]: Add compat...
225

66cf191f3   Al Viro   compat_ioctl: don...
226
  	err = do_ioctl(file, cmd, (unsigned long) up_native);
6e87abd0b   David S. Miller   [DVB]: Add compat...
227
228
229
  
  	return err;
  }
9361401eb   David Howells   [PATCH] BLOCK: Ma...
230
  #ifdef CONFIG_BLOCK
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  typedef struct sg_io_hdr32 {
  	compat_int_t interface_id;	/* [i] 'S' for SCSI generic (required) */
  	compat_int_t dxfer_direction;	/* [i] data transfer direction  */
  	unsigned char cmd_len;		/* [i] SCSI command length ( <= 16 bytes) */
  	unsigned char mx_sb_len;		/* [i] max length to write to sbp */
  	unsigned short iovec_count;	/* [i] 0 implies no scatter gather */
  	compat_uint_t dxfer_len;		/* [i] byte count of data transfer */
  	compat_uint_t dxferp;		/* [i], [*io] points to data transfer memory
  					      or scatter gather list */
  	compat_uptr_t cmdp;		/* [i], [*i] points to command to perform */
  	compat_uptr_t sbp;		/* [i], [*o] points to sense_buffer memory */
  	compat_uint_t timeout;		/* [i] MAX_UINT->no timeout (unit: millisec) */
  	compat_uint_t flags;		/* [i] 0 -> default, see SG_FLAG... */
  	compat_int_t pack_id;		/* [i->o] unused internally (normally) */
  	compat_uptr_t usr_ptr;		/* [i->o] unused internally */
  	unsigned char status;		/* [o] scsi status */
  	unsigned char masked_status;	/* [o] shifted, masked scsi status */
  	unsigned char msg_status;		/* [o] messaging level data (optional) */
  	unsigned char sb_len_wr;		/* [o] byte count actually written to sbp */
  	unsigned short host_status;	/* [o] errors from host adapter */
  	unsigned short driver_status;	/* [o] errors from software driver */
  	compat_int_t resid;		/* [o] dxfer_len - actual_transferred */
  	compat_uint_t duration;		/* [o] time taken by cmd (unit: millisec) */
  	compat_uint_t info;		/* [o] auxiliary information */
  } sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
  
  typedef struct sg_iovec32 {
  	compat_uint_t iov_base;
  	compat_uint_t iov_len;
  } sg_iovec32_t;
  
  static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
  {
  	sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
  	sg_iovec32_t __user *iov32 = dxferp;
  	int i;
  
  	for (i = 0; i < iovec_count; i++) {
  		u32 base, len;
  
  		if (get_user(base, &iov32[i].iov_base) ||
  		    get_user(len, &iov32[i].iov_len) ||
  		    put_user(compat_ptr(base), &iov[i].iov_base) ||
  		    put_user(len, &iov[i].iov_len))
  			return -EFAULT;
  	}
  
  	if (put_user(iov, &sgio->dxferp))
  		return -EFAULT;
  	return 0;
  }
66cf191f3   Al Viro   compat_ioctl: don...
282
  static int sg_ioctl_trans(struct file *file, unsigned int cmd,
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
283
  			sg_io_hdr32_t __user *sgio32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
  {
  	sg_io_hdr_t __user *sgio;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
288
289
  	u16 iovec_count;
  	u32 data;
  	void __user *dxferp;
  	int err;
84eb8fb42   FUJITA Tomonori   [SCSI] compat_ioc...
290
291
292
293
294
  	int interface_id;
  
  	if (get_user(interface_id, &sgio32->interface_id))
  		return -EFAULT;
  	if (interface_id != 'S')
66cf191f3   Al Viro   compat_ioctl: don...
295
  		return do_ioctl(file, cmd, (unsigned long)sgio32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  	if (get_user(iovec_count, &sgio32->iovec_count))
  		return -EFAULT;
  
  	{
  		void __user *top = compat_alloc_user_space(0);
  		void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
  				       (iovec_count * sizeof(sg_iovec_t)));
  		if (new > top)
  			return -EINVAL;
  
  		sgio = new;
  	}
  
  	/* Ok, now construct.  */
  	if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
  			 (2 * sizeof(int)) +
  			 (2 * sizeof(unsigned char)) +
  			 (1 * sizeof(unsigned short)) +
  			 (1 * sizeof(unsigned int))))
  		return -EFAULT;
  
  	if (get_user(data, &sgio32->dxferp))
  		return -EFAULT;
  	dxferp = compat_ptr(data);
  	if (iovec_count) {
  		if (sg_build_iovec(sgio, dxferp, iovec_count))
  			return -EFAULT;
  	} else {
  		if (put_user(dxferp, &sgio->dxferp))
  			return -EFAULT;
  	}
  
  	{
  		unsigned char __user *cmdp;
  		unsigned char __user *sbp;
  
  		if (get_user(data, &sgio32->cmdp))
  			return -EFAULT;
  		cmdp = compat_ptr(data);
  
  		if (get_user(data, &sgio32->sbp))
  			return -EFAULT;
  		sbp = compat_ptr(data);
  
  		if (put_user(cmdp, &sgio->cmdp) ||
  		    put_user(sbp, &sgio->sbp))
  			return -EFAULT;
  	}
  
  	if (copy_in_user(&sgio->timeout, &sgio32->timeout,
  			 3 * sizeof(int)))
  		return -EFAULT;
  
  	if (get_user(data, &sgio32->usr_ptr))
  		return -EFAULT;
  	if (put_user(compat_ptr(data), &sgio->usr_ptr))
  		return -EFAULT;
66cf191f3   Al Viro   compat_ioctl: don...
354
  	err = do_ioctl(file, cmd, (unsigned long) sgio);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  
  	if (err >= 0) {
  		void __user *datap;
  
  		if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
  				 sizeof(int)) ||
  		    get_user(datap, &sgio->usr_ptr) ||
  		    put_user((u32)(unsigned long)datap,
  			     &sgio32->usr_ptr) ||
  		    copy_in_user(&sgio32->status, &sgio->status,
  				 (4 * sizeof(unsigned char)) +
  				 (2 * sizeof(unsigned short)) +
  				 (3 * sizeof(int))))
  			err = -EFAULT;
  	}
  
  	return err;
  }
2966387b4   Andi Kleen   [PATCH] x86_64: I...
373
374
375
376
377
378
379
380
381
382
  struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
  	char req_state;
  	char orphan;
  	char sg_io_owned;
  	char problem;
  	int pack_id;
  	compat_uptr_t usr_ptr;
  	unsigned int duration;
  	int unused;
  };
66cf191f3   Al Viro   compat_ioctl: don...
383
  static int sg_grt_trans(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
384
  		unsigned int cmd, struct compat_sg_req_info __user *o)
2966387b4   Andi Kleen   [PATCH] x86_64: I...
385
386
  {
  	int err, i;
6b2b4e5a2   Al Viro   [PATCH] compat_io...
387
  	sg_req_info_t __user *r;
2966387b4   Andi Kleen   [PATCH] x86_64: I...
388
  	r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
66cf191f3   Al Viro   compat_ioctl: don...
389
  	err = do_ioctl(file, cmd, (unsigned long)r);
2966387b4   Andi Kleen   [PATCH] x86_64: I...
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
  	if (err < 0)
  		return err;
  	for (i = 0; i < SG_MAX_QUEUE; i++) {
  		void __user *ptr;
  		int d;
  
  		if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
  		    get_user(ptr, &r[i].usr_ptr) ||
  		    get_user(d, &r[i].duration) ||
  		    put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
  		    put_user(d, &o[i].duration))
  			return -EFAULT;
  	}
  	return err;
  }
9361401eb   David Howells   [PATCH] BLOCK: Ma...
405
  #endif /* CONFIG_BLOCK */
2966387b4   Andi Kleen   [PATCH] x86_64: I...
406

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
408
409
410
411
412
413
  struct sock_fprog32 {
  	unsigned short	len;
  	compat_caddr_t	filter;
  };
  
  #define PPPIOCSPASS32	_IOW('t', 71, struct sock_fprog32)
  #define PPPIOCSACTIVE32	_IOW('t', 70, struct sock_fprog32)
66cf191f3   Al Viro   compat_ioctl: don...
414
  static int ppp_sock_fprog_ioctl_trans(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
415
  		unsigned int cmd, struct sock_fprog32 __user *u_fprog32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
416
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
  	struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
  	void __user *fptr64;
  	u32 fptr32;
  	u16 flen;
  
  	if (get_user(flen, &u_fprog32->len) ||
  	    get_user(fptr32, &u_fprog32->filter))
  		return -EFAULT;
  
  	fptr64 = compat_ptr(fptr32);
  
  	if (put_user(flen, &u_fprog64->len) ||
  	    put_user(fptr64, &u_fprog64->filter))
  		return -EFAULT;
  
  	if (cmd == PPPIOCSPASS32)
  		cmd = PPPIOCSPASS;
  	else
  		cmd = PPPIOCSACTIVE;
66cf191f3   Al Viro   compat_ioctl: don...
436
  	return do_ioctl(file, cmd, (unsigned long) u_fprog64);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
438
439
440
441
442
443
444
445
446
447
448
449
450
  }
  
  struct ppp_option_data32 {
  	compat_caddr_t	ptr;
  	u32			length;
  	compat_int_t		transmit;
  };
  #define PPPIOCSCOMPRESS32	_IOW('t', 77, struct ppp_option_data32)
  
  struct ppp_idle32 {
  	compat_time_t xmit_idle;
  	compat_time_t recv_idle;
  };
  #define PPPIOCGIDLE32		_IOR('t', 63, struct ppp_idle32)
66cf191f3   Al Viro   compat_ioctl: don...
451
  static int ppp_gidle(struct file *file, unsigned int cmd,
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
452
  		struct ppp_idle32 __user *idle32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
454
  {
  	struct ppp_idle __user *idle;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
458
  	__kernel_time_t xmit, recv;
  	int err;
  
  	idle = compat_alloc_user_space(sizeof(*idle));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
459

66cf191f3   Al Viro   compat_ioctl: don...
460
  	err = do_ioctl(file, PPPIOCGIDLE, (unsigned long) idle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
465
466
467
468
469
470
  
  	if (!err) {
  		if (get_user(xmit, &idle->xmit_idle) ||
  		    get_user(recv, &idle->recv_idle) ||
  		    put_user(xmit, &idle32->xmit_idle) ||
  		    put_user(recv, &idle32->recv_idle))
  			err = -EFAULT;
  	}
  	return err;
  }
66cf191f3   Al Viro   compat_ioctl: don...
471
  static int ppp_scompress(struct file *file, unsigned int cmd,
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
472
  	struct ppp_option_data32 __user *odata32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
474
  {
  	struct ppp_option_data __user *odata;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
477
478
  	__u32 data;
  	void __user *datap;
  
  	odata = compat_alloc_user_space(sizeof(*odata));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
479
480
481
482
483
484
485
486
487
488
489
  
  	if (get_user(data, &odata32->ptr))
  		return -EFAULT;
  
  	datap = compat_ptr(data);
  	if (put_user(datap, &odata->ptr))
  		return -EFAULT;
  
  	if (copy_in_user(&odata->length, &odata32->length,
  			 sizeof(__u32) + sizeof(int)))
  		return -EFAULT;
66cf191f3   Al Viro   compat_ioctl: don...
490
  	return do_ioctl(file, PPPIOCSCOMPRESS, (unsigned long) odata);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
  }
9361401eb   David Howells   [PATCH] BLOCK: Ma...
492
  #ifdef CONFIG_BLOCK
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  struct mtget32 {
  	compat_long_t	mt_type;
  	compat_long_t	mt_resid;
  	compat_long_t	mt_dsreg;
  	compat_long_t	mt_gstat;
  	compat_long_t	mt_erreg;
  	compat_daddr_t	mt_fileno;
  	compat_daddr_t	mt_blkno;
  };
  #define MTIOCGET32	_IOR('m', 2, struct mtget32)
  
  struct mtpos32 {
  	compat_long_t	mt_blkno;
  };
  #define MTIOCPOS32	_IOR('m', 3, struct mtpos32)
66cf191f3   Al Viro   compat_ioctl: don...
508
  static int mt_ioctl_trans(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
509
  		unsigned int cmd, void __user *argp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
  {
a7f61e89a   Jann Horn   compat_ioctl: don...
511
512
  	/* NULL initialization to make gcc shut up */
  	struct mtget __user *get = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
513
  	struct mtget32 __user *umget32;
a7f61e89a   Jann Horn   compat_ioctl: don...
514
  	struct mtpos __user *pos = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
517
518
519
520
521
522
  	struct mtpos32 __user *upos32;
  	unsigned long kcmd;
  	void *karg;
  	int err = 0;
  
  	switch(cmd) {
  	case MTIOCPOS32:
  		kcmd = MTIOCPOS;
a7f61e89a   Jann Horn   compat_ioctl: don...
523
524
  		pos = compat_alloc_user_space(sizeof(*pos));
  		karg = pos;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
525
  		break;
45bf5cd7b   Andrew Morton   fs/compat_ioctl.c...
526
  	default:	/* MTIOCGET32 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
527
  		kcmd = MTIOCGET;
a7f61e89a   Jann Horn   compat_ioctl: don...
528
529
  		get = compat_alloc_user_space(sizeof(*get));
  		karg = get;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
  	}
a7f61e89a   Jann Horn   compat_ioctl: don...
532
533
  	if (karg == NULL)
  		return -EFAULT;
66cf191f3   Al Viro   compat_ioctl: don...
534
  	err = do_ioctl(file, kcmd, (unsigned long)karg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
536
537
538
  	if (err)
  		return err;
  	switch (cmd) {
  	case MTIOCPOS32:
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
539
  		upos32 = argp;
a7f61e89a   Jann Horn   compat_ioctl: don...
540
  		err = convert_in_user(&pos->mt_blkno, &upos32->mt_blkno);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541
542
  		break;
  	case MTIOCGET32:
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
543
  		umget32 = argp;
a7f61e89a   Jann Horn   compat_ioctl: don...
544
545
546
547
548
549
550
  		err = convert_in_user(&get->mt_type, &umget32->mt_type);
  		err |= convert_in_user(&get->mt_resid, &umget32->mt_resid);
  		err |= convert_in_user(&get->mt_dsreg, &umget32->mt_dsreg);
  		err |= convert_in_user(&get->mt_gstat, &umget32->mt_gstat);
  		err |= convert_in_user(&get->mt_erreg, &umget32->mt_erreg);
  		err |= convert_in_user(&get->mt_fileno, &umget32->mt_fileno);
  		err |= convert_in_user(&get->mt_blkno, &umget32->mt_blkno);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
551
552
553
554
  		break;
  	}
  	return err ? -EFAULT: 0;
  }
9361401eb   David Howells   [PATCH] BLOCK: Ma...
555
  #endif /* CONFIG_BLOCK */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
  /* Bluetooth ioctls */
2cdf096ff   Johan Hedberg   Bluetooth: Add mi...
558
559
560
  #define HCIUARTSETPROTO		_IOW('U', 200, int)
  #define HCIUARTGETPROTO		_IOR('U', 201, int)
  #define HCIUARTGETDEVICE	_IOR('U', 202, int)
63c7d09cd   Johan Hedberg   Bluetooth: Add HC...
561
562
  #define HCIUARTSETFLAGS		_IOW('U', 203, int)
  #define HCIUARTGETFLAGS		_IOR('U', 204, int)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
565
566
567
  
  #define BNEPCONNADD	_IOW('B', 200, int)
  #define BNEPCONNDEL	_IOW('B', 201, int)
  #define BNEPGETCONNLIST	_IOR('B', 210, int)
  #define BNEPGETCONNINFO	_IOR('B', 211, int)
0477e2e86   Grzegorz Kolodziejczyk   Bluetooth: bnep: ...
568
  #define BNEPGETSUPPFEAT	_IOR('B', 212, int)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
569
570
571
572
573
574
575
576
577
578
  
  #define CMTPCONNADD	_IOW('C', 200, int)
  #define CMTPCONNDEL	_IOW('C', 201, int)
  #define CMTPGETCONNLIST	_IOR('C', 210, int)
  #define CMTPGETCONNINFO	_IOR('C', 211, int)
  
  #define HIDPCONNADD	_IOW('H', 200, int)
  #define HIDPCONNDEL	_IOW('H', 201, int)
  #define HIDPGETCONNLIST	_IOR('H', 210, int)
  #define HIDPGETCONNINFO	_IOR('H', 211, int)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
  
  struct serial_struct32 {
          compat_int_t    type;
          compat_int_t    line;
          compat_uint_t   port;
          compat_int_t    irq;
          compat_int_t    flags;
          compat_int_t    xmit_fifo_size;
          compat_int_t    custom_divisor;
          compat_int_t    baud_base;
          unsigned short  close_delay;
          char    io_type;
          char    reserved_char[1];
          compat_int_t    hub6;
          unsigned short  closing_wait; /* time to wait before closing */
          unsigned short  closing_wait2; /* no longer used... */
          compat_uint_t   iomem_base;
          unsigned short  iomem_reg_shift;
          unsigned int    port_high;
       /* compat_ulong_t  iomap_base FIXME */
          compat_int_t    reserved[1];
  };
66cf191f3   Al Viro   compat_ioctl: don...
601
  static int serial_struct_ioctl(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
602
  		unsigned cmd, struct serial_struct32 __user *ss32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
          typedef struct serial_struct32 SS32;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
605
          int err;
a7f61e89a   Jann Horn   compat_ioctl: don...
606
  	struct serial_struct __user *ss = compat_alloc_user_space(sizeof(*ss));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
          __u32 udata;
7116e994b   Heiko Carstens   [PATCH] compat: f...
608
  	unsigned int base;
a7f61e89a   Jann Horn   compat_ioctl: don...
609
  	unsigned char *iomem_base;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610

a7f61e89a   Jann Horn   compat_ioctl: don...
611
612
  	if (ss == NULL)
  		return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
613
          if (cmd == TIOCSSERIAL) {
a7f61e89a   Jann Horn   compat_ioctl: don...
614
615
  		if (copy_in_user(ss, ss32, offsetof(SS32, iomem_base)) ||
  		    get_user(udata, &ss32->iomem_base))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
616
  			return -EFAULT;
a7f61e89a   Jann Horn   compat_ioctl: don...
617
618
619
620
621
622
  		iomem_base = compat_ptr(udata);
  		if (put_user(iomem_base, &ss->iomem_base) ||
  		    convert_in_user(&ss32->iomem_reg_shift,
  		      &ss->iomem_reg_shift) ||
  		    convert_in_user(&ss32->port_high, &ss->port_high) ||
  		    put_user(0UL, &ss->iomap_base))
7116e994b   Heiko Carstens   [PATCH] compat: f...
623
  			return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
          }
a7f61e89a   Jann Horn   compat_ioctl: don...
625
  	err = do_ioctl(file, cmd, (unsigned long)ss);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626
          if (cmd == TIOCGSERIAL && err >= 0) {
a7f61e89a   Jann Horn   compat_ioctl: don...
627
628
  		if (copy_in_user(ss32, ss, offsetof(SS32, iomem_base)) ||
  		    get_user(iomem_base, &ss->iomem_base))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
629
  			return -EFAULT;
a7f61e89a   Jann Horn   compat_ioctl: don...
630
631
632
633
634
635
  		base = (unsigned long)iomem_base  >> 32 ?
  			0xffffffff : (unsigned)(unsigned long)iomem_base;
  		if (put_user(base, &ss32->iomem_base) ||
  		    convert_in_user(&ss->iomem_reg_shift,
  		      &ss32->iomem_reg_shift) ||
  		    convert_in_user(&ss->port_high, &ss32->port_high))
7116e994b   Heiko Carstens   [PATCH] compat: f...
636
  			return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
637
638
639
          }
          return err;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
  /*
   * I2C layer ioctls
   */
  
  struct i2c_msg32 {
  	u16 addr;
  	u16 flags;
  	u16 len;
  	compat_caddr_t buf;
  };
  
  struct i2c_rdwr_ioctl_data32 {
  	compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
  	u32 nmsgs;
  };
  
  struct i2c_smbus_ioctl_data32 {
  	u8 read_write;
  	u8 command;
  	u32 size;
  	compat_caddr_t data; /* union i2c_smbus_data *data */
  };
  
  struct i2c_rdwr_aligned {
  	struct i2c_rdwr_ioctl_data cmd;
  	struct i2c_msg msgs[0];
  };
66cf191f3   Al Viro   compat_ioctl: don...
667
  static int do_i2c_rdwr_ioctl(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
668
  	unsigned int cmd, struct i2c_rdwr_ioctl_data32 __user *udata)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
669
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
670
671
672
673
  	struct i2c_rdwr_aligned		__user *tdata;
  	struct i2c_msg			__user *tmsgs;
  	struct i2c_msg32		__user *umsgs;
  	compat_caddr_t			datap;
38316c8ab   Dan Carpenter   fs/compat_ioctl.c...
674
675
  	u32				nmsgs;
  	int				i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
677
678
  
  	if (get_user(nmsgs, &udata->nmsgs))
  		return -EFAULT;
c57d3e7a9   Jean Delvare   i2c-dev: Fix typo...
679
  	if (nmsgs > I2C_RDWR_IOCTL_MAX_MSGS)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  		return -EINVAL;
  
  	if (get_user(datap, &udata->msgs))
  		return -EFAULT;
  	umsgs = compat_ptr(datap);
  
  	tdata = compat_alloc_user_space(sizeof(*tdata) +
  				      nmsgs * sizeof(struct i2c_msg));
  	tmsgs = &tdata->msgs[0];
  
  	if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
  	    put_user(tmsgs, &tdata->cmd.msgs))
  		return -EFAULT;
  
  	for (i = 0; i < nmsgs; i++) {
  		if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
  			return -EFAULT;
  		if (get_user(datap, &umsgs[i].buf) ||
  		    put_user(compat_ptr(datap), &tmsgs[i].buf))
  			return -EFAULT;
  	}
66cf191f3   Al Viro   compat_ioctl: don...
701
  	return do_ioctl(file, cmd, (unsigned long)tdata);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
702
  }
66cf191f3   Al Viro   compat_ioctl: don...
703
  static int do_i2c_smbus_ioctl(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
704
  		unsigned int cmd, struct i2c_smbus_ioctl_data32   __user *udata)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
705
706
  {
  	struct i2c_smbus_ioctl_data	__user *tdata;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
707
708
709
710
711
712
713
  	compat_caddr_t			datap;
  
  	tdata = compat_alloc_user_space(sizeof(*tdata));
  	if (tdata == NULL)
  		return -ENOMEM;
  	if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
  		return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714
715
716
717
718
719
720
721
722
723
  	if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
  		return -EFAULT;
  
  	if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
  		return -EFAULT;
  	if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
  		return -EFAULT;
  	if (__get_user(datap, &udata->data) ||
  	    __put_user(compat_ptr(datap), &tdata->data))
  		return -EFAULT;
66cf191f3   Al Viro   compat_ioctl: don...
724
  	return do_ioctl(file, cmd, (unsigned long)tdata);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
  }
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
726
727
728
729
  #define RTC_IRQP_READ32		_IOR('p', 0x0b, compat_ulong_t)
  #define RTC_IRQP_SET32		_IOW('p', 0x0c, compat_ulong_t)
  #define RTC_EPOCH_READ32	_IOR('p', 0x0d, compat_ulong_t)
  #define RTC_EPOCH_SET32		_IOW('p', 0x0e, compat_ulong_t)
66cf191f3   Al Viro   compat_ioctl: don...
730
  static int rtc_ioctl(struct file *file,
b43417216   Jann Horn   compat_ioctl: don...
731
  		unsigned cmd, void __user *argp)
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
732
  {
a7f61e89a   Jann Horn   compat_ioctl: don...
733
  	unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp));
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
734
  	int ret;
a7f61e89a   Jann Horn   compat_ioctl: don...
735
736
  	if (valp == NULL)
  		return -EFAULT;
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
737
738
739
  	switch (cmd) {
  	case RTC_IRQP_READ32:
  	case RTC_EPOCH_READ32:
66cf191f3   Al Viro   compat_ioctl: don...
740
  		ret = do_ioctl(file, (cmd == RTC_IRQP_READ32) ?
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
741
  					RTC_IRQP_READ : RTC_EPOCH_READ,
a7f61e89a   Jann Horn   compat_ioctl: don...
742
  					(unsigned long)valp);
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
743
744
  		if (ret)
  			return ret;
a7f61e89a   Jann Horn   compat_ioctl: don...
745
  		return convert_in_user(valp, (unsigned int __user *)argp);
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
746
  	case RTC_IRQP_SET32:
66cf191f3   Al Viro   compat_ioctl: don...
747
  		return do_ioctl(file, RTC_IRQP_SET, (unsigned long)argp);
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
748
  	case RTC_EPOCH_SET32:
66cf191f3   Al Viro   compat_ioctl: don...
749
  		return do_ioctl(file, RTC_EPOCH_SET, (unsigned long)argp);
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
750
  	}
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
751
752
  
  	return -ENOIOCTLCMD;
ec3cad969   Christoph Hellwig   [PATCH] move rtc ...
753
  }
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
  /* on ia32 l_start is on a 32-bit boundary */
  #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
  struct space_resv_32 {
  	__s16		l_type;
  	__s16		l_whence;
  	__s64		l_start	__attribute__((packed));
  			/* len == 0 means until end of file */
  	__s64		l_len __attribute__((packed));
  	__s32		l_sysid;
  	__u32		l_pid;
  	__s32		l_pad[4];	/* reserve area */
  };
  
  #define FS_IOC_RESVSP_32		_IOW ('X', 40, struct space_resv_32)
  #define FS_IOC_RESVSP64_32	_IOW ('X', 42, struct space_resv_32)
  
  /* just account for different alignment */
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
771
772
  static int compat_ioctl_preallocate(struct file *file,
  			struct space_resv_32    __user *p32)
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
773
  {
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
  	struct space_resv	__user *p = compat_alloc_user_space(sizeof(*p));
  
  	if (copy_in_user(&p->l_type,	&p32->l_type,	sizeof(s16)) ||
  	    copy_in_user(&p->l_whence,	&p32->l_whence, sizeof(s16)) ||
  	    copy_in_user(&p->l_start,	&p32->l_start,	sizeof(s64)) ||
  	    copy_in_user(&p->l_len,	&p32->l_len,	sizeof(s64)) ||
  	    copy_in_user(&p->l_sysid,	&p32->l_sysid,	sizeof(s32)) ||
  	    copy_in_user(&p->l_pid,	&p32->l_pid,	sizeof(u32)) ||
  	    copy_in_user(&p->l_pad,	&p32->l_pad,	4*sizeof(u32)))
  		return -EFAULT;
  
  	return ioctl_preallocate(file, p);
  }
  #endif
661f627da   Arnd Bergmann   compat_ioctl: sim...
788
789
790
791
792
  /*
   * simple reversible transform to make our table more evenly
   * distributed after sorting.
   */
  #define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff)
6272e2667   Christoph Hellwig   cleanup compat io...
793

661f627da   Arnd Bergmann   compat_ioctl: sim...
794
  #define COMPATIBLE_IOCTL(cmd) XFORM(cmd),
421f02810   Andi Kleen   [PATCH] x86-64: D...
795
796
797
798
799
800
801
802
  /* ioctl should not be warned about even if it's not implemented.
     Valid reasons to use this:
     - It is implemented with ->compat_ioctl on some device, but programs
     call it on others too.
     - The ioctl is not implemented in the native kernel, but programs
     call it commonly anyways.
     Most other reasons are not valid. */
  #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd)
e6a6d2efc   Christoph Hellwig   [PATCH] sanitize ...
803

661f627da   Arnd Bergmann   compat_ioctl: sim...
804
  static unsigned int ioctl_pointer[] = {
644fd4f5d   Christoph Hellwig   merge compat_ioct...
805
806
807
808
809
810
811
812
813
814
  /* compatible ioctls first */
  COMPATIBLE_IOCTL(0x4B50)   /* KDGHWCLK - not in the kernel, but don't complain */
  COMPATIBLE_IOCTL(0x4B51)   /* KDSHWCLK - not in the kernel, but don't complain */
  
  /* Big T */
  COMPATIBLE_IOCTL(TCGETA)
  COMPATIBLE_IOCTL(TCSETA)
  COMPATIBLE_IOCTL(TCSETAW)
  COMPATIBLE_IOCTL(TCSETAF)
  COMPATIBLE_IOCTL(TCSBRK)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
815
816
817
818
819
820
821
822
  COMPATIBLE_IOCTL(TCXONC)
  COMPATIBLE_IOCTL(TCFLSH)
  COMPATIBLE_IOCTL(TCGETS)
  COMPATIBLE_IOCTL(TCSETS)
  COMPATIBLE_IOCTL(TCSETSW)
  COMPATIBLE_IOCTL(TCSETSF)
  COMPATIBLE_IOCTL(TIOCLINUX)
  COMPATIBLE_IOCTL(TIOCSBRK)
b7b8de087   Werner Fink   TTY: Add tty ioct...
823
  COMPATIBLE_IOCTL(TIOCGDEV)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
824
  COMPATIBLE_IOCTL(TIOCCBRK)
4cfbafd33   Andreas Schwab   compat_ioctl: add...
825
  COMPATIBLE_IOCTL(TIOCGSID)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
826
  COMPATIBLE_IOCTL(TIOCGICOUNT)
c6298038b   Cyrill Gorcunov   tty, ioctls -- Ad...
827
828
829
  COMPATIBLE_IOCTL(TIOCGPKT)
  COMPATIBLE_IOCTL(TIOCGPTLCK)
  COMPATIBLE_IOCTL(TIOCGEXCL)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
  /* Little t */
  COMPATIBLE_IOCTL(TIOCGETD)
  COMPATIBLE_IOCTL(TIOCSETD)
  COMPATIBLE_IOCTL(TIOCEXCL)
  COMPATIBLE_IOCTL(TIOCNXCL)
  COMPATIBLE_IOCTL(TIOCCONS)
  COMPATIBLE_IOCTL(TIOCGSOFTCAR)
  COMPATIBLE_IOCTL(TIOCSSOFTCAR)
  COMPATIBLE_IOCTL(TIOCSWINSZ)
  COMPATIBLE_IOCTL(TIOCGWINSZ)
  COMPATIBLE_IOCTL(TIOCMGET)
  COMPATIBLE_IOCTL(TIOCMBIC)
  COMPATIBLE_IOCTL(TIOCMBIS)
  COMPATIBLE_IOCTL(TIOCMSET)
  COMPATIBLE_IOCTL(TIOCPKT)
  COMPATIBLE_IOCTL(TIOCNOTTY)
  COMPATIBLE_IOCTL(TIOCSTI)
  COMPATIBLE_IOCTL(TIOCOUTQ)
  COMPATIBLE_IOCTL(TIOCSPGRP)
  COMPATIBLE_IOCTL(TIOCGPGRP)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
850
851
852
  COMPATIBLE_IOCTL(TIOCGPTN)
  COMPATIBLE_IOCTL(TIOCSPTLCK)
  COMPATIBLE_IOCTL(TIOCSERGETLSR)
26df6d134   hyc@symas.com   tty: Add EXTPROC ...
853
  COMPATIBLE_IOCTL(TIOCSIG)
142e5460a   Jaeden Amero   compat_ioctl: Avo...
854
  #ifdef TIOCSRS485
84c3b8486   Jaeden Amero   compat_ioctl: Add...
855
  COMPATIBLE_IOCTL(TIOCSRS485)
142e5460a   Jaeden Amero   compat_ioctl: Avo...
856
857
  #endif
  #ifdef TIOCGRS485
84c3b8486   Jaeden Amero   compat_ioctl: Add...
858
  COMPATIBLE_IOCTL(TIOCGRS485)
142e5460a   Jaeden Amero   compat_ioctl: Avo...
859
  #endif
81257def2   Heiko Carstens   tty: add the new ...
860
861
862
863
864
865
  #ifdef TCGETS2
  COMPATIBLE_IOCTL(TCGETS2)
  COMPATIBLE_IOCTL(TCSETS2)
  COMPATIBLE_IOCTL(TCSETSW2)
  COMPATIBLE_IOCTL(TCSETSF2)
  #endif
644fd4f5d   Christoph Hellwig   merge compat_ioct...
866
867
868
869
870
871
  /* Little f */
  COMPATIBLE_IOCTL(FIOCLEX)
  COMPATIBLE_IOCTL(FIONCLEX)
  COMPATIBLE_IOCTL(FIOASYNC)
  COMPATIBLE_IOCTL(FIONBIO)
  COMPATIBLE_IOCTL(FIONREAD)  /* This is also TIOCINQ */
69130c7cf   Eric Sandeen   compat_ioctl: hoo...
872
  COMPATIBLE_IOCTL(FS_IOC_FIEMAP)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
873
874
875
  /* 0x00 */
  COMPATIBLE_IOCTL(FIBMAP)
  COMPATIBLE_IOCTL(FIGETBSZ)
5cf8cf414   Christoph Hellwig   Fix FREEZE/THAW c...
876
877
878
  /* 'X' - originally XFS but some now in the VFS */
  COMPATIBLE_IOCTL(FIFREEZE)
  COMPATIBLE_IOCTL(FITHAW)
9abea2d64   Mikulas Patocka   ioctl_compat: han...
879
  COMPATIBLE_IOCTL(FITRIM)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
880
881
  COMPATIBLE_IOCTL(KDGETKEYCODE)
  COMPATIBLE_IOCTL(KDSETKEYCODE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
882
  COMPATIBLE_IOCTL(KDGKBTYPE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
883
  COMPATIBLE_IOCTL(KDGETMODE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
884
  COMPATIBLE_IOCTL(KDGKBMODE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
885
886
887
888
889
890
891
  COMPATIBLE_IOCTL(KDGKBMETA)
  COMPATIBLE_IOCTL(KDGKBENT)
  COMPATIBLE_IOCTL(KDSKBENT)
  COMPATIBLE_IOCTL(KDGKBSENT)
  COMPATIBLE_IOCTL(KDSKBSENT)
  COMPATIBLE_IOCTL(KDGKBDIACR)
  COMPATIBLE_IOCTL(KDSKBDIACR)
caaa357dc   Michael Schutte   Input: Add KD[GS]...
892
893
  COMPATIBLE_IOCTL(KDGKBDIACRUC)
  COMPATIBLE_IOCTL(KDSKBDIACRUC)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
894
895
  COMPATIBLE_IOCTL(KDKBDREP)
  COMPATIBLE_IOCTL(KDGKBLED)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
896
  COMPATIBLE_IOCTL(KDGETLED)
3c3622dcb   Randy Dunlap   Fix compile issue...
897
  #ifdef CONFIG_BLOCK
644fd4f5d   Christoph Hellwig   merge compat_ioct...
898
899
900
901
902
903
904
905
906
  /* Big S */
  COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN)
  COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK)
  COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK)
  COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY)
  COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER)
  COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND)
  COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST)
  COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI)
3c3622dcb   Randy Dunlap   Fix compile issue...
907
  #endif
3f0017112   Atsushi Nemoto   compat_ioctl: Sup...
908
909
910
  /* Big V (don't complain on serial console) */
  IGNORE_IOCTL(VT_OPENQRY)
  IGNORE_IOCTL(VT_GETMODE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
  /* Little p (/dev/rtc, /dev/envctrl, etc.) */
  COMPATIBLE_IOCTL(RTC_AIE_ON)
  COMPATIBLE_IOCTL(RTC_AIE_OFF)
  COMPATIBLE_IOCTL(RTC_UIE_ON)
  COMPATIBLE_IOCTL(RTC_UIE_OFF)
  COMPATIBLE_IOCTL(RTC_PIE_ON)
  COMPATIBLE_IOCTL(RTC_PIE_OFF)
  COMPATIBLE_IOCTL(RTC_WIE_ON)
  COMPATIBLE_IOCTL(RTC_WIE_OFF)
  COMPATIBLE_IOCTL(RTC_ALM_SET)
  COMPATIBLE_IOCTL(RTC_ALM_READ)
  COMPATIBLE_IOCTL(RTC_RD_TIME)
  COMPATIBLE_IOCTL(RTC_SET_TIME)
  COMPATIBLE_IOCTL(RTC_WKALM_SET)
  COMPATIBLE_IOCTL(RTC_WKALM_RD)
  /*
   * These two are only for the sbus rtc driver, but
   * hwclock tries them on every rtc device first when
   * running on sparc.  On other architectures the entries
   * are useless but harmless.
   */
  COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */
  COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */
  /* Little m */
  COMPATIBLE_IOCTL(MTIOCTOP)
  /* Socket level stuff */
  COMPATIBLE_IOCTL(FIOQSIZE)
3c3622dcb   Randy Dunlap   Fix compile issue...
938
  #ifdef CONFIG_BLOCK
f79f11852   Arnd Bergmann   compat_ioctl: ign...
939
940
  /* md calls this on random blockdevs */
  IGNORE_IOCTL(RAID_VERSION)
390192b30   Johannes Stezenbach   compat_ioctl: fix...
941
942
943
  /* qemu/qemu-img might call these two on plain files for probing */
  IGNORE_IOCTL(CDROM_DRIVE_STATUS)
  IGNORE_IOCTL(FDGETPRM32)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
944
945
946
947
  /* SG stuff */
  COMPATIBLE_IOCTL(SG_SET_TIMEOUT)
  COMPATIBLE_IOCTL(SG_GET_TIMEOUT)
  COMPATIBLE_IOCTL(SG_EMULATED_HOST)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
  COMPATIBLE_IOCTL(SG_GET_TRANSFORM)
  COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE)
  COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE)
  COMPATIBLE_IOCTL(SG_GET_SCSI_ID)
  COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA)
  COMPATIBLE_IOCTL(SG_GET_LOW_DMA)
  COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID)
  COMPATIBLE_IOCTL(SG_GET_PACK_ID)
  COMPATIBLE_IOCTL(SG_GET_NUM_WAITING)
  COMPATIBLE_IOCTL(SG_SET_DEBUG)
  COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE)
  COMPATIBLE_IOCTL(SG_GET_COMMAND_Q)
  COMPATIBLE_IOCTL(SG_SET_COMMAND_Q)
  COMPATIBLE_IOCTL(SG_GET_VERSION_NUM)
  COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN)
  COMPATIBLE_IOCTL(SG_SCSI_RESET)
  COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE)
  COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN)
  COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN)
3c3622dcb   Randy Dunlap   Fix compile issue...
967
  #endif
644fd4f5d   Christoph Hellwig   merge compat_ioct...
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
  /* PPP stuff */
  COMPATIBLE_IOCTL(PPPIOCGFLAGS)
  COMPATIBLE_IOCTL(PPPIOCSFLAGS)
  COMPATIBLE_IOCTL(PPPIOCGASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCSASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCGUNIT)
  COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCGMRU)
  COMPATIBLE_IOCTL(PPPIOCSMRU)
  COMPATIBLE_IOCTL(PPPIOCSMAXCID)
  COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP)
  COMPATIBLE_IOCTL(PPPIOCXFERUNIT)
  /* PPPIOCSCOMPRESS is translated */
  COMPATIBLE_IOCTL(PPPIOCGNPMODE)
  COMPATIBLE_IOCTL(PPPIOCSNPMODE)
  COMPATIBLE_IOCTL(PPPIOCGDEBUG)
  COMPATIBLE_IOCTL(PPPIOCSDEBUG)
  /* PPPIOCSPASS is translated */
  /* PPPIOCSACTIVE is translated */
  /* PPPIOCGIDLE is translated */
  COMPATIBLE_IOCTL(PPPIOCNEWUNIT)
  COMPATIBLE_IOCTL(PPPIOCATTACH)
  COMPATIBLE_IOCTL(PPPIOCDETACH)
  COMPATIBLE_IOCTL(PPPIOCSMRRU)
  COMPATIBLE_IOCTL(PPPIOCCONNECT)
  COMPATIBLE_IOCTL(PPPIOCDISCONN)
  COMPATIBLE_IOCTL(PPPIOCATTCHAN)
  COMPATIBLE_IOCTL(PPPIOCGCHAN)
8bab6f140   Florian Westphal   compat_ioctl: add...
998
  COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
999
1000
1001
  /* PPPOX */
  COMPATIBLE_IOCTL(PPPOEIOCSFWD)
  COMPATIBLE_IOCTL(PPPOEIOCDFWD)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
  /* Big A */
  /* sparc only */
  /* Big Q for sound/OSS */
  COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC)
  COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE)
  COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS)
  COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD)
  COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL)
  COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND)
  COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME)
  COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID)
  COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL)
  COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE)
  /* Big T for sound/OSS */
  COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE)
  COMPATIBLE_IOCTL(SNDCTL_TMR_START)
  COMPATIBLE_IOCTL(SNDCTL_TMR_STOP)
  COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE)
  COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO)
  COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE)
  COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME)
  COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT)
  /* Little m for sound/OSS */
  COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME)
  COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE)
  COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD)
  /* Big P for sound/OSS */
  COMPATIBLE_IOCTL(SNDCTL_DSP_RESET)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED)
  COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE)
  COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS)
  COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER)
  COMPATIBLE_IOCTL(SNDCTL_DSP_POST)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE)
  COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR)
  /* SNDCTL_DSP_MAPINBUF,  XXX needs translation */
  /* SNDCTL_DSP_MAPOUTBUF,  XXX needs translation */
  COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO)
  COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX)
  COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY)
  COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE)
  COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE)
  COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS)
  COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS)
  COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER)
  /* Big C for sound/OSS */
  COMPATIBLE_IOCTL(SNDCTL_COPR_RESET)
  COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD)
  COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA)
  COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE)
  COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA)
  COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE)
  COMPATIBLE_IOCTL(SNDCTL_COPR_RUN)
  COMPATIBLE_IOCTL(SNDCTL_COPR_HALT)
  COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG)
  COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG)
  /* Big M for sound/OSS */
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3)
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO))
  COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR))
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE)
  /* SOUND_MIXER_READ_ENHANCE,  same value as READ_MUTE */
  /* SOUND_MIXER_READ_LOUD,  same value as READ_MUTE */
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS)
  COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2)
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3)
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO))
  COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR))
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE)
  /* SOUND_MIXER_WRITE_ENHANCE,  same value as WRITE_MUTE */
  /* SOUND_MIXER_WRITE_LOUD,  same value as WRITE_MUTE */
  COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC)
  COMPATIBLE_IOCTL(SOUND_MIXER_INFO)
  COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO)
  COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS)
  COMPATIBLE_IOCTL(SOUND_MIXER_AGC)
  COMPATIBLE_IOCTL(SOUND_MIXER_3DSE)
  COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1)
  COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2)
  COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3)
  COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4)
  COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5)
  COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS)
  COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS)
  COMPATIBLE_IOCTL(OSS_GETVERSION)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1158
1159
1160
  /* Raw devices */
  COMPATIBLE_IOCTL(RAW_SETBIND)
  COMPATIBLE_IOCTL(RAW_GETBIND)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1161
1162
1163
1164
1165
1166
1167
1168
1169
  /* Watchdog */
  COMPATIBLE_IOCTL(WDIOC_GETSUPPORT)
  COMPATIBLE_IOCTL(WDIOC_GETSTATUS)
  COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS)
  COMPATIBLE_IOCTL(WDIOC_GETTEMP)
  COMPATIBLE_IOCTL(WDIOC_SETOPTIONS)
  COMPATIBLE_IOCTL(WDIOC_KEEPALIVE)
  COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT)
  COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT)
97beb3ae0   Wolfram Sang   fs: compat_ioctl:...
1170
1171
  COMPATIBLE_IOCTL(WDIOC_SETPRETIMEOUT)
  COMPATIBLE_IOCTL(WDIOC_GETPRETIMEOUT)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
  /* Big R */
  COMPATIBLE_IOCTL(RNDGETENTCNT)
  COMPATIBLE_IOCTL(RNDADDTOENTCNT)
  COMPATIBLE_IOCTL(RNDGETPOOL)
  COMPATIBLE_IOCTL(RNDADDENTROPY)
  COMPATIBLE_IOCTL(RNDZAPENTCNT)
  COMPATIBLE_IOCTL(RNDCLEARPOOL)
  /* Bluetooth */
  COMPATIBLE_IOCTL(HCIDEVUP)
  COMPATIBLE_IOCTL(HCIDEVDOWN)
  COMPATIBLE_IOCTL(HCIDEVRESET)
  COMPATIBLE_IOCTL(HCIDEVRESTAT)
  COMPATIBLE_IOCTL(HCIGETDEVLIST)
  COMPATIBLE_IOCTL(HCIGETDEVINFO)
  COMPATIBLE_IOCTL(HCIGETCONNLIST)
  COMPATIBLE_IOCTL(HCIGETCONNINFO)
40be492fe   Marcel Holtmann   [Bluetooth] Expor...
1188
  COMPATIBLE_IOCTL(HCIGETAUTHINFO)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1189
1190
1191
1192
1193
1194
1195
1196
1197
  COMPATIBLE_IOCTL(HCISETRAW)
  COMPATIBLE_IOCTL(HCISETSCAN)
  COMPATIBLE_IOCTL(HCISETAUTH)
  COMPATIBLE_IOCTL(HCISETENCRYPT)
  COMPATIBLE_IOCTL(HCISETPTYPE)
  COMPATIBLE_IOCTL(HCISETLINKPOL)
  COMPATIBLE_IOCTL(HCISETLINKMODE)
  COMPATIBLE_IOCTL(HCISETACLMTU)
  COMPATIBLE_IOCTL(HCISETSCOMTU)
f03585689   Johan Hedberg   Bluetooth: Add bl...
1198
1199
  COMPATIBLE_IOCTL(HCIBLOCKADDR)
  COMPATIBLE_IOCTL(HCIUNBLOCKADDR)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1200
1201
1202
  COMPATIBLE_IOCTL(HCIINQUIRY)
  COMPATIBLE_IOCTL(HCIUARTSETPROTO)
  COMPATIBLE_IOCTL(HCIUARTGETPROTO)
d10d34aa7   Marcel Holtmann   Bluetooth: Add mi...
1203
1204
1205
  COMPATIBLE_IOCTL(HCIUARTGETDEVICE)
  COMPATIBLE_IOCTL(HCIUARTSETFLAGS)
  COMPATIBLE_IOCTL(HCIUARTGETFLAGS)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1206
1207
1208
1209
1210
1211
1212
1213
1214
  COMPATIBLE_IOCTL(RFCOMMCREATEDEV)
  COMPATIBLE_IOCTL(RFCOMMRELEASEDEV)
  COMPATIBLE_IOCTL(RFCOMMGETDEVLIST)
  COMPATIBLE_IOCTL(RFCOMMGETDEVINFO)
  COMPATIBLE_IOCTL(RFCOMMSTEALDLC)
  COMPATIBLE_IOCTL(BNEPCONNADD)
  COMPATIBLE_IOCTL(BNEPCONNDEL)
  COMPATIBLE_IOCTL(BNEPGETCONNLIST)
  COMPATIBLE_IOCTL(BNEPGETCONNINFO)
0477e2e86   Grzegorz Kolodziejczyk   Bluetooth: bnep: ...
1215
  COMPATIBLE_IOCTL(BNEPGETSUPPFEAT)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
  COMPATIBLE_IOCTL(CMTPCONNADD)
  COMPATIBLE_IOCTL(CMTPCONNDEL)
  COMPATIBLE_IOCTL(CMTPGETCONNLIST)
  COMPATIBLE_IOCTL(CMTPGETCONNINFO)
  COMPATIBLE_IOCTL(HIDPCONNADD)
  COMPATIBLE_IOCTL(HIDPCONNDEL)
  COMPATIBLE_IOCTL(HIDPGETCONNLIST)
  COMPATIBLE_IOCTL(HIDPGETCONNINFO)
  /* CAPI */
  COMPATIBLE_IOCTL(CAPI_REGISTER)
  COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER)
  COMPATIBLE_IOCTL(CAPI_GET_VERSION)
  COMPATIBLE_IOCTL(CAPI_GET_SERIAL)
  COMPATIBLE_IOCTL(CAPI_GET_PROFILE)
  COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD)
  COMPATIBLE_IOCTL(CAPI_GET_ERRCODE)
  COMPATIBLE_IOCTL(CAPI_INSTALLED)
  COMPATIBLE_IOCTL(CAPI_GET_FLAGS)
  COMPATIBLE_IOCTL(CAPI_SET_FLAGS)
  COMPATIBLE_IOCTL(CAPI_CLR_FLAGS)
  COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT)
  COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT)
  /* Siemens Gigaset */
  COMPATIBLE_IOCTL(GIGASET_REDIR)
  COMPATIBLE_IOCTL(GIGASET_CONFIG)
  COMPATIBLE_IOCTL(GIGASET_BRKCHARS)
  COMPATIBLE_IOCTL(GIGASET_VERSION)
  /* Misc. */
  COMPATIBLE_IOCTL(0x41545900)		/* ATYIO_CLKR */
  COMPATIBLE_IOCTL(0x41545901)		/* ATYIO_CLKW */
  COMPATIBLE_IOCTL(PCIIOC_CONTROLLER)
  COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO)
  COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM)
  COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1250
1251
1252
1253
1254
1255
1256
  /* i2c */
  COMPATIBLE_IOCTL(I2C_SLAVE)
  COMPATIBLE_IOCTL(I2C_SLAVE_FORCE)
  COMPATIBLE_IOCTL(I2C_TENBIT)
  COMPATIBLE_IOCTL(I2C_PEC)
  COMPATIBLE_IOCTL(I2C_RETRIES)
  COMPATIBLE_IOCTL(I2C_TIMEOUT)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
  /* hiddev */
  COMPATIBLE_IOCTL(HIDIOCGVERSION)
  COMPATIBLE_IOCTL(HIDIOCAPPLICATION)
  COMPATIBLE_IOCTL(HIDIOCGDEVINFO)
  COMPATIBLE_IOCTL(HIDIOCGSTRING)
  COMPATIBLE_IOCTL(HIDIOCINITREPORT)
  COMPATIBLE_IOCTL(HIDIOCGREPORT)
  COMPATIBLE_IOCTL(HIDIOCSREPORT)
  COMPATIBLE_IOCTL(HIDIOCGREPORTINFO)
  COMPATIBLE_IOCTL(HIDIOCGFIELDINFO)
  COMPATIBLE_IOCTL(HIDIOCGUSAGE)
  COMPATIBLE_IOCTL(HIDIOCSUSAGE)
  COMPATIBLE_IOCTL(HIDIOCGUCODE)
  COMPATIBLE_IOCTL(HIDIOCGFLAG)
  COMPATIBLE_IOCTL(HIDIOCSFLAG)
  COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX)
  COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO)
  /* dvb */
  COMPATIBLE_IOCTL(AUDIO_STOP)
  COMPATIBLE_IOCTL(AUDIO_PLAY)
  COMPATIBLE_IOCTL(AUDIO_PAUSE)
  COMPATIBLE_IOCTL(AUDIO_CONTINUE)
  COMPATIBLE_IOCTL(AUDIO_SELECT_SOURCE)
  COMPATIBLE_IOCTL(AUDIO_SET_MUTE)
  COMPATIBLE_IOCTL(AUDIO_SET_AV_SYNC)
  COMPATIBLE_IOCTL(AUDIO_SET_BYPASS_MODE)
  COMPATIBLE_IOCTL(AUDIO_CHANNEL_SELECT)
  COMPATIBLE_IOCTL(AUDIO_GET_STATUS)
  COMPATIBLE_IOCTL(AUDIO_GET_CAPABILITIES)
  COMPATIBLE_IOCTL(AUDIO_CLEAR_BUFFER)
  COMPATIBLE_IOCTL(AUDIO_SET_ID)
  COMPATIBLE_IOCTL(AUDIO_SET_MIXER)
  COMPATIBLE_IOCTL(AUDIO_SET_STREAMTYPE)
  COMPATIBLE_IOCTL(AUDIO_SET_EXT_ID)
  COMPATIBLE_IOCTL(AUDIO_SET_ATTRIBUTES)
  COMPATIBLE_IOCTL(AUDIO_SET_KARAOKE)
  COMPATIBLE_IOCTL(DMX_START)
  COMPATIBLE_IOCTL(DMX_STOP)
  COMPATIBLE_IOCTL(DMX_SET_FILTER)
  COMPATIBLE_IOCTL(DMX_SET_PES_FILTER)
  COMPATIBLE_IOCTL(DMX_SET_BUFFER_SIZE)
  COMPATIBLE_IOCTL(DMX_GET_PES_PIDS)
  COMPATIBLE_IOCTL(DMX_GET_CAPS)
  COMPATIBLE_IOCTL(DMX_SET_SOURCE)
  COMPATIBLE_IOCTL(DMX_GET_STC)
  COMPATIBLE_IOCTL(FE_GET_INFO)
  COMPATIBLE_IOCTL(FE_DISEQC_RESET_OVERLOAD)
  COMPATIBLE_IOCTL(FE_DISEQC_SEND_MASTER_CMD)
  COMPATIBLE_IOCTL(FE_DISEQC_RECV_SLAVE_REPLY)
  COMPATIBLE_IOCTL(FE_DISEQC_SEND_BURST)
  COMPATIBLE_IOCTL(FE_SET_TONE)
  COMPATIBLE_IOCTL(FE_SET_VOLTAGE)
  COMPATIBLE_IOCTL(FE_ENABLE_HIGH_LNB_VOLTAGE)
  COMPATIBLE_IOCTL(FE_READ_STATUS)
  COMPATIBLE_IOCTL(FE_READ_BER)
  COMPATIBLE_IOCTL(FE_READ_SIGNAL_STRENGTH)
  COMPATIBLE_IOCTL(FE_READ_SNR)
  COMPATIBLE_IOCTL(FE_READ_UNCORRECTED_BLOCKS)
  COMPATIBLE_IOCTL(FE_SET_FRONTEND)
  COMPATIBLE_IOCTL(FE_GET_FRONTEND)
  COMPATIBLE_IOCTL(FE_GET_EVENT)
  COMPATIBLE_IOCTL(FE_DISHNETWORK_SEND_LEGACY_CMD)
  COMPATIBLE_IOCTL(VIDEO_STOP)
  COMPATIBLE_IOCTL(VIDEO_PLAY)
  COMPATIBLE_IOCTL(VIDEO_FREEZE)
  COMPATIBLE_IOCTL(VIDEO_CONTINUE)
  COMPATIBLE_IOCTL(VIDEO_SELECT_SOURCE)
  COMPATIBLE_IOCTL(VIDEO_SET_BLANK)
  COMPATIBLE_IOCTL(VIDEO_GET_STATUS)
  COMPATIBLE_IOCTL(VIDEO_SET_DISPLAY_FORMAT)
  COMPATIBLE_IOCTL(VIDEO_FAST_FORWARD)
  COMPATIBLE_IOCTL(VIDEO_SLOWMOTION)
  COMPATIBLE_IOCTL(VIDEO_GET_CAPABILITIES)
  COMPATIBLE_IOCTL(VIDEO_CLEAR_BUFFER)
  COMPATIBLE_IOCTL(VIDEO_SET_ID)
  COMPATIBLE_IOCTL(VIDEO_SET_STREAMTYPE)
  COMPATIBLE_IOCTL(VIDEO_SET_FORMAT)
  COMPATIBLE_IOCTL(VIDEO_SET_SYSTEM)
  COMPATIBLE_IOCTL(VIDEO_SET_HIGHLIGHT)
  COMPATIBLE_IOCTL(VIDEO_SET_SPU)
  COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
  COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
  COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
  COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
594edf39c   Hans Verkuil   [media] cec: add ...
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
  /* cec */
  COMPATIBLE_IOCTL(CEC_ADAP_G_CAPS)
  COMPATIBLE_IOCTL(CEC_ADAP_G_LOG_ADDRS)
  COMPATIBLE_IOCTL(CEC_ADAP_S_LOG_ADDRS)
  COMPATIBLE_IOCTL(CEC_ADAP_G_PHYS_ADDR)
  COMPATIBLE_IOCTL(CEC_ADAP_S_PHYS_ADDR)
  COMPATIBLE_IOCTL(CEC_G_MODE)
  COMPATIBLE_IOCTL(CEC_S_MODE)
  COMPATIBLE_IOCTL(CEC_TRANSMIT)
  COMPATIBLE_IOCTL(CEC_RECEIVE)
  COMPATIBLE_IOCTL(CEC_DQEVENT)
644fd4f5d   Christoph Hellwig   merge compat_ioct...
1352

3fee37c1e   Akos Maroy   fix: using joysti...
1353
1354
1355
1356
1357
  /* joystick */
  COMPATIBLE_IOCTL(JSIOCGVERSION)
  COMPATIBLE_IOCTL(JSIOCGAXES)
  COMPATIBLE_IOCTL(JSIOCGBUTTONS)
  COMPATIBLE_IOCTL(JSIOCGNAME(0))
9c0cbd54c   Christoph Hellwig   [PATCH] TIOC* com...
1358
1359
1360
1361
  #ifdef TIOCGLTC
  COMPATIBLE_IOCTL(TIOCGLTC)
  COMPATIBLE_IOCTL(TIOCSLTC)
  #endif
7a81e3168   Christoph Hellwig   [PATCH] re-add TI...
1362
1363
  #ifdef TIOCSTART
  /*
6070d81eb   Adam Buchbinder   tree-wide: fix mi...
1364
   * For these two we have definitions in ioctls.h and/or termios.h on
7a81e3168   Christoph Hellwig   [PATCH] re-add TI...
1365
1366
1367
1368
1369
1370
1371
   * some architectures but no actual implemention.  Some applications
   * like bash call them if they are defined in the headers, so we provide
   * entries here to avoid syslog message spew.
   */
  COMPATIBLE_IOCTL(TIOCSTART)
  COMPATIBLE_IOCTL(TIOCSTOP)
  #endif
c6b44d10f   Andi Kleen   [PATCH] Implement...
1372

2724b6db6   Andi Kleen   [PATCH] x86-64: S...
1373
1374
1375
1376
1377
1378
1379
1380
  /* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
     but we don't want warnings on other file systems. So declare
     them as compatible here. */
  #define VFAT_IOCTL_READDIR_BOTH32       _IOR('r', 1, struct compat_dirent[2])
  #define VFAT_IOCTL_READDIR_SHORT32      _IOR('r', 2, struct compat_dirent[2])
  
  IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32)
  IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32)
98701dc19   Geert Uytterhoeven   compat32: ignore ...
1381

8163904e6   David S. Miller   [SPARC]: Mark SBU...
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
  #ifdef CONFIG_SPARC
  /* Sparc framebuffers, handled in sbusfb_compat_ioctl() */
  IGNORE_IOCTL(FBIOGTYPE)
  IGNORE_IOCTL(FBIOSATTR)
  IGNORE_IOCTL(FBIOGATTR)
  IGNORE_IOCTL(FBIOSVIDEO)
  IGNORE_IOCTL(FBIOGVIDEO)
  IGNORE_IOCTL(FBIOSCURPOS)
  IGNORE_IOCTL(FBIOGCURPOS)
  IGNORE_IOCTL(FBIOGCURMAX)
  IGNORE_IOCTL(FBIOPUTCMAP32)
  IGNORE_IOCTL(FBIOGETCMAP32)
  IGNORE_IOCTL(FBIOSCURSOR32)
  IGNORE_IOCTL(FBIOGCURSOR32)
  #endif
e6a6d2efc   Christoph Hellwig   [PATCH] sanitize ...
1397
  };
6e87abd0b   David S. Miller   [DVB]: Add compat...
1398

5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1399
1400
1401
1402
1403
1404
1405
  /*
   * Convert common ioctl arguments based on their command number
   *
   * Please do not add any code in here. Instead, implement
   * a compat_ioctl operation in the place that handleѕ the
   * ioctl for the native case.
   */
66cf191f3   Al Viro   compat_ioctl: don...
1406
  static long do_ioctl_trans(unsigned int cmd,
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1407
1408
  		 unsigned long arg, struct file *file)
  {
43c6e7b97   Arnd Bergmann   compat_ioctl: pas...
1409
  	void __user *argp = compat_ptr(arg);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1410
1411
  	switch (cmd) {
  	case PPPIOCGIDLE32:
66cf191f3   Al Viro   compat_ioctl: don...
1412
  		return ppp_gidle(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1413
  	case PPPIOCSCOMPRESS32:
66cf191f3   Al Viro   compat_ioctl: don...
1414
  		return ppp_scompress(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1415
1416
  	case PPPIOCSPASS32:
  	case PPPIOCSACTIVE32:
66cf191f3   Al Viro   compat_ioctl: don...
1417
  		return ppp_sock_fprog_ioctl_trans(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1418
1419
  #ifdef CONFIG_BLOCK
  	case SG_IO:
66cf191f3   Al Viro   compat_ioctl: don...
1420
  		return sg_ioctl_trans(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1421
  	case SG_GET_REQUEST_TABLE:
66cf191f3   Al Viro   compat_ioctl: don...
1422
  		return sg_grt_trans(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1423
1424
  	case MTIOCGET32:
  	case MTIOCPOS32:
66cf191f3   Al Viro   compat_ioctl: don...
1425
  		return mt_ioctl_trans(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1426
  #endif
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1427
1428
1429
  	/* Serial */
  	case TIOCGSERIAL:
  	case TIOCSSERIAL:
66cf191f3   Al Viro   compat_ioctl: don...
1430
  		return serial_struct_ioctl(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1431
1432
  	/* i2c */
  	case I2C_FUNCS:
66cf191f3   Al Viro   compat_ioctl: don...
1433
  		return w_long(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1434
  	case I2C_RDWR:
66cf191f3   Al Viro   compat_ioctl: don...
1435
  		return do_i2c_rdwr_ioctl(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1436
  	case I2C_SMBUS:
66cf191f3   Al Viro   compat_ioctl: don...
1437
  		return do_i2c_smbus_ioctl(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1438
1439
1440
1441
1442
  	/* Not implemented in the native kernel */
  	case RTC_IRQP_READ32:
  	case RTC_IRQP_SET32:
  	case RTC_EPOCH_READ32:
  	case RTC_EPOCH_SET32:
66cf191f3   Al Viro   compat_ioctl: don...
1443
  		return rtc_ioctl(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1444
1445
1446
  
  	/* dvb */
  	case VIDEO_GET_EVENT:
66cf191f3   Al Viro   compat_ioctl: don...
1447
  		return do_video_get_event(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1448
  	case VIDEO_STILLPICTURE:
66cf191f3   Al Viro   compat_ioctl: don...
1449
  		return do_video_stillpicture(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1450
  	case VIDEO_SET_SPU_PALETTE:
66cf191f3   Al Viro   compat_ioctl: don...
1451
  		return do_video_set_spu_palette(file, cmd, argp);
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1452
  	}
789f0f891   Arnd Bergmann   compat_ioctl: sim...
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
  
  	/*
  	 * These take an integer instead of a pointer as 'arg',
  	 * so we must not do a compat_ptr() translation.
  	 */
  	switch (cmd) {
  	/* Big T */
  	case TCSBRKP:
  	case TIOCMIWAIT:
  	case TIOCSCTTY:
  	/* RAID */
  	case HOT_REMOVE_DISK:
  	case HOT_ADD_DISK:
  	case SET_DISK_FAULTY:
  	case SET_BITMAP_FILE:
  	/* Big K */
  	case KDSIGACCEPT:
  	case KIOCSOUND:
  	case KDMKTONE:
  	case KDSETMODE:
  	case KDSKBMODE:
  	case KDSKBMETA:
  	case KDSKBLED:
  	case KDSETLED:
66cf191f3   Al Viro   compat_ioctl: don...
1477
  		return vfs_ioctl(file, cmd, arg);
789f0f891   Arnd Bergmann   compat_ioctl: sim...
1478
  	}
5a07ea0b9   Arnd Bergmann   compat_ioctl: inl...
1479
1480
  	return -ENOIOCTLCMD;
  }
661f627da   Arnd Bergmann   compat_ioctl: sim...
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
  static int compat_ioctl_check_table(unsigned int xcmd)
  {
  	int i;
  	const int max = ARRAY_SIZE(ioctl_pointer) - 1;
  
  	BUILD_BUG_ON(max >= (1 << 16));
  
  	/* guess initial offset into table, assuming a
  	   normalized distribution */
  	i = ((xcmd >> 16) * max) >> 16;
  
  	/* do linear search up first, until greater or equal */
  	while (ioctl_pointer[i] < xcmd && i < max)
  		i++;
  
  	/* then do linear search down */
  	while (ioctl_pointer[i] > xcmd && i > 0)
  		i--;
  
  	return ioctl_pointer[i] == xcmd;
  }
932602e23   Heiko Carstens   fs/compat: conver...
1502
1503
  COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
  		       compat_ulong_t, arg32)
6272e2667   Christoph Hellwig   cleanup compat io...
1504
  {
932602e23   Heiko Carstens   fs/compat: conver...
1505
  	unsigned long arg = arg32;
2903ff019   Al Viro   switch simple cas...
1506
  	struct fd f = fdget(fd);
6272e2667   Christoph Hellwig   cleanup compat io...
1507
  	int error = -EBADF;
2903ff019   Al Viro   switch simple cas...
1508
  	if (!f.file)
6272e2667   Christoph Hellwig   cleanup compat io...
1509
1510
1511
  		goto out;
  
  	/* RED-PEN how should LSM module know it's handling 32bit? */
2903ff019   Al Viro   switch simple cas...
1512
  	error = security_file_ioctl(f.file, cmd, arg);
6272e2667   Christoph Hellwig   cleanup compat io...
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
  	if (error)
  		goto out_fput;
  
  	/*
  	 * To allow the compat_ioctl handlers to be self contained
  	 * we need to check the common ioctls here first.
  	 * Just handle them with the standard handlers below.
  	 */
  	switch (cmd) {
  	case FIOCLEX:
  	case FIONCLEX:
  	case FIONBIO:
  	case FIOASYNC:
  	case FIOQSIZE:
  		break;
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
1528
1529
1530
  #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
  	case FS_IOC_RESVSP_32:
  	case FS_IOC_RESVSP64_32:
2903ff019   Al Viro   switch simple cas...
1531
  		error = compat_ioctl_preallocate(f.file, compat_ptr(arg));
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
1532
1533
1534
1535
  		goto out_fput;
  #else
  	case FS_IOC_RESVSP:
  	case FS_IOC_RESVSP64:
2903ff019   Al Viro   switch simple cas...
1536
  		error = ioctl_preallocate(f.file, compat_ptr(arg));
3e63cbb1e   Ankit Jain   fs: Add new pre-a...
1537
1538
  		goto out_fput;
  #endif
d79bdd52d   Darrick J. Wong   vfs: wire up comp...
1539
1540
  	case FICLONE:
  	case FICLONERANGE:
54dbc1517   Darrick J. Wong   vfs: hoist the bt...
1541
  	case FIDEDUPERANGE:
d79bdd52d   Darrick J. Wong   vfs: wire up comp...
1542
  		goto do_ioctl;
6272e2667   Christoph Hellwig   cleanup compat io...
1543
1544
1545
  	case FIBMAP:
  	case FIGETBSZ:
  	case FIONREAD:
496ad9aa8   Al Viro   new helper: file_...
1546
  		if (S_ISREG(file_inode(f.file)->i_mode))
6272e2667   Christoph Hellwig   cleanup compat io...
1547
1548
1549
1550
  			break;
  		/*FALL THROUGH*/
  
  	default:
72c2d5319   Al Viro   file->f_op is nev...
1551
  		if (f.file->f_op->compat_ioctl) {
2903ff019   Al Viro   switch simple cas...
1552
  			error = f.file->f_op->compat_ioctl(f.file, cmd, arg);
6272e2667   Christoph Hellwig   cleanup compat io...
1553
1554
1555
  			if (error != -ENOIOCTLCMD)
  				goto out_fput;
  		}
72c2d5319   Al Viro   file->f_op is nev...
1556
  		if (!f.file->f_op->unlocked_ioctl)
6272e2667   Christoph Hellwig   cleanup compat io...
1557
1558
1559
  			goto do_ioctl;
  		break;
  	}
661f627da   Arnd Bergmann   compat_ioctl: sim...
1560
1561
  	if (compat_ioctl_check_table(XFORM(cmd)))
  		goto found_handler;
6272e2667   Christoph Hellwig   cleanup compat io...
1562

66cf191f3   Al Viro   compat_ioctl: don...
1563
  	error = do_ioctl_trans(cmd, arg, f.file);
07d106d0a   Linus Torvalds   vfs: fix up ENOIO...
1564
1565
  	if (error == -ENOIOCTLCMD)
  		error = -ENOTTY;
6272e2667   Christoph Hellwig   cleanup compat io...
1566
1567
1568
1569
  
  	goto out_fput;
  
   found_handler:
789f0f891   Arnd Bergmann   compat_ioctl: sim...
1570
  	arg = (unsigned long)compat_ptr(arg);
6272e2667   Christoph Hellwig   cleanup compat io...
1571
   do_ioctl:
2903ff019   Al Viro   switch simple cas...
1572
  	error = do_vfs_ioctl(f.file, fd, cmd, arg);
6272e2667   Christoph Hellwig   cleanup compat io...
1573
   out_fput:
2903ff019   Al Viro   switch simple cas...
1574
  	fdput(f);
6272e2667   Christoph Hellwig   cleanup compat io...
1575
1576
1577
   out:
  	return error;
  }
661f627da   Arnd Bergmann   compat_ioctl: sim...
1578
  static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
6272e2667   Christoph Hellwig   cleanup compat io...
1579
  {
661f627da   Arnd Bergmann   compat_ioctl: sim...
1580
1581
1582
1583
1584
1585
1586
1587
  	unsigned int a, b;
  	a = *(unsigned int *)p;
  	b = *(unsigned int *)q;
  	if (a > b)
  		return 1;
  	if (a < b)
  		return -1;
  	return 0;
6272e2667   Christoph Hellwig   cleanup compat io...
1588
1589
1590
1591
  }
  
  static int __init init_sys32_ioctl(void)
  {
661f627da   Arnd Bergmann   compat_ioctl: sim...
1592
1593
  	sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer),
  		init_sys32_ioctl_cmp, NULL);
6272e2667   Christoph Hellwig   cleanup compat io...
1594
1595
1596
  	return 0;
  }
  __initcall(init_sys32_ioctl);