在编写ioctl驱动后,利用应用程序检验编写的驱动是否正确时,应用层ioctl(fd,cmd,arg)一直返回值-1,我怀疑是ioctl函数有问题。发现file_operations 中ioctl用的是 .unlocked_ioctl .
/* 设备操作函数 */
static struct file_operations timer_fops = {
.owner = THIS_MODULE,
.open = timer_open,
.unlocked_ioctl = timer_unlocked_ioctl,
};
查找资料得知, 正常的情况下,对Ioctl的调用,会走unlock_ioctl,但在32位系统64位的内核上面会走compat_ioctl接口,这就是compat_ioctl存在的意义,由于我使用的linux系统是32位,内核编译的是arm64,问题解决;
long (unlocked_ioctl) (struct file , unsigned int, unsigned long);
long (compat_ioctl) (struct file , unsigned int, unsigned long);