编译LDD3-scull
1、提示scripts/Makefile.build:46:*** CFLAGS was changed in "/home/chenfang/scull/Makefile",Fix it use EXTRA_CFLAGS.Stop.:
由于LDD3使用的是2.6.10内核,很多东西已经发生了变化,这里提示我们修改Makefile中的CFLAGS,用EXTRA_CFLAGS代替,照它说的做就可以。
2、提示找不到文件linux/config.h:
在2.6.19开始的内核中删除了config.h文件,因此只要在mian.c中注释掉#include即可。
3、提示access.c中存在:dereferencing pointer to incomplete type 错误:
在
源码中发现只能是current存在错误,current应该是一个task_struct类型的全局变量,查找task_struct存在于
linux/sched.h中,因此在access.c中加入#include,重新make即可。
顺便看下current这个全局变量是在哪里定义的:
在source ininsight中查找得到的current类似于以下的定义:
static inline struct task_struct *get_current(void) __attribute_const__;
static inline struct task_struct *get_current(void)
{
return current_thread_info()->task;
}
#define current (get_current())
可
见,current其实是一个“伪全局变量”,是函数get_current()的宏定义。当access.c中使用current->uid时,
就调用了get_current()函数,从而返回task_struct结构的task,因此current->uid就相当于
task->uid。
之前在Ubuntu里编译scull时有错误,还好有网友提供了解决办法,即删除config.h文件和增加#include 两个头文件:capability.h和sched.h
最近将Ubuntu升级到9.10版本后,重新生成了2.6.31版本的内核树,没想到编译scull模块时出现新的
/home/dengwei/eclipse_workspace/scull/access.c:108: error: ‘struct task_struct’ has no member named ‘uid’
/home/dengwei/eclipse_workspace/scull/access.c:109: error: ‘struct task_struct’ has no member named ‘euid’
/home/dengwei/eclipse_workspace/scull/access.c:116: error: ‘struct task_struct’ has no member named ‘uid’
/home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_available’:
/home/dengwei/eclipse_workspace/scull/access.c:167: error: ‘struct task_struct’ has no member named ‘uid’
/home/dengwei/eclipse_workspace/scull/access.c:168: error: ‘struct task_struct’ has no member named ‘euid’
/home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_open’:
/home/dengwei/eclipse_workspace/scull/access.c:186: error: ‘struct task_struct’ has no member named ‘uid’
原因:
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
make success结果:
root@dw:/home/dengwei/eclipse_workspace/scull# ls
access.c main.o Module.symvers scull.init scull.mod.o
access.o Makefile pipe.c scull.ko scull.o
_desktop.ini Module.markers pipe.o scull_load scull_unload
main.c modules.order scull.h scull.mod.c
root@dw:/home/dengwei/eclipse_workspace/scull# insmod scull.ko
参考网站:
http://blog.163.com/chenfang7977@yeah/blog/static/1282741962010219327201/
http://hi.baidu.com/swinggucas/blog/item/32e1d3c3d4eacf3ee4dd3b22.html
阅读(1108) | 评论(0) | 转发(0) |