首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何称呼compat_ioctl或unlocked_ioctl?

如何称呼compat_ioctl或unlocked_ioctl?
EN

Stack Overflow用户
提问于 2014-05-17 07:12:43
回答 1查看 14K关注 0票数 5

我正在尝试为RTC (实时时钟)实现一个驱动程序。我在ioctl中使用了kernel 2.6.32函数。效果很好。但是,当我在内核3.13.0中运行相同的驱动程序时,它给出了一个错误‘struct file_operations’ has no member named ‘ioctl’

当我将ioctl更改为unlocked_ioctlcompat_ioctl时,编译并模块化了插入。

但是在用户应用程序中调用ioctl函数,而不是在模块中调用函数。我必须在用户应用程序中使用什么功能来调用compat_ioctlunlocked_ioctl

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-17 11:05:32

检查驱动程序中的参数

定义结构文件操作定义,如

代码语言:javascript
复制
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类

代码语言:javascript
复制
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,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 int cmd, unsigned long arg)
        #endif
    {
              switch(cmd){
                ....................................
                ...................................
              }
    }

和应用水平

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

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23708661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档