1. ioctl

ioctl - 设备控制

1.1. 概述

#include <sys/ioctl.h>
int ioctl(int d, int request, ...);

1.2. 描述

ioctl()函数操作基础的字符文件设备。通常,一些字符设备会请求被ioctl控制(例如:终端)。

d参数必须是打开的文件描述符。 第二个参数是一个设备相关请求码。 第三个参数是一个无类型的内存指针。

It's traditionally char *argp (from the days before void * was valid C), and will be so named for this discussion.

An ioctl() request has encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes.

Macros and defines used in specifying an ioctl() request are located in the file .

1.3. 返回值

正常返回0, A few ioctl() requests use the return value as an output parameter and return a non-negative value on success.发生错误时返回-1,并置 errno 为相应值.

1.4. 错误类型

EBADF : d是一个非法文件描述符 EFAULT : argp references an inaccessible memory area. EINVAL : 请求或argp 无效 ENOTTY : d is not associated with a character special device. ENOTTY : The specified request does not apply to the kind of object that the descriptor d references.

1.5. CONFORMING TO

No single standard. Arguments, returns, and semantics of ioctl() vary according to the device driver in question (the call is used as a catch-all for operations that don't cleanly fit the Unix stream I/O model). See ioctl_list(2) for a list of many of the known ioctl() calls. The ioctl() function call appeared in Version 7 AT&T Unix.

1.6. 注意

使用ioctl调用需要有一个打开的文件描述符 Often the open(2) call has unwanted side effects, that can be avoided under Linux by giving it the O_NONBLOCK flag.

1.7. 参见

execve(2), fcntl(2), ioctl_list(2), open(2), sd(4), tty(4)

1.8. 版本记录

This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.

Copyright © 温玉 2021 | 浙ICP备2020032454号 all right reserved,powered by Gitbook该文件修订时间: 2023-06-19 08:59:50

results matching ""

    No results matching ""