Node:IOCTLs, Previous:Interrupt Input, Up:Low-Level I/O
The GNU system can handle most input/output operations on many different
devices and objects in terms of a few file primitives - read
,
write
and lseek
. However, most devices also have a few
peculiar operations which do not fit into this model. Such as:
lseek
is inapplicable).
Although some such objects such as sockets and terminals 1 have special functions of their own, it would not be practical to create functions for all these cases.
Instead these minor operations, known as IOCTLs, are assigned code
numbers and multiplexed through the ioctl
function, defined in
sys/ioctl.h
. The code numbers themselves are defined in many
different headers.
int ioctl (int filedes, int command, ...) | Function |
The A third argument is usually present, either a single number or a pointer to a structure. The meaning of this argument, the returned value, and any error codes depends upon the command used. Often -1 is returned for a failure. |
On some systems, IOCTLs used by different devices share the same numbers. Thus, although use of an inappropriate IOCTL usually only produces an error, you should not attempt to use device-specific IOCTLs on an unknown device.
Most IOCTLs are OS-specific and/or only used in special system utilities, and are thus beyond the scope of this document. For an example of the use of an IOCTL, see Out-of-Band Data.