如何调用compat_ioctl或unlocked_ioctl?

gan*_*ars 4 ioctl linux-device-driver

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

当我换ioctlunlocked_ioctlcompat_ioctl,编译和为模插入.

但是调用ioctl用户应用程序而不是调用ioctl模块中的函数.我有什么功能在用户应用程序用来调用compat_ioctlunlocked_ioctl

Roc*_*der 8

检查驱动程序中的参数

定义结构文件操作定义如

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
};
Run Code Online (Sandbox Code Playgroud)

像ioctl一样定义

#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){
                ....................................
                ...................................
              }
    }
Run Code Online (Sandbox Code Playgroud)

和应用程序级别

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