Linux如何知道调用哪个ioctl函数?
发布时间:2020-12-15 15:26:41 所属栏目: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 – 如何跟踪EC2实例或弹性IP上的公共带宽使用情况?
- linux – 我可以将(大)地址块绑定到接口吗?
- 有没有办法确定Linux上的库使用的线程本地存储模型
- linux – Ubuntu / Mint上的PhpStorm更新
- c – waitpid和pthread_cond_wait(3)
- Linux上的编译器是否支持Objective-C块?
- Mount NAS Storage in Linux Overview 转载
- linux – 在bash中将apache日志日期格式转换为epoch
- 如何在Linux中创建MP3的波形图?
- linux – 我想使用“awk”或sed打印文件中以“comm =”开头
推荐文章
站长推荐
- linux – 为什么clock_gettime(CLOCK_REALTIME,.
- Linux上的C / Assembly IDE
- linux – 现代cpus如何处理跨页未对齐访问?
- linux-kernel – 编译Linux内核错误xt_CONNMARK.
- linux – 启动/停止或重启后,AMI启动的EC2实例无
- linux – xprop设置atom属性的多个字段
- linux – 如何让apache包含文件夹中的所有文件
- linux – Varnish无法启动:无法从共享对象映射段
- LINUX实操:Ubuntu 16.04安装Adobe AIR
- 如何在Linux / Fedora中使用Qt的’windeployqt’
热点阅读
