Linux Kernel Module/IOCTL: inappropriate ioctl for device

本秂侑毒 提交于 2019-12-05 04:33:00

Okay. So. Here's the solution.

In Linux kernel 2.6.x the declaration for _ioctl calls changed from

static long wait_ioctl(struct inode *, struct file *, unsigned int, unsigned long);

To:

static long wait_ioctl(struct file *, unsigned int, unsigned long);

The fix is thus:

...
static long wait_ioctl(struct file *, unsigned int, unsigned long);
...
static long wait_ioctl(struct file *file, unsigned int cmd, unsigned long sub_cmd){
    if(_IOC_TYPE(cmd) != WAIT_DEVICE_MAGIC){
       printk(KERN_INFO "[wait device] invalid magic number: %u:%u:%u", _IOC_TYPE(cmd), cmd, WAIT_DEVICE_MAGIC);
       return -ENOTTY;
    }
 ....

.compat_ioctl

Also make sure to implement this file_operation if you are making 32-bit calls to a 64-bit kernel.

The symptom is that your ioctl handler is never run.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!