1 .\" $NetBSD: ioctl.2,v 1.23 2010/12/19 22:19:27 wiz Exp $
3 .\" Copyright (c) 1980, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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.
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
30 .\" @(#)ioctl.2 8.2 (Berkeley) 12/11/93
43 .Fn ioctl "int d" "unsigned long request" "..."
47 function manipulates the underlying device parameters of special files.
48 In particular, many operating
49 characteristics of character special files (e.g. terminals)
50 may be controlled with
55 must be an open file descriptor.
60 has encoded in it whether the argument is an
65 parameter, and the size of the first variadic argument
67 Note that there can be only one variadic argument but cannot be represented as
70 argument in the prototype because this would require a cast to pass integral
71 types without warnings.
72 Macros and defines used in specifying an
75 are located in the header
78 Some ioctls are applicable to any file descriptor.
80 .Bl -tag -width "xxxxxx"
82 Set close-on-exec flag.
83 The file will be closed when
86 (This is equivalent to
92 form should be preferred).
94 Clear close-on-exec flag.
95 The file will remain open across
97 (This is equivalent to
103 form should be preferred).
106 Some generic ioctls are not implemented for all types of file
109 .Bl -tag -width "xxxxxx"
110 .It Dv FIONREAD "int"
111 Get the number of bytes that are immediately available for reading.
112 .It Dv FIONWRITE "int"
113 Get the number of bytes in the descriptor's send queue.
114 These bytes are data which has been written to the descriptor but
115 which are being held by the kernel for further processing.
116 The nature of the required processing depends on the underlying device.
117 For tty devices, these bytes are typically queued for delivery
119 For TCP sockets, these bytes have not yet been acknowledged by the
120 other side of the connection.
121 For files, this operation always returns zero as files do not have
123 .It Dv FIONSPACE "int"
124 Get the free space in the descriptor's send queue.
125 This value is the size of the send queue minus the number of bytes
126 being held in the queue.
127 Note: while this value represents the number of bytes that may be
128 added to the queue, other resource limitations may cause a write
129 not larger than the send queue's space to be blocked.
130 One such limitation would be a lack of network buffers for a write
131 to a network connection.
133 Set non-blocking I/O mode if the argument is non-zero.
134 In non-blocking mode,
144 immediately when no data is available
145 (This is equivalent to
151 form should be preferred).
152 .It Dv FIOASYNC "int"
153 Set asynchronous I/O mode if the argument is non-zero
154 (This is equivalent to
160 form should be preferred).
161 In asynchronous mode, the process or process group specified by
165 signals when data is available.
168 signal will be delivered when data is available on the file
170 .It Dv FIOSETOWN, FIOGETOWN "int"
171 Set/get the process or the process group (if negative) that should receive
173 signals when data is available
174 (This is equivalent to
180 form should be preferred).
183 If an error has occurred, a value of \-1 is returned and
185 is set to indicate the error.
192 is not a valid descriptor.
195 points outside the process's allocated address space.
203 is not associated with a character
205 the specified request does not apply to the kind
206 of object that the descriptor
219 function call appeared in