xref: /netbsd-src/lib/libc/sys/ioctl.2 (revision de1dfb1250df962f1ff3a011772cf58e605aed11)
1.\"	$NetBSD: ioctl.2,v 1.18 2004/05/13 10:20:58 wiz Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)ioctl.2	8.2 (Berkeley) 12/11/93
31.\"
32.Dd August 11, 2002
33.Dt IOCTL 2
34.Os
35.Sh NAME
36.Nm ioctl
37.Nd control device
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In sys/ioctl.h
42.Ft int
43.Fn ioctl "int d" "unsigned long request" "void *argp"
44.Sh DESCRIPTION
45The
46.Fn ioctl
47function manipulates the underlying device parameters of special files.
48In particular, many operating
49characteristics of character special files (e.g. terminals)
50may be controlled with
51.Fn ioctl
52requests.
53The argument
54.Fa d
55must be an open file descriptor.
56.Pp
57An  ioctl
58.Fa request
59has encoded in it whether the argument is an
60.Dq in
61parameter
62or
63.Dq out
64parameter, and the size of the argument
65.Fa argp
66in bytes.
67Macros and defines used in specifying an ioctl
68.Fa request
69are located in the file
70.Ao Pa sys/ioctl.h Ac .
71.Sh GENERIC IOCTLS
72Some ioctls are applicable to any file descriptor.
73These include:
74.Bl -tag -width "xxxxxx"
75.It Dv FIOCLEX
76Set close-on-exec flag.
77The file will be closed when
78.Xr exec 3
79is invoked.
80.It Dv FIONCLEX
81Clear close-on-exec flag.
82The file will remain open across
83.Xr exec 3 .
84.El
85.Pp
86Some generic ioctls are not implemented for all types of file
87descriptors.
88These include:
89.Bl -tag -width "xxxxxx"
90.It Dv FIONREAD "int"
91Get the number of bytes that are immediately available for reading.
92.It Dv FIONBIO "int"
93Set non-blocking I/O mode if the argument is non-zero.
94In non-blocking mode,
95.Xr read 2
96or
97.Xr write 2
98calls return \-1 and set
99.Va errno
100to
101.Er EAGAIN
102immediately when no data is available.
103.It Dv FIOASYNC "int"
104Set asynchronous I/O mode if the argument is non-zero.
105In asynchronous mode, the process or process group specified by
106.Dv FIOSETOWN
107will start receiving
108.Dv SIGIO
109signals when data is available.
110The
111.Dv SIGIO
112signal will be delivered when data is available on the file
113descriptor.
114.It Dv FIOSETOWN, FIOGETOWN "int"
115Set/get the process or the process group (if negative) that should receive
116.Dv SIGIO
117signals when data is available.
118.El
119.Sh RETURN VALUES
120If an error has occurred, a value of \-1 is returned and
121.Va errno
122is set to indicate the error.
123.Sh ERRORS
124.Fn ioctl
125will fail if:
126.Bl -tag -width Er
127.It Bq Er EBADF
128.Fa d
129is not a valid descriptor.
130.It Bq Er ENOTTY
131.Fa d
132is not associated with a character
133special device.
134.It Bq Er ENOTTY
135The specified request does not apply to the kind
136of object that the descriptor
137.Fa d
138references.
139.It Bq Er EINVAL
140.Fa request
141or
142.Fa argp
143is not valid.
144.It Bq Er EFAULT
145.Fa argp
146points outside the process's allocated address space.
147.El
148.Sh SEE ALSO
149.Xr mt 1 ,
150.Xr execve 2 ,
151.Xr fcntl 2 ,
152.Xr intro 4 ,
153.Xr tty 4
154.Sh HISTORY
155An
156.Fn ioctl
157function call appeared in
158.At v7 .
159