我需要使用ioctl
. 我需要使用ioctl(fd, USBDEVFS_REAPURBNDELAY, &receive);
。但是USBDEVFS_REAPURBNDELAY
在内核头文件中定义,所以我包含一些这样的内核文件:
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <asm/byteorder.h>
#include <linux/usb/ch9.h>
并编译它gcc -g -I /usr/src/linux-3.4.4-2-pae/include/ -o /home/madper/kernel/usb/select_for_usb /home/madper/kernel/usb/select_for_usb.c
它说#warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" [-Wcpp]
并且伴随着很多错误,那么,使用内核头文件的正确方法是什么?
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:21:2: error: unknown type name ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:36:2: error: unknown type name ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:37:33: error: ‘kernel_ulong_t’ undeclared here (not in a function)
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:37:3: error: requested alignment is not an integer constant
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:119:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:141:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:154:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:168:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:179:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:187:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:195:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:200:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:227:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:260:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:314:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:341:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:366:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:413:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:433:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:444:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:479:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:508:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:540:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:551:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:566:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/usr/src/linux-3.4.4-2-pae/include/linux/mod_devicetable.h:582:2: error: expected specifier-qualifier-list before ‘kernel_ulong_t’
/home/madper/kernel/usb/select_for_usb.c: In function ‘main’:
/home/madper/kernel/usb/select_for_usb.c:46:30: error: expected expression before ‘void’