Ioctl設備方法學習中遇到的一些問題

Ioctl設備方法

執行make後顯示

error: implicit declaration of function'kmalloc'

error: implicit declaration of function'kfree'

經查到是缺少頭文件#include <linux/slab.h>

然後再make後顯示:錯誤:初始值設定項裏有未知的字段‘ioctl’

這個錯誤原來是新的內核裏面已經刪除了ioctl函數,取代的是

long (*unlocked_ioctl) (struct file *,unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int,unsigned long);

我將static const struct file_operations結構體中的.ioctl改爲.compat_ioctl,然後在測試程序測試時一直調不到ioctl()函數,原因是對於compat_sys_ioctl系統調用的使用比較麻煩一些,因爲默認kernel是不將它built-in進內核的,
可以通過fs/Makefile看到如下定義obj-$(CONFIG_COMPAT)+= compat.o compat_ioctl.o
對於CONFIG_COMPAT的定義於cpu體系結構有關,就是說CONFIG_COMPAT這個宏不打開的話compat_ioctl是編不進內核的, 所以又改爲.unlocked_ioct才解決問題

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章