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才解决问题