LDD3学习笔记--scull的编译

学习ldd3,内核太新以至于scull编译不过,自己搞不定上网查资料,发现这位老兄把我的问题都解决了(赞!)。
原文链接    http://www.diybl.com/course/6_system/linux/Linuxjs/20101230/551519.html
----------

我的linux系统是 Ubuntu 10.04,内核版本是
root@libin:~# uname -ar
Linux libin 2.6.32-26-generic #47-Ubuntu SMP Wed Nov 17 15:59:05 UTC 2010 i686 GNU/Linux

LDD3中,内核代码是2.6.10,所以从下载下来的代码不能够直接编译。
首先是 Makefile我在网上查,发现 CFLAG不能修改,所以把Makefile中的CFLAGS用EXTRAFLAGS取代

然后报错的是main.c   /linux/config.h不存在。我查看后,发现的确不存在。
root@libin:/usr/src/linux-headers-2.6.32-26-generic/include/linux# ll config.h
ls: 无法访问config.h: 没有那个文件或目录

1 将main.c中#include <linux/config.h>改为 #include<linux/autoconf.h>
发现出现如下打印信息
/home/libin/project/ldd3/examples/scull/pipe.c: In function ‘scull_p_read’:
/home/libin/project/ldd3/examples/scull/pipe.c:132: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/pipe.c:132: error: (Each undeclared identifier is reported only once
/home/libin/project/ldd3/examples/scull/pipe.c:132: error: for each function it appears in.)
/home/libin/project/ldd3/examples/scull/pipe.c:132: error: implicit declaration of function ‘signal_pending’
/home/libin/project/ldd3/examples/scull/pipe.c:132: error: implicit declaration of function ‘schedule’
/home/libin/project/ldd3/examples/scull/pipe.c: In function ‘scull_getwritespace’:
/home/libin/project/ldd3/examples/scull/pipe.c:169: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/pipe.c: In function ‘scull_p_write’:
/home/libin/project/ldd3/examples/scull/pipe.c:220: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/pipe.c:224: error: ‘SIGIO’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/pipe.c:224: error: ‘POLL_IN’ undeclared (first use in this function)
make[2]: *** [/home/libin/project/ldd3/examples/scull/pipe.o] 错误 1
make[1]: *** [_module_/home/libin/project/ldd3/examples/scull] 错误 2
make[1]:正在离开目录 `/usr/src/linux-headers-2.6.32-26-generic'

2 将pipe.c 中添加头文件  linux/sched.h。 即添加 #include<linux/sched.h>
重新make 发现如下打印/home/libin/project/ldd3/examples/scull/access.c: In function ‘scull_u_open’:
/home/libin/project/ldd3/examples/scull/access.c:107: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c:108: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c:115: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c: In function ‘scull_w_available’:
/home/libin/project/ldd3/examples/scull/access.c:166: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c:167: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c: In function ‘scull_w_open’:
/home/libin/project/ldd3/examples/scull/access.c:180: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/access.c:180: error: (Each undeclared identifier is reported only once
/home/libin/project/ldd3/examples/scull/access.c:180: error: for each function it appears in.)
/home/libin/project/ldd3/examples/scull/access.c:180: error: implicit declaration of function ‘signal_pending’
/home/libin/project/ldd3/examples/scull/access.c:180: error: implicit declaration of function ‘schedule’
/home/libin/project/ldd3/examples/scull/access.c:185: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c: In function ‘scull_w_release’:
/home/libin/project/ldd3/examples/scull/access.c:206: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/libin/project/ldd3/examples/scull/access.c: In function ‘scull_c_open’:
/home/libin/project/ldd3/examples/scull/access.c:278: error: dereferencing pointer to incomplete type
/home/libin/project/ldd3/examples/scull/access.c:282: error: dereferencing pointer to incomplete type
make[2]: *** [/home/libin/project/ldd3/examples/scull/access.o] 错误 1
make[1]: *** [_module_/home/libin/project/ldd3/examples/scull] 错误 2
make[1]:正在离开目录 `/usr/src/linux-headers-2.6.32-26-generic'
make: *** [modules] 错误 2

3 在access.c添加 <linux/sched.h>
make 会出现
error: 'struct task_struct' has no member named 'uid'error: 'struct task_struct' has no member named 'euid'
4struct 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

然后make,就大功告成了
----------

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