Linux如何知道调用哪个ioctl函数?
发布时间:2020-12-15 15:20:37 所属栏目: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密钥从/ dev / input / event *转换为ASCII
- linux – 如果我启动后台进程然后注销,它会继续运行吗?
- 可执行文件在linux上删除
- linux-kernel – IO-APIC级别与PCI-MSI-X之间的差异
- linux – 有没有一个工具来检查两个callgrind / valgrind配
- 在Linux上自动执行串口通讯
- linux – 如何避免在.so文件名中使用版本号
- LINUX教程:CentOS安装使用VNC进行远程桌面登录
- linux – LXC – Cgroup内存控制器:丢失
- SAP Java:java.lang.NoClassDefFoundError:com.sap.conn.
