1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" @(#)ioctl.2 6.4 (Berkeley) 3/10/91
8 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
9 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
10 .\" Modified 1999-06-25 by Rachael Munns <vashti@dream.org.uk>
11 .\" Modified 2000-09-21 by Andries Brouwer <aeb@cwi.nl>
13 .TH ioctl 2 (date) "Linux man-pages (unreleased)"
15 ioctl \- control device
18 .RI ( libc ", " \-lc )
21 .B #include <sys/ioctl.h>
23 .BI "int ioctl(int " fd ", unsigned long " op ", ...);" "\f[R] /* glibc, BSD */\f[]"
24 .BI "int ioctl(int " fd ", int " op ", ...);" "\f[R] /* musl, other UNIX */\f[]"
29 system call manipulates the underlying device parameters of special files.
30 In particular, many operating characteristics of character special files
31 (e.g., terminals) may be controlled with
36 must be an open file descriptor.
38 The second argument is a device-dependent operation code.
39 The third argument is an untyped pointer to memory.
44 was valid C), and will be so named for this discussion.
49 has encoded in it whether the argument is an
53 parameter, and the size of the argument
56 Macros and defines used in specifying an
59 are located in the file
63 Usually, on success zero is returned.
66 operations use the return value as an output parameter
67 and return a nonnegative value on success.
68 On error, \-1 is returned, and
70 is set to indicate the error.
75 is not a valid file descriptor.
79 references an inaccessible memory area.
89 is not associated with a character special device.
92 The specified operation does not apply to the kind of object that the
97 Arguments, returns, and semantics of
99 vary according to the device driver in question (the call is used as a
100 catch-all for operations that don't cleanly fit the UNIX stream I/O
105 Version\~7 AT&T UNIX has
109 .BI "ioctl(int " fildes ", int " op ", struct sgttyb *" argp );
116 has historically been used by
120 and is polymorphic by operation type (like a
122 would be, if it had been available)).
126 without a type at all.
132 .BI "ioctl(int " d ", unsigned long " op ", char *" argp );
146 .BI "int ioctl(int " fildes ", int " op ", ... /* " arg " */);"
152 In order to use this call, one needs an open file descriptor.
155 call has unwanted side effects, that can be avoided under Linux
161 .\" added two sections - aeb
164 values are 32-bit constants.
165 In principle these constants are completely arbitrary, but people have
166 tried to build some structure into them.
168 The old Linux situation was that of mostly 16-bit constants, where the
169 last byte is a serial number, and the preceding byte(s) give a type
170 indicating the driver.
171 Sometimes the major number was used: 0x03
178 one or more ASCII letters were used.
182 0x00005401, with 0x54 = \[aq]T\[aq] indicating the terminal driver, and
184 has value 0x00435906, with 0x43 0x59 = \[aq]C\[aq] \[aq]Y\[aq]
185 indicating the cyclades driver.
187 Later (0.98p5) some more information was built into the number.
188 One has 2 direction bits
189 (00: none, 01: write, 10: read, 11: read/write)
190 followed by 14 size bits (giving the size of the argument),
191 followed by an 8-bit type (collecting the ioctls in groups
192 for a common purpose or a common driver), and an 8-bit
195 The macros describing this structure live in
200 .BR "{_IOR,_IOW,_IOWR}(type,nr,size)" .
204 misnomer here: this third argument is a data type.
206 Note that the size bits are very unreliable: in lots of cases
207 they are wrong, either because of buggy macros using
208 .IR sizeof(sizeof(struct)) ,
209 or because of legacy values.
211 Thus, it seems that the new structure only gave disadvantages:
212 it does not help in checking, but it causes varying values
213 for the various architectures.
217 .BR ioctl_console (2),
219 .BR ioctl_ficlone (2),
220 .BR ioctl_ficlonerange (2),
221 .BR ioctl_fideduperange (2),
222 .BR ioctl_fslabel (2),
223 .BR ioctl_getfsmap (2),
224 .BR ioctl_iflags (2),
227 .BR ioctl_userfaultfd (2),