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