Linux如何知道调用哪个ioctl函数?
发布时间:2020-12-15 16:23:06 所属栏目:Linux 来源:互联网
导读:这是用户空间中的ioctl调用: int ioctl(int fd, int cmd, ...); 据我所知,当我们想要执行IO操作时,我们使用一组请求(命令)定义我们自己的ioctl函数,将我们的ioctl分配给这样的file_operations结构: struct file_operations fops = { .read = device_read, .
这是用户空间中的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 解决方法查看Linux源代码,fs / ioctl.c( http://lxr.free-electrons.com/source/fs/ioctl.c)在那里你会看到ioctl的系统调用: SYSCALL_DEFINE3(ioctl,unsigned int,fd,cmd,unsigned long,arg) 这反过来调用do_vfs_ioctl(),它调用vfs_ioctl(),然后调用file_operations结构中为该文件系统定义的unlocked_ioctl函数.这将是您注册的device_ioctl函数. (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- linux – make / home / tmp noexec nodev没有单独的patiti
- linux – 与ext4结合使用的透明压缩文件系统
- linux – 如何用AWK选择一些列?
- linux – 我想使用“awk”或sed打印文件中以“comm =”开头
- linux-kernel – Linux:使用U-Boot和Flat Image Tree(FIT)
- Linux中硬件辅助磁盘加密的状态
- /bin/bash^M: bad interpreter: 没有那个文件或目录--转载
- linux – FindXXX.cmake文件的本地编译库的正确位置是什么?
- linux – 无法从外部机器访问公开暴露的Docker容器端口,只能
- 如何在IEEE802.11框架内找到封装协议?