After calling a program for half a day, we found that the CMD parameter of the application's IOCTL was transferred to the driver's IOCTL. But according to the Linux device driver, the CMD should remain unchanged. Because the ioctl function pointer in struct file_operations has been completely deleted in kernel 2.6.36 and replaced by unlocked_ioctl, I suspect the two are compatible. I checked some information on the Internet. Many articles just talked about it in general, saying that IOCTL is compatible in applications and does not need to be changed. In the driver, the biggest impact of this pointer function change is that inode is missing in the parameter, so the application IOCTL is compatible, but our ioctl function in the driver must be changed, otherwise, the CMD parameter changes:
Original driver
Static const struct file_operations globalmem_fops =
{
. Owner = this_module,
. Llseek = globalmem_llseek,
. Open = globalmem_open,
. Read = globalmem_read,
. Write = globalmem_write,
. IOCTL = globalmem_ioctl,
. Release = globalmem_release,
};
Int globalmem_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, unsigned long Arg)
{
Switch (CMD)
{
Case: XXX :...
......
}
}
Changed
Static const struct file_operations globalmem_fops =
{
. Owner = this_module,
. Llseek = globalmem_llseek,
. Open = globalmem_open,
. Read = globalmem_read,
. Write = globalmem_write,
. Unlocked_ioctl = globalmem_ioctl,
. Release = globalmem_release,
};
Int globalmem_ioctl (struct file * filp, unsigned int cmd, unsigned long Arg) // No inode parameter!
{
Switch (CMD)
{
Case: XXX :...
......
}
}
Differences between IOCTL and unlock_ioctl