1*8269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993 2*8269e767SBrooks Davis.\" The Regents of the University of California. All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors 13*8269e767SBrooks Davis.\" may be used to endorse or promote products derived from this software 14*8269e767SBrooks Davis.\" without specific prior written permission. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd September 11, 2013 29*8269e767SBrooks Davis.Dt IOCTL 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm ioctl 33*8269e767SBrooks Davis.Nd control device 34*8269e767SBrooks Davis.Sh LIBRARY 35*8269e767SBrooks Davis.Lb libc 36*8269e767SBrooks Davis.Sh SYNOPSIS 37*8269e767SBrooks Davis.In sys/ioctl.h 38*8269e767SBrooks Davis.Ft int 39*8269e767SBrooks Davis.Fn ioctl "int fd" "unsigned long request" ... 40*8269e767SBrooks Davis.Sh DESCRIPTION 41*8269e767SBrooks DavisThe 42*8269e767SBrooks Davis.Fn ioctl 43*8269e767SBrooks Davissystem call manipulates the underlying device parameters of special files. 44*8269e767SBrooks DavisIn particular, many operating 45*8269e767SBrooks Davischaracteristics of character special files (e.g.\& terminals) 46*8269e767SBrooks Davismay be controlled with 47*8269e767SBrooks Davis.Fn ioctl 48*8269e767SBrooks Davisrequests. 49*8269e767SBrooks DavisThe argument 50*8269e767SBrooks Davis.Fa fd 51*8269e767SBrooks Davismust be an open file descriptor. 52*8269e767SBrooks Davis.Pp 53*8269e767SBrooks DavisThe third argument to 54*8269e767SBrooks Davis.Fn ioctl 55*8269e767SBrooks Davisis traditionally named 56*8269e767SBrooks Davis.Va "char *argp" . 57*8269e767SBrooks DavisMost uses of 58*8269e767SBrooks Davis.Fn ioctl , 59*8269e767SBrooks Davishowever, require the third argument to be a 60*8269e767SBrooks Davis.Vt caddr_t 61*8269e767SBrooks Davisor an 62*8269e767SBrooks Davis.Vt int . 63*8269e767SBrooks Davis.Pp 64*8269e767SBrooks DavisAn 65*8269e767SBrooks Davis.Fn ioctl 66*8269e767SBrooks Davis.Fa request 67*8269e767SBrooks Davishas encoded in it whether the argument is an 68*8269e767SBrooks Davis.Dq in 69*8269e767SBrooks Davisargument 70*8269e767SBrooks Davisor 71*8269e767SBrooks Davis.Dq out 72*8269e767SBrooks Davisargument, and the size of the argument 73*8269e767SBrooks Davis.Fa argp 74*8269e767SBrooks Davisin bytes. 75*8269e767SBrooks DavisMacros and defines used in specifying an ioctl 76*8269e767SBrooks Davis.Fa request 77*8269e767SBrooks Davisare located in the file 78*8269e767SBrooks Davis.In sys/ioctl.h . 79*8269e767SBrooks Davis.Sh GENERIC IOCTLS 80*8269e767SBrooks DavisSome generic ioctls are not implemented for all types of file 81*8269e767SBrooks Davisdescriptors. 82*8269e767SBrooks DavisThese include: 83*8269e767SBrooks Davis.Bl -tag -width "xxxxxx" 84*8269e767SBrooks Davis.It Dv FIONREAD int 85*8269e767SBrooks DavisGet the number of bytes that are immediately available for reading. 86*8269e767SBrooks Davis.It Dv FIONWRITE int 87*8269e767SBrooks DavisGet the number of bytes in the descriptor's send queue. 88*8269e767SBrooks DavisThese bytes are data which has been written to the descriptor but 89*8269e767SBrooks Daviswhich are being held by the kernel for further processing. 90*8269e767SBrooks DavisThe nature of the required processing depends on the underlying device. 91*8269e767SBrooks DavisFor TCP sockets, these bytes have not yet been acknowledged by the 92*8269e767SBrooks Davisother side of the connection. 93*8269e767SBrooks Davis.It Dv FIONSPACE int 94*8269e767SBrooks DavisGet the free space in the descriptor's send queue. 95*8269e767SBrooks DavisThis value is the size of the send queue minus the number of bytes 96*8269e767SBrooks Davisbeing held in the queue. 97*8269e767SBrooks DavisNote: while this value represents the number of bytes that may be 98*8269e767SBrooks Davisadded to the queue, other resource limitations may cause a write 99*8269e767SBrooks Davisnot larger than the send queue's space to be blocked. 100*8269e767SBrooks DavisOne such limitation would be a lack of network buffers for a write 101*8269e767SBrooks Davisto a network connection. 102*8269e767SBrooks Davis.El 103*8269e767SBrooks Davis.Sh RETURN VALUES 104*8269e767SBrooks DavisIf an error has occurred, a value of -1 is returned and 105*8269e767SBrooks Davis.Va errno 106*8269e767SBrooks Davisis set to indicate the error. 107*8269e767SBrooks Davis.Sh ERRORS 108*8269e767SBrooks DavisThe 109*8269e767SBrooks Davis.Fn ioctl 110*8269e767SBrooks Davissystem call 111*8269e767SBrooks Daviswill fail if: 112*8269e767SBrooks Davis.Bl -tag -width Er 113*8269e767SBrooks Davis.It Bq Er EBADF 114*8269e767SBrooks DavisThe 115*8269e767SBrooks Davis.Fa fd 116*8269e767SBrooks Davisargument 117*8269e767SBrooks Davisis not a valid descriptor. 118*8269e767SBrooks Davis.It Bq Er ENOTTY 119*8269e767SBrooks DavisThe 120*8269e767SBrooks Davis.Fa fd 121*8269e767SBrooks Davisargument 122*8269e767SBrooks Davisis not associated with a character 123*8269e767SBrooks Davisspecial device. 124*8269e767SBrooks Davis.It Bq Er ENOTTY 125*8269e767SBrooks DavisThe specified request does not apply to the kind 126*8269e767SBrooks Davisof object that the descriptor 127*8269e767SBrooks Davis.Fa fd 128*8269e767SBrooks Davisreferences. 129*8269e767SBrooks Davis.It Bq Er EINVAL 130*8269e767SBrooks DavisThe 131*8269e767SBrooks Davis.Fa request 132*8269e767SBrooks Davisor 133*8269e767SBrooks Davis.Fa argp 134*8269e767SBrooks Davisargument 135*8269e767SBrooks Davisis not valid. 136*8269e767SBrooks Davis.It Bq Er EFAULT 137*8269e767SBrooks DavisThe 138*8269e767SBrooks Davis.Fa argp 139*8269e767SBrooks Davisargument 140*8269e767SBrooks Davispoints outside the process's allocated address space. 141*8269e767SBrooks Davis.El 142*8269e767SBrooks Davis.Sh SEE ALSO 143*8269e767SBrooks Davis.Xr execve 2 , 144*8269e767SBrooks Davis.Xr fcntl 2 , 145*8269e767SBrooks Davis.Xr intro 4 , 146*8269e767SBrooks Davis.Xr tty 4 147*8269e767SBrooks Davis.Sh HISTORY 148*8269e767SBrooks DavisThe 149*8269e767SBrooks Davis.Fn ioctl 150*8269e767SBrooks Davisfunction appeared in 151*8269e767SBrooks Davis.At v7 . 152