IOCTL错误

 gpiodevice.c:97:3: error: unknown field ‘ioctl’ specified in initializer
   .ioctl = gpio_ioctl,
内核版本是3.10.x,编写一个gpio 模块,调用ioctl,报错,网上查了查是现在不支持ioctl了····技术果然也在更新换代啊···自己参照网上的用法用了unlocked_ioctl,另外参数也少了一个需要注意,
引用http://blog.chinaunix.net/uid-24943863-id-3191465.html 下的说法。“
/home/jqzeng/workSpace/ldd3/ldd3-samples-1.0.0/scull/main.c:556:2: error: unknown field 'ioctl' specified in initializer
 
ioctl是未知域,查看file_operations结构体,在build/inlcude/linux/fs.h中的1603行定义,前面有两句话
 /* These macros are for out of kernel modules to test that
  * the kernel supports the unlocked_ioctl and compat_ioctl
  * fields in struct file_operations. */
根据开发者的意见,ioctl使用了大内核锁,这个是不安全的,新的kerne将l不再支持ioctl方法,而应该使用 unlocked_ioctl或者compat_ioctl。修改main.c中556行的.ioctl为unlocked_ioctl,这个错误不会出现了。同时,这个函数指针的原型也改变了!
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 
与原来的ioctl函数原型相比少传递了struct inode *inode 这个变量,因此我们的实现scull_ioctl需要变为
main.c
394  int scull_ioctl(struct file *filp,
395                        unsigned int cmd, unsigned long arg)
scull.h
131 int     scull_ioctl(struct file *filp,
132                     unsigned int cmd, unsigned long arg);
 
接着,出现另外一个问题:
/home/jqzeng/workSpace/ldd3/ldd3-samples-1.0.0/scull/main.c:652:3: error: implicit declaration of function 'init_MUTEX
 
与前一个错误来源一样,init_MUTEX(&sem)在新内核里也被弃用了。用sema_init(&sem,1)进行替换可解决此问题。
好了,main.c的问题解决了,pipe.c编译的时候出现了一大堆问题了。 ”
原文地址:https://www.cnblogs.com/yinseyingji/p/7550085.html