Blame man2/ioctl.2

Packit 7cfc04
.\" Copyright (c) 1980, 1991 Regents of the University of California.
Packit 7cfc04
.\" All rights reserved.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
Packit 7cfc04
.\" Redistribution and use in source and binary forms, with or without
Packit 7cfc04
.\" modification, are permitted provided that the following conditions
Packit 7cfc04
.\" are met:
Packit 7cfc04
.\" 1. Redistributions of source code must retain the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer.
Packit 7cfc04
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer in the
Packit 7cfc04
.\"    documentation and/or other materials provided with the distribution.
Packit 7cfc04
.\" 3. All advertising materials mentioning features or use of this software
Packit 7cfc04
.\"    must display the following acknowledgement:
Packit 7cfc04
.\"	This product includes software developed by the University of
Packit 7cfc04
.\"	California, Berkeley and its contributors.
Packit 7cfc04
.\" 4. Neither the name of the University nor the names of its contributors
Packit 7cfc04
.\"    may be used to endorse or promote products derived from this software
Packit 7cfc04
.\"    without specific prior written permission.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 7cfc04
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 7cfc04
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 7cfc04
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 7cfc04
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 7cfc04
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 7cfc04
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 7cfc04
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 7cfc04
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 7cfc04
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 7cfc04
.\" SUCH DAMAGE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"     @(#)ioctl.2	6.4 (Berkeley) 3/10/91
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
Packit 7cfc04
.\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified 1999-06-25 by Rachael Munns <vashti@dream.org.uk>
Packit 7cfc04
.\" Modified 2000-09-21 by Andries Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\"
Packit 7cfc04
.TH IOCTL 2 2017-05-03 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
ioctl \- control device
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <sys/ioctl.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int ioctl(int " fd ", unsigned long " request ", ...);"
Packit 7cfc04
.\" POSIX says 'request' is int, but glibc has the above
Packit 7cfc04
.\" See https://bugzilla.kernel.org/show_bug.cgi?id=42705
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
system call manipulates the underlying device parameters of special files.
Packit 7cfc04
In particular, many operating characteristics of character special files
Packit 7cfc04
(e.g., terminals) may be controlled with
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
requests.
Packit 7cfc04
The argument
Packit 7cfc04
.I fd
Packit 7cfc04
must be an open file descriptor.
Packit 7cfc04
.PP
Packit 7cfc04
The second argument is a device-dependent request code.
Packit 7cfc04
The third argument is an untyped pointer to memory.
Packit 7cfc04
It's traditionally
Packit 7cfc04
.BI "char *" argp
Packit 7cfc04
(from the days before
Packit 7cfc04
.B "void *"
Packit 7cfc04
was valid C), and will be so named for this discussion.
Packit 7cfc04
.PP
Packit 7cfc04
An
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
.I request
Packit 7cfc04
has encoded in it whether the argument is an
Packit 7cfc04
.I in
Packit 7cfc04
parameter or
Packit 7cfc04
.I out
Packit 7cfc04
parameter, and the size of the argument
Packit 7cfc04
.I argp
Packit 7cfc04
in bytes.
Packit 7cfc04
Macros and defines used in specifying an
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
.I request
Packit 7cfc04
are located in the file
Packit 7cfc04
.IR <sys/ioctl.h> .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
Usually, on success zero is returned.
Packit 7cfc04
A few
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
requests use the return value as an output parameter
Packit 7cfc04
and return a nonnegative value on success.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP 0.7i
Packit 7cfc04
.B EBADF
Packit 7cfc04
.I fd
Packit 7cfc04
is not a valid file descriptor.
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
.I argp
Packit 7cfc04
references an inaccessible memory area.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.I request
Packit 7cfc04
or
Packit 7cfc04
.I argp
Packit 7cfc04
is not valid.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTTY
Packit 7cfc04
.I fd
Packit 7cfc04
is not associated with a character special device.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOTTY
Packit 7cfc04
The specified request does not apply to the kind of object that the
Packit 7cfc04
file descriptor
Packit 7cfc04
.I fd
Packit 7cfc04
references.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
No single standard.
Packit 7cfc04
Arguments, returns, and semantics of
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
vary according to the device driver in question (the call is used as a
Packit 7cfc04
catch-all for operations that don't cleanly fit the UNIX stream I/O
Packit 7cfc04
model).
Packit 7cfc04
See
Packit 7cfc04
.BR ioctl_list (2)
Packit 7cfc04
for a list of many of the known
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
calls.
Packit 7cfc04
The
Packit 7cfc04
.BR ioctl ()
Packit 7cfc04
system call appeared in Version 7 AT&T UNIX.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
In order to use this call, one needs an open file descriptor.
Packit 7cfc04
Often the
Packit 7cfc04
.BR open (2)
Packit 7cfc04
call has unwanted side effects, that can be avoided under Linux
Packit 7cfc04
by giving it the
Packit 7cfc04
.B O_NONBLOCK
Packit 7cfc04
flag.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR execve (2),
Packit 7cfc04
.BR fcntl (2),
Packit 7cfc04
.BR ioctl_console (2),
Packit 7cfc04
.BR ioctl_fat (2),
Packit 7cfc04
.BR ioctl_ficlonerange (2),
Packit 7cfc04
.BR ioctl_fideduperange (2),
Packit 7cfc04
.BR ioctl_getfsmap (2),
Packit 7cfc04
.BR ioctl_iflags (2),
Packit 7cfc04
.BR ioctl_list (2),
Packit 7cfc04
.BR ioctl_ns (2),
Packit 7cfc04
.BR ioctl_tty (2),
Packit 7cfc04
.BR ioctl_userfaultfd (2),
Packit 7cfc04
.BR open (2),
Packit 7cfc04
.\" .BR mt (4),
Packit 7cfc04
.BR sd (4),
Packit 7cfc04
.BR tty (4)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.