linux-device-driver – 如何调用compat_ioctl或unlocked_ioctl
发布时间:2020-12-14 00:30:45 所属栏目:Linux 来源:网络整理
导读:我正在尝试为RTC(实时时钟)实现一个驱动程序.我在内核2.6.32中使用了ioctl函数.它工作正常.但是当我在内核3.13.0中运行相同的驱动程序时,它给出了一个错误’struct file_operations’没有名为’ioctl’的成员 当我将ioctl更改为unlocked_ioctl和compat_ioctl
我正在尝试为RTC(实时时钟)实现一个驱动程序.我在内核2.6.32中使用了ioctl函数.它工作正常.但是当我在内核3.13.0中运行相同的驱动程序时,它给出了一个错误’struct file_operations’没有名为’ioctl’的成员
当我将ioctl更改为unlocked_ioctl和compat_ioctl时,编译并模块化插入. 但是在用户应用程序中调用ioctl而不是在模块中调用ioctl函数.我必须在用户应用程序中使用什么函数来调用compat_ioctl或unlocked_ioctl? 解决方法
检查驱动程序中的参数
定义结构文件操作定义如 static struct file_operations query_fops = { .owner = THIS_MODULE,.open = my_open,.release = my_close,#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)) .ioctl = my_ioctl #else .unlocked_ioctl = my_ioctl #endif }; 像ioctl一样定义 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,35)) static int my_ioctl(struct inode *i,struct file *f,unsigned int cmd,unsigned long arg) #else static long my_ioctl(struct file *f,unsigned long arg) #endif { switch(cmd){ .................................... ................................... } } 和应用程序级别 无需进行任何修改,您可以在应用程序级别遵循ioctl的基本规则. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |