linux-device-driver – 如何调用compat_ioctl或unlocked_ioctl?

linux-device-driver – 如何调用compat_ioctl或unlocked_ioctl?,第1张

概述我正在尝试为RTC(实时时钟)实现一个驱动程序.我在内核2.6.32中使用了ioctl函数.它工作正常.但是当我在内核3.13.0中运行相同的驱动程序时,它给出了一个错误’struct file_operations’没有名为’ioctl’的成员 当我将ioctl更改为unlocked_ioctl和compat_ioctl时,编译并模块化插入. 但是在用户应用程序中调用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)#elsestatic long my_ioctl(struct file *f,unsigned long arg)        #endif    {              switch(cmd){                ....................................                ...................................              }    }

和应用程序级别

无需进行任何修改,您可以在应用程序级别遵循ioctl的基本规则.

总结

以上是内存溢出为你收集整理的linux-device-driver – 如何调用compat_ioctl或unlocked_ioctl?全部内容,希望文章能够帮你解决linux-device-driver – 如何调用compat_ioctl或unlocked_ioctl?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1023634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存