.\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)ioctl.2 8.2 (Berkeley) 12/11/93 .\" .\" %FreeBSD: src/lib/libc/sys/ioctl.2,v 1.26 2004/07/02 23:52:13 ru Exp % .\" .\" $FreeBSD$ .Dd December 11, 1993 .Dt IOCTL 2 .Os .Sh 名称 .Nm ioctl .Nd デバイスを制御する .Sh ライブラリ .Lb libc .Sh 書式 .In sys/ioctl.h .Ft int .Fn ioctl "int d" "unsigned long request" ... .Sh 解説 .Fn ioctl システムコールは特殊ファイルの下層となっているデバイスのパラメータを 操作します。 特に、キャラクタ型特殊ファイル (たとえば、端末) の多数の操作属性は .Fn ioctl で制御できます。 引数 .Fa d は開いているファイル記述子である必要があります。 .Pp .Fn ioctl への 3 番めの引数は従来から .Va "char *argp" と名前付けられています。 しかし、 .Fx 3.0 での .Fn ioctl のほとんどの使用法では、3 番めの引数が .Vt caddr_t または .Vt int である必要があります。 .Pp .Fn ioctl の .Fa request は、引数が .Dq in 引数なのか .Dq out 引数なのかということと、引数 .Fa argp のサイズ (バイト単位) をエンコードします。 ioctl の .Fa request を指定するのに使用されるマクロと定義はファイル .In sys/ioctl.h の中にあります。 .Sh 戻り値 エラーが起きた場合は -1 が返され、エラーを示すために .Va errno が設定されます。 .Sh エラー .Fn ioctl システムコールは次の場合に失敗します: .Bl -tag -width Er .It Bq Er EBADF .Fa d 引数が有効な記述子ではありません。 .It Bq Er ENOTTY .Fa d 引数がキャラクタ型特殊デバイスに対応していません。 .It Bq Er ENOTTY 指定された要求は記述子 .Fa d が参照する種類のオブジェクトには適用されません。 .It Bq Er EINVAL .Fa request または .Fa argp 引数が有効ではありません。 .It Bq Er EFAULT .Fa argp 引数がプロセッサが割り当てたアドレス範囲外を指しています。 .El .Sh 関連項目 .Xr execve 2 , .Xr fcntl 2 , .Xr intro 4 , .Xr tty 4 .Sh 歴史 .Fn ioctl 関数は .At v7 ではじめて登場しました。