1.\" Copyright (c) 1980, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)ioctl.2 8.2 (Berkeley) 12/11/93 33.\" 34.\" $FreeBSD$ 35.\" 36.Dd December 11, 1993 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 <sys/ioctl.h> 46.Ft int 47.Fn ioctl "int d" "unsigned long request" ... 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 61The third argument to 62.Nm 63is traditionally named 64.Ar "char *argp" . 65Most uses of 66.Nm 67in 68.Fx 3.0 69however, require the third argument to be a 70.Ar caddr_t 71or an 72.Ar int . 73.Pp 74An ioctl 75.Fa request 76has encoded in it whether the argument is an 77.Dq in 78parameter 79or 80.Dq out 81parameter, and the size of the argument 82.Fa argp 83in bytes. 84Macros and defines used in specifying an ioctl 85.Fa request 86are located in the file 87.Ao Pa sys/ioctl.h Ac . 88.Sh IMPLEMENTATION NOTES 89In the non-threaded library 90.Fn ioctl 91is implemented as the 92.Va ioctl 93syscall. 94.Pp 95In the threaded library, the 96.Va ioctl 97syscall is assembled to 98.Fn _thread_sys_ioctl 99and 100.Fn ioctl 101is implemented as a function which locks 102.Va d 103for read and write, then calls 104.Fn _thread_sys_ioctl . 105Before returning, 106.Fn ioctl 107unlocks 108.Va d . 109.Sh RETURN VALUES 110If an error has occurred, a value of -1 is returned and 111.Va errno 112is set to indicate the error. 113.Sh ERRORS 114.Fn Ioctl 115will fail if: 116.Bl -tag -width Er 117.It Bq Er EBADF 118.Fa d 119is not a valid descriptor. 120.It Bq Er ENOTTY 121.Fa d 122is not associated with a character 123special device. 124.It Bq Er ENOTTY 125The specified request does not apply to the kind 126of object that the descriptor 127.Fa d 128references. 129.It Bq Er EINVAL 130.Fa Request 131or 132.Fa argp 133is not valid. 134.El 135.Sh SEE ALSO 136.Xr mt 1 , 137.Xr execve 2 , 138.Xr fcntl 2 , 139.Xr intro 4 , 140.Xr tty 4 141.Sh HISTORY 142An 143.Fn ioctl 144function call appeared in 145.At v7 . 146