Linux2.6.38中驱动使用unlocked_ioctl,于是我就将file_operations中的ioctl换成unlocked_ioctl,但编译结果有warning:initialization from incompatible pointer type,后来才发现unlocked_ioctl与ioctl不只是名字变了,参数与返回值也变了。
区别如下:
ioctl原型为:int ioctl(struct inode *inode,struct file *filp,unsigned int cmd,unsigned long arg)
unlocked_ioctl原型为:long unlocked_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
即:后者返回值由原来的int变为long,函数参数少了一个inode。
即使参数改为一致,但int没改成long,也会出现警告,需要完全一致。
另:ioctl与unlocked_ioctl在应用程序中是完全一样的。
本文详细解析了Linux内核中ioctl与unlocked_ioctl的区别,包括它们的参数类型及返回值的变化,并指出了在替换使用时需要注意的问题。
1291

被折叠的 条评论
为什么被折叠?



