1IOCTL(2) Linux Programmer's Manual IOCTL(2)
2
3
4
6 ioctl - control device
7
9 #include <sys/ioctl.h>
10
11 int ioctl(int fd, unsigned long request, ...);
12
14 The ioctl() system call manipulates the underlying device parameters of
15 special files. In particular, many operating characteristics of char‐
16 acter special files (e.g., terminals) may be controlled with ioctl()
17 requests. The argument fd must be an open file descriptor.
18
19 The second argument is a device-dependent request code. The third
20 argument is an untyped pointer to memory. It's traditionally char
21 *argp (from the days before void * was valid C), and will be so named
22 for this discussion.
23
24 An ioctl() request has encoded in it whether the argument is an in
25 parameter or out parameter, and the size of the argument argp in bytes.
26 Macros and defines used in specifying an ioctl() request are located in
27 the file <sys/ioctl.h>.
28
30 Usually, on success zero is returned. A few ioctl() requests use the
31 return value as an output parameter and return a nonnegative value on
32 success. On error, -1 is returned, and errno is set appropriately.
33
35 EBADF fd is not a valid file descriptor.
36
37 EFAULT argp references an inaccessible memory area.
38
39 EINVAL request or argp is not valid.
40
41 ENOTTY fd is not associated with a character special device.
42
43 ENOTTY The specified request does not apply to the kind of object that
44 the file descriptor fd references.
45
47 No single standard. Arguments, returns, and semantics of ioctl() vary
48 according to the device driver in question (the call is used as a
49 catch-all for operations that don't cleanly fit the UNIX stream I/O
50 model). See ioctl_list(2) for a list of many of the known ioctl()
51 calls. The ioctl() system call appeared in Version 7 AT&T UNIX.
52
54 In order to use this call, one needs an open file descriptor. Often
55 the open(2) call has unwanted side effects, that can be avoided under
56 Linux by giving it the O_NONBLOCK flag.
57
59 execve(2), fcntl(2), ioctl_console(2), ioctl_fat(2), ioctl_ficlon‐
60 erange(2), ioctl_fideduperange(2), ioctl_getfsmap(2), ioctl_iflags(2),
61 ioctl_list(2), ioctl_ns(2), ioctl_tty(2), ioctl_userfaultfd(2),
62 open(2), sd(4), tty(4)
63
65 This page is part of release 5.04 of the Linux man-pages project. A
66 description of the project, information about reporting bugs, and the
67 latest version of this page, can be found at
68 https://www.kernel.org/doc/man-pages/.
69
70
71
72Linux 2017-05-03 IOCTL(2)