gpiodevice.c:97:3: error: unknown field ‘ioctl’ specified in initializer
.ioctl = gpio_ioctl,
.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編譯的時候出現了一大堆問題了。 ”
