IOCTL and UNLOCK_IOCTL functions
This article turns from: http://blog.csdn.net/punk_lover/article/details/19610643
but I may have ignored the return value type of the function as long
When I was working, I found a warning when I compiled the program.
"Warning:initialization from incompatible pointer type [enabled by default]
: Warning: (near initialization for ' Hello_fops.unlocked_ioctl ') [enabled by default]
The details are found because the function return value type is long integer
Today, a program tuned for half a day, found that the application of the ioctl cmd parameter to the driver ioctl changed. And according to "Linux device driver" This cmd should be unchanged. Since the IOCTL function pointer in the struct file_operations has been completely removed in the kernel 2.6.36, Unlocked_ioctl is replaced, so I suspect that the two are not compatible. On the Internet to check some information, a lot of articles just general talk about, said in the application IOCTL is compatible, do not have to change. The biggest effect of this pointer function in the driver is that the inode is less in the parameter, so the application IOCTL is compatible, but our IOCTL function in the driver must change, otherwise the cmd parameter will change:
The 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: ...
......
}
}
After the change
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,
};
Long Globalmem_ioctl (struct file* filp, unsigned int cmd,unsigned long arg)//no inode parameter. The return value is long.
{
Switch (CMD)
{
Case:xxx: ...
......
}
}
Summary: When IOCTL changed to Unlocked_ioctl, there were two changes: one was that the return value type changed to a long integer; the second one was less the first parameter inode;
Note that the corresponding change in file_operations to Unlocked_ioctl