1 |
199 |
simons |
Ioctl Numbers
|
2 |
|
|
6 Aug 1996
|
3 |
|
|
Michael Chastain
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
If you are adding new ioctl's to the kernel, you should use the _IO
|
7 |
|
|
macros defined in :
|
8 |
|
|
|
9 |
|
|
_IO an ioctl with no parameters
|
10 |
|
|
_IOW an ioctl with write parameters (from user's point of view)
|
11 |
|
|
_IOR an ioctl with read parameters (from user's point of view)
|
12 |
|
|
_IOWR an ioctl with both write and read parameters.
|
13 |
|
|
|
14 |
|
|
'Write' and 'read' are from the user's point of view. This is like the
|
15 |
|
|
system calls 'write' and 'read'. For example, a SET_FOO ioctl would be
|
16 |
|
|
_IOW, although the kernel would actually read data from user space; a
|
17 |
|
|
GET_FOO ioctl would be _IOR, although the kernel would actually write
|
18 |
|
|
data to user space.
|
19 |
|
|
|
20 |
|
|
The first argument to _IO, _IOW, _IOR, or _IOWR is an identifying letter
|
21 |
|
|
or number from the table below. If you are writing a driver for a new
|
22 |
|
|
device and need a letter, pick an unused letter. You can register the
|
23 |
|
|
letter by patching this file and submitting the patch to Linus Torvalds.
|
24 |
|
|
Or you can e-mail me at and I'll register one
|
25 |
|
|
for you.
|
26 |
|
|
|
27 |
|
|
The second argument to _IO, _IOW, _IOR, or _IOWR is a sequence number
|
28 |
|
|
to distinguish ioctls from each other. The third argument is the size
|
29 |
|
|
of the structure going into the kernel or coming out of the kernel.
|
30 |
|
|
|
31 |
|
|
Some devices use their major number as the identifier; this is not
|
32 |
|
|
recommended. Some devices are even more irregular and don't follow
|
33 |
|
|
the convention at all.
|
34 |
|
|
|
35 |
|
|
Following the convention is good because:
|
36 |
|
|
|
37 |
|
|
(1) Keeping the ioctl's globally unique helps error checking:
|
38 |
|
|
if a program calls an ioctl on the wrong device, it will get an
|
39 |
|
|
error rather than some unexpected behaviour.
|
40 |
|
|
|
41 |
|
|
(2) The 'strace' build procedure automatically finds ioctl numbers
|
42 |
|
|
defined with _IO, _IOW, _IOR, or _IOWR.
|
43 |
|
|
|
44 |
|
|
(3) 'strace' can decode numbers back into useful names when the
|
45 |
|
|
numbers are unique.
|
46 |
|
|
|
47 |
|
|
(4) People looking for ioctls can grep for them more easily when
|
48 |
|
|
the convention is used to define the ioctl numbers.
|
49 |
|
|
|
50 |
|
|
(5) When following the convention, the driver code can use generic
|
51 |
|
|
code to call verify_area to validate parameters.
|
52 |
|
|
|
53 |
|
|
This table lists ioctls visible from user land for Linux/i386. It is
|
54 |
|
|
current to Linux 2.0.11.
|
55 |
|
|
|
56 |
|
|
Code Seq# Include File Comments
|
57 |
|
|
========================================================
|
58 |
|
|
0x00 01-02 linux/fs.h conflict!
|
59 |
|
|
0x00 01-04 scsi/scsi_ioctl.h conflict!
|
60 |
|
|
0x02 all linux/fd.h
|
61 |
|
|
0x03 all linux/hdreg.h
|
62 |
|
|
0x04 all linux/umsdos_fs.h
|
63 |
|
|
0x06 all linux/lp.h
|
64 |
|
|
0x09 all linux/md.h
|
65 |
|
|
0x12 all linux/fs.h
|
66 |
|
|
0x20 all linux/cm206.h
|
67 |
|
|
0x22 all linux/scc.h conflict! (version 2.01 of z8530drv)
|
68 |
|
|
0x22 all scsi/sg.h conflict!
|
69 |
|
|
'A' all linux/apm_bios.h
|
70 |
|
|
'B' all linux/baycom.h
|
71 |
|
|
'C' all linux/soundcard.h
|
72 |
|
|
'F' all linux/fb.h
|
73 |
|
|
'I' all linux/isdn.h
|
74 |
|
|
'K' all linux/kd.h
|
75 |
|
|
'L' all linux/loop.h
|
76 |
|
|
'M' all linux/soundcard.h
|
77 |
|
|
'P' all linux/soundcard.h
|
78 |
|
|
'Q' all linux/soundcard.h
|
79 |
|
|
'R' all linux/random.h
|
80 |
|
|
'S' 00-1F linux/cdrom.h
|
81 |
|
|
'S' 20-7F linux/ucdrom.h
|
82 |
|
|
'S' 80-81 scsi/scsi_ioctl.h
|
83 |
|
|
'S' 82-FF scsi/scsi.h
|
84 |
|
|
'T' all linux/soundcard.h conflict!
|
85 |
|
|
'T' all asm-i386/ioctls.h conflict!
|
86 |
|
|
'V' all linux/vt.h
|
87 |
|
|
'W' 00-1F linux/pcwd.h
|
88 |
|
|
'Y' all linux/cyclades.h
|
89 |
|
|
'Z' all linux/scc.h version 2.2 of z8530drv
|
90 |
|
|
'a' all various, see http://lrcwww.epfl.ch/linux-atm/magic.html
|
91 |
|
|
'c' all linux/comstats.h
|
92 |
|
|
'f' all linux/ext2_fs.h
|
93 |
|
|
'm' all linux/mtio.h conflict!
|
94 |
|
|
'm' all linux/soundcard.h conflict!
|
95 |
|
|
'n' all linux/ncp_fs.h
|
96 |
|
|
'p' all linux/mc146818rtc.h
|
97 |
|
|
'r' all linux/msdos_fs.h
|
98 |
|
|
's' all linux/cdk.h
|
99 |
|
|
't' 00-7F linux/if_ppp.h
|
100 |
|
|
't' 80-8F linux/isdn_ppp.h
|
101 |
|
|
'u' all linux/smb_fs.h
|
102 |
|
|
'v' all linux/ext2_fs.h
|
103 |
|
|
'w' all CERN SCI driver (in development)
|
104 |
|
|
0x89 00-0F asm-i386/sockios.h
|
105 |
|
|
0x89 10-FF linux/sockios.h
|
106 |
|
|
0x90 00 linux/sbpcd.h
|