1*2fe8fb19SBen Gras.\" $NetBSD: ioctl.2,v 1.23 2010/12/19 22:19:27 wiz Exp $ 2*2fe8fb19SBen Gras.\" 3*2fe8fb19SBen Gras.\" Copyright (c) 1980, 1991, 1993 4*2fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 5*2fe8fb19SBen Gras.\" 6*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 7*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 8*2fe8fb19SBen Gras.\" are met: 9*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 10*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 11*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 12*2fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 13*2fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 14*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 15*2fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 16*2fe8fb19SBen Gras.\" without specific prior written permission. 17*2fe8fb19SBen Gras.\" 18*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*2fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*2fe8fb19SBen Gras.\" SUCH DAMAGE. 29*2fe8fb19SBen Gras.\" 30*2fe8fb19SBen Gras.\" @(#)ioctl.2 8.2 (Berkeley) 12/11/93 31*2fe8fb19SBen Gras.\" 32*2fe8fb19SBen Gras.Dd December 19, 2010 33*2fe8fb19SBen Gras.Dt IOCTL 2 34*2fe8fb19SBen Gras.Os 35*2fe8fb19SBen Gras.Sh NAME 36*2fe8fb19SBen Gras.Nm ioctl 37*2fe8fb19SBen Gras.Nd control device 38*2fe8fb19SBen Gras.Sh LIBRARY 39*2fe8fb19SBen Gras.Lb libc 40*2fe8fb19SBen Gras.Sh SYNOPSIS 41*2fe8fb19SBen Gras.In sys/ioctl.h 42*2fe8fb19SBen Gras.Ft int 43*2fe8fb19SBen Gras.Fn ioctl "int d" "unsigned long request" "..." 44*2fe8fb19SBen Gras.Sh DESCRIPTION 45*2fe8fb19SBen GrasThe 46*2fe8fb19SBen Gras.Fn ioctl 47*2fe8fb19SBen Grasfunction manipulates the underlying device parameters of special files. 48*2fe8fb19SBen GrasIn particular, many operating 49*2fe8fb19SBen Grascharacteristics of character special files (e.g. terminals) 50*2fe8fb19SBen Grasmay be controlled with 51*2fe8fb19SBen Gras.Fn ioctl 52*2fe8fb19SBen Grasrequests. 53*2fe8fb19SBen GrasThe argument 54*2fe8fb19SBen Gras.Fa d 55*2fe8fb19SBen Grasmust be an open file descriptor. 56*2fe8fb19SBen Gras.Pp 57*2fe8fb19SBen GrasAn 58*2fe8fb19SBen Gras.Fn ioctl 59*2fe8fb19SBen Gras.Fa request 60*2fe8fb19SBen Grashas encoded in it whether the argument is an 61*2fe8fb19SBen Gras.Dq in , 62*2fe8fb19SBen Gras.Dq out , 63*2fe8fb19SBen Grasor 64*2fe8fb19SBen Gras.Dq inout 65*2fe8fb19SBen Grasparameter, and the size of the first variadic argument 66*2fe8fb19SBen Grasin bytes. 67*2fe8fb19SBen GrasNote that there can be only one variadic argument but cannot be represented as 68*2fe8fb19SBen Grasa 69*2fe8fb19SBen Gras.Ft "void *" 70*2fe8fb19SBen Grasargument in the prototype because this would require a cast to pass integral 71*2fe8fb19SBen Grastypes without warnings. 72*2fe8fb19SBen GrasMacros and defines used in specifying an 73*2fe8fb19SBen Gras.Fn ioctl 74*2fe8fb19SBen Gras.Fa request 75*2fe8fb19SBen Grasare located in the header 76*2fe8fb19SBen Gras.In sys/ioctl.h . 77*2fe8fb19SBen Gras.Sh GENERIC IOCTLS 78*2fe8fb19SBen GrasSome ioctls are applicable to any file descriptor. 79*2fe8fb19SBen GrasThese include: 80*2fe8fb19SBen Gras.Bl -tag -width "xxxxxx" 81*2fe8fb19SBen Gras.It Dv FIOCLEX 82*2fe8fb19SBen GrasSet close-on-exec flag. 83*2fe8fb19SBen GrasThe file will be closed when 84*2fe8fb19SBen Gras.Xr exec 3 85*2fe8fb19SBen Grasis invoked 86*2fe8fb19SBen Gras(This is equivalent to 87*2fe8fb19SBen Gras.Fn fcntl 88*2fe8fb19SBen Gras.Dv F_SETFD 89*2fe8fb19SBen Gras.Dv FD_CLOEXEC 90*2fe8fb19SBen Grasand the 91*2fe8fb19SBen Gras.Fn fcntl 92*2fe8fb19SBen Grasform should be preferred). 93*2fe8fb19SBen Gras.It Dv FIONCLEX 94*2fe8fb19SBen GrasClear close-on-exec flag. 95*2fe8fb19SBen GrasThe file will remain open across 96*2fe8fb19SBen Gras.Xr exec 3 97*2fe8fb19SBen Gras(This is equivalent to 98*2fe8fb19SBen Gras.Fn fcntl 99*2fe8fb19SBen Gras.Dv F_SETFD 100*2fe8fb19SBen Gras.Dv 0 101*2fe8fb19SBen Grasand the 102*2fe8fb19SBen Gras.Fn fcntl 103*2fe8fb19SBen Grasform should be preferred). 104*2fe8fb19SBen Gras.El 105*2fe8fb19SBen Gras.Pp 106*2fe8fb19SBen GrasSome generic ioctls are not implemented for all types of file 107*2fe8fb19SBen Grasdescriptors. 108*2fe8fb19SBen GrasThese include: 109*2fe8fb19SBen Gras.Bl -tag -width "xxxxxx" 110*2fe8fb19SBen Gras.It Dv FIONREAD "int" 111*2fe8fb19SBen GrasGet the number of bytes that are immediately available for reading. 112*2fe8fb19SBen Gras.It Dv FIONWRITE "int" 113*2fe8fb19SBen GrasGet the number of bytes in the descriptor's send queue. 114*2fe8fb19SBen GrasThese bytes are data which has been written to the descriptor but 115*2fe8fb19SBen Graswhich are being held by the kernel for further processing. 116*2fe8fb19SBen GrasThe nature of the required processing depends on the underlying device. 117*2fe8fb19SBen GrasFor tty devices, these bytes are typically queued for delivery 118*2fe8fb19SBen Grasto the tty hardware. 119*2fe8fb19SBen GrasFor TCP sockets, these bytes have not yet been acknowledged by the 120*2fe8fb19SBen Grasother side of the connection. 121*2fe8fb19SBen GrasFor files, this operation always returns zero as files do not have 122*2fe8fb19SBen Grassend queues. 123*2fe8fb19SBen Gras.It Dv FIONSPACE "int" 124*2fe8fb19SBen GrasGet the free space in the descriptor's send queue. 125*2fe8fb19SBen GrasThis value is the size of the send queue minus the number of bytes 126*2fe8fb19SBen Grasbeing held in the queue. 127*2fe8fb19SBen GrasNote: while this value represents the number of bytes that may be 128*2fe8fb19SBen Grasadded to the queue, other resource limitations may cause a write 129*2fe8fb19SBen Grasnot larger than the send queue's space to be blocked. 130*2fe8fb19SBen GrasOne such limitation would be a lack of network buffers for a write 131*2fe8fb19SBen Grasto a network connection. 132*2fe8fb19SBen Gras.It Dv FIONBIO "int" 133*2fe8fb19SBen GrasSet non-blocking I/O mode if the argument is non-zero. 134*2fe8fb19SBen GrasIn non-blocking mode, 135*2fe8fb19SBen Gras.Xr read 2 136*2fe8fb19SBen Grasor 137*2fe8fb19SBen Gras.Xr write 2 138*2fe8fb19SBen Grascalls return 139*2fe8fb19SBen Gras.Dv \-1 140*2fe8fb19SBen Grasand set 141*2fe8fb19SBen Gras.Va errno 142*2fe8fb19SBen Grasto 143*2fe8fb19SBen Gras.Er EAGAIN 144*2fe8fb19SBen Grasimmediately when no data is available 145*2fe8fb19SBen Gras(This is equivalent to 146*2fe8fb19SBen Gras.Fn fcntl 147*2fe8fb19SBen Gras.Dv F_SETFL 148*2fe8fb19SBen Gras.Dv O_NONBLOCK 149*2fe8fb19SBen Grasand the 150*2fe8fb19SBen Gras.Fn fcntl 151*2fe8fb19SBen Grasform should be preferred). 152*2fe8fb19SBen Gras.It Dv FIOASYNC "int" 153*2fe8fb19SBen GrasSet asynchronous I/O mode if the argument is non-zero 154*2fe8fb19SBen Gras(This is equivalent to 155*2fe8fb19SBen Gras.Fn fcntl 156*2fe8fb19SBen Gras.Dv F_SETFL 157*2fe8fb19SBen Gras.Dv O_ASYNC 158*2fe8fb19SBen Grasand the 159*2fe8fb19SBen Gras.Fn fcntl 160*2fe8fb19SBen Grasform should be preferred). 161*2fe8fb19SBen GrasIn asynchronous mode, the process or process group specified by 162*2fe8fb19SBen Gras.Dv FIOSETOWN 163*2fe8fb19SBen Graswill start receiving 164*2fe8fb19SBen Gras.Dv SIGIO 165*2fe8fb19SBen Grassignals when data is available. 166*2fe8fb19SBen GrasThe 167*2fe8fb19SBen Gras.Dv SIGIO 168*2fe8fb19SBen Grassignal will be delivered when data is available on the file 169*2fe8fb19SBen Grasdescriptor. 170*2fe8fb19SBen Gras.It Dv FIOSETOWN, FIOGETOWN "int" 171*2fe8fb19SBen GrasSet/get the process or the process group (if negative) that should receive 172*2fe8fb19SBen Gras.Dv SIGIO 173*2fe8fb19SBen Grassignals when data is available 174*2fe8fb19SBen Gras(This is equivalent to 175*2fe8fb19SBen Gras.Fn fcntl 176*2fe8fb19SBen Gras.Dv F_SETOWN 177*2fe8fb19SBen Gras.Ft pid_t 178*2fe8fb19SBen Grasand the 179*2fe8fb19SBen Gras.Ft fcntl 180*2fe8fb19SBen Grasform should be preferred). 181*2fe8fb19SBen Gras.El 182*2fe8fb19SBen Gras.Sh RETURN VALUES 183*2fe8fb19SBen GrasIf an error has occurred, a value of \-1 is returned and 184*2fe8fb19SBen Gras.Va errno 185*2fe8fb19SBen Grasis set to indicate the error. 186*2fe8fb19SBen Gras.Sh ERRORS 187*2fe8fb19SBen Gras.Fn ioctl 188*2fe8fb19SBen Graswill fail if: 189*2fe8fb19SBen Gras.Bl -tag -width Er 190*2fe8fb19SBen Gras.It Bq Er EBADF 191*2fe8fb19SBen Gras.Fa d 192*2fe8fb19SBen Grasis not a valid descriptor. 193*2fe8fb19SBen Gras.It Bq Er EFAULT 194*2fe8fb19SBen Gras.Fa argp 195*2fe8fb19SBen Graspoints outside the process's allocated address space. 196*2fe8fb19SBen Gras.It Bq Er EINVAL 197*2fe8fb19SBen Gras.Fa request 198*2fe8fb19SBen Grasor 199*2fe8fb19SBen Gras.Fa argp 200*2fe8fb19SBen Grasis not valid. 201*2fe8fb19SBen Gras.It Bq Er ENOTTY 202*2fe8fb19SBen Gras.Fa d 203*2fe8fb19SBen Grasis not associated with a character 204*2fe8fb19SBen Grasspecial device; or 205*2fe8fb19SBen Grasthe specified request does not apply to the kind 206*2fe8fb19SBen Grasof object that the descriptor 207*2fe8fb19SBen Gras.Fa d 208*2fe8fb19SBen Grasreferences. 209*2fe8fb19SBen Gras.El 210*2fe8fb19SBen Gras.Sh SEE ALSO 211*2fe8fb19SBen Gras.Xr mt 1 , 212*2fe8fb19SBen Gras.Xr execve 2 , 213*2fe8fb19SBen Gras.Xr fcntl 2 , 214*2fe8fb19SBen Gras.Xr intro 4 , 215*2fe8fb19SBen Gras.Xr tty 4 216*2fe8fb19SBen Gras.Sh HISTORY 217*2fe8fb19SBen GrasAn 218*2fe8fb19SBen Gras.Fn ioctl 219*2fe8fb19SBen Grasfunction call appeared in 220*2fe8fb19SBen Gras.At v7 . 221