我定义了以下 chardev:
。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
设备的 ioctl 不合适
我见过类似的问题:即
Linux 内核模块 - IOCTL 使用返回 ENOTTY
Linux 内核模块/IOCTL:设备的 ioctl 不合适
但是他们的解决方案对我不起作用