Linux device driver 如何调用compat_ioctl或unlocked_ioctl?

Linux device driver 如何调用compat_ioctl或unlocked_ioctl?,linux-device-driver,ioctl,Linux Device Driver,Ioctl,我正在尝试为RTC(实时时钟)实现一个驱动程序。我在内核2.6.32中使用了ioctl函数。它工作得很好。但是当我在内核3.13.0中运行同一个驱动程序时,它给出了一个错误,“struct file\u operations”没有名为“ioctl”的成员。 当我将ioctl更改为unlocked\u ioctl和compat\u ioctl时,编译并模块化插入 但是在用户应用程序中调用ioctl,而不是在模块中调用ioctl函数。我必须在用户应用程序中使用什么函数来调用compat\u ioct

我正在尝试为RTC(实时时钟)实现一个驱动程序。我在
内核2.6.32
中使用了
ioctl
函数。它工作得很好。但是当我在内核3.13.0中运行同一个驱动程序时,它给出了一个错误,
“struct file\u operations”没有名为“ioctl”的成员。

当我将
ioctl
更改为
unlocked\u ioctl
compat\u ioctl
时,编译并模块化插入


但是在用户应用程序中调用
ioctl
,而不是在模块中调用
ioctl
函数。我必须在用户应用程序中使用什么函数来调用
compat\u ioctl
unlocked\u 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
};
静态结构文件\u操作查询\u fops=
{
.owner=此_模块,
.open=my_open,
.release=my_close,
#if(LINUX版本代码<内核版本(2,6,35))
.ioctl=我的ioctl
#否则
.unlocked\u ioctl=我的\u ioctl
#恩迪夫
};
定义ioctl-like

#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){
                ....................................
                ...................................
              }
    }
#if(LINUX版本代码<内核版本(2,6,35))
静态int my_ioctl(结构索引节点*i,结构文件*f,无符号int cmd,无符号长参数)
#否则
静态长my_ioctl(结构文件*f,无符号int cmd,无符号长参数)
#恩迪夫
{
开关(cmd){
....................................
...................................
}
}
和应用级别


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

使用unlocked_ioctlgiving
参数验证错误:在标记“(”之前缺少二进制运算符
你能将模块插入吗???你得到错误的应用程序端或驱动程序端的确切位置?很抱歉,我忘了包括
linux/version.h
。我建议使用下面的宏,而不是版本检查,
\ifdef HAVE_UNLOCKED_IOCTL…\endif