0
我有以下chardev定义:入门上的ioctl ENOTTY针对Linux内核模块
.H
#define MAJOR_NUM 245
#define MINOR_NUM 0
#define IOCTL_MY_DEV1 _IOW(MAJOR_NUM, 0, unsigned long)
#define IOCTL_MY_DEV2 _IOW(MAJOR_NUM, 1, unsigned long)
#define IOCTL_MY_DEV3 _IOW(MAJOR_NUM, 2, unsigned long)
模块的.c
static long device_ioctl(
struct file* file,
unsigned int ioctl_num,
unsigned long ioctl_param)
{
...
}
static int device_open(struct inode* inode, struct file* file)
{
...
}
static int device_release(struct inode* inode, struct file* file)
{
...
}
struct file_operations Fops = {
.open=device_open,
.unlocked_ioctl= device_ioctl,
.release=device_release
};
static int __init my_dev_init(void)
{
register_chrdev(MAJOR_NUM, "MY_DEV", &Fops);
...
}
module_init(my_dev_init);
我的用户代码
ioctl(fd, IOCTL_MY_DEV1, 1);
始终以相同错误失败:ENOTTY
Inappropriate ioctl for device
我已经看到了类似的问题: 即
Linux kernel module - IOCTL usage returns ENOTTY
Linux Kernel Module/IOCTL: inappropriate ioctl for device
但对我来说
您是否验证过您的'device_ioctl()'是否被调用? (在那里放一个printk调用) – nos
@nos我的'device_ioctl()'没有被调用,只用'printk'放置一个空的主体 – Mugen
你没有很好的注册ioctl的调用版本...试试锁定的版本。 –