这里是用户空间中的 ioctl
调用:
int ioctl(int fd, int cmd, ...);
据我所知,当我们想要执行IO操作时,我们需要定义自己的
ioctl
函数和一组请求(命令),将我们的ioctl
赋值给file_operations结构体,代码如下:struct file_operations fops = {
.read = device_read,
.write = device_write,
.ioctl = device_ioctl, // device_ioctl is our function
.open = device_open,
.release = device_release,
};
而且,与用户空间接口相比,device_ioctl
函数的定义有所不同:
static long device_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
我认为基于文件描述符,内核可以获得适当的文件结构并调用设备的
ioctl
函数。这只是猜测,因为我找不到内核根据传递给通用ioctl
接口的文件描述符fd
选择适当的ioctl
函数的通用函数定义。我只能找到3个ioctl
定义,但显然这些只是设备的定义,而不是内核的定义:ioctl。