tony之linux driver_LDD3_scull字符设备驱动编译在新内核编译问题

在编译ldd3的scull程序的时候碰到编译不通过的情况,发现遇到的问题和下面的哥们遇到的问题一样,

照着做了一下,解决问题,记录于此。

/*******************************************************************************************************************************************/

最近在看《LINUX设备驱动程序》,给出的字符设备驱动程序scull,在linux 2.6.32-22内核上make编译时出现了下面的问题:

make -C /lib/modules/2.6.32-22-generic/build M=/home/savi0r/Desktop/linux设备驱动开发/examples/scull LDDINC=/home/savi0r/Desktop/linux设备驱动开发/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/savi0r/Desktop/linux设备驱动开发/examples/scull/Makefile". Fix it to use EXTRA_CFLAGS.  Stop.
make[1]: *** [_module_/home/savi0r/Desktop/linux设备驱动开发/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

打开Makefile,将CFLAGS屏蔽掉:
# CFLAGS += $(DEBFLAGS)
# CFLAGS += -I$(LDDINC)

继续make,又出现了下面的问题:
make -C /lib/modules/2.6.32-22-generic/build M=/home/savi0r/Desktop/linux设备驱动开发/examples/scull LDDINC=/home/savi0r/Desktop/linux设备驱动开发/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M]  /home/savi0r/Desktop/linux设备驱动开发/examples/scull/main.o
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/main.c:17:26: error: linux/config.h: No such file or directory
make[2]: *** [/home/savi0r/Desktop/linux设备驱动开发/examples/scull/main.o] Error 1
make[1]: *** [_module_/home/savi0r/Desktop/linux设备驱动开发/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

linux/config.h文件找不到,可能时新版内核结构改变了,这个文件被删除了吧。
打开main.c,把#include <linux/config.h>删除掉。

继续make,还有问题:
make -C /lib/modules/2.6.32-22-generic/build M=/home/savi0r/Desktop/linux设备驱动开发/examples/scull LDDINC=/home/savi0r/Desktop/linux设备驱动开发/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M]  /home/savi0r/Desktop/linux设备驱动开发/examples/scull/main.o
CC [M]  /home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.o
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c: In function ‘scull_p_read’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:131: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:131: error: (Each undeclared identifier is reported only once
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:131: error: for each function it appears in.)
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:131: error: implicit declaration of function ‘signal_pending’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:131: error: implicit declaration of function ‘schedule’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c: In function ‘scull_getwritespace’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:168: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c: In function ‘scull_p_write’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:219: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:223: error: ‘SIGIO’ undeclared (first use in this function)
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.c:223: error: ‘POLL_IN’ undeclared (first use in this function)
make[2]: *** [/home/savi0r/Desktop/linux设备驱动开发/examples/scull/pipe.o] Error 1
make[1]: *** [_module_/home/savi0r/Desktop/linux设备驱动开发/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

TASK_INTERRUPTIBLE找不到,既然前面删除掉了了一个头文件,必然有很多变量找不到,
那就到
/usr/src/linux-headers-2.6.32-22-generic下grep一下呗:
最终找到头文件,添加上:
#include <linux/sched.h>

access.c也需要添加上面的头文件。

然后,还得make,痛苦阿。。。。

make -C /lib/modules/2.6.32-22-generic/build M=/home/savi0r/Desktop/linux设备驱动开发/examples/scull LDDINC=/home/savi0r/Desktop/linux设备驱动开发/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M]  /home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.o
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c: In function ‘scull_u_open’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:107: error: ‘struct task_struct’ has no member named ‘uid’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:108: error: ‘struct task_struct’ has no member named ‘euid’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:115: error: ‘struct task_struct’ has no member named ‘uid’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c: In function ‘scull_w_available’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:166: error: ‘struct task_struct’ has no member named ‘uid’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:167: error: ‘struct task_struct’ has no member named ‘euid’
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c: In function ‘scull_w_open’:
/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.c:185: error: ‘struct task_struct’ has no member named ‘uid’
make[2]: *** [/home/savi0r/Desktop/linux设备驱动开发/examples/scull/access.o] Error 1
make[1]: *** [_module_/home/savi0r/Desktop/linux设备驱动开发/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

说task_struct结构体没有uid,euid成员变量,
struct task_struct定义在include/linux/sched.h中,这主要是由于原来task_struct结构体定义有所改动,将uid和euid等挪到 cred中,见include/linux/sched.h和include/linux/cred.h。

因此只需要将报error的代码做如下修改
current->uid 修改为 current->cred->uid
current->euid 修改为 current->cred->euid

然后编译,即可通过。

/*******************************************************************************************************************************************/

在redhat2.6.9.55上面编译是OK的,貌似LDD3是基于内核2.6.10来写的。


你可能感兴趣的:(linux,struct,function,Module,makefile,Signal)