Ldd3学习遇到的linux升版问题汇总

来自个人维基
跳转至: 导航搜索

说明一下,我的环境为Ubuntu11.04 64bits.


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、error: unknown field 'ioctl' specified in initializer

file_operations结构发生了重大变化,取消了原有的ioctl成员,添加来新的成员:

long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);    原来的ioctl 但是返回值变为long
long (*compat_ioctl) (struct file *, unsigned int, unsigned long); 内核空间64位,用户空间32位

关于这一点,这里有一篇不错的文章.


4、error: implicit declaration of function ‘init_MUTEX’

2.6.25以后找不到这个函数,但在2.6.16以前可以找到源码(http://lxr.oss.org.cn/source/include/asm-i386/semaphore.h#L89):

static inline void init_MUTEX (struct semaphore *sem)
{
    sema_init(sem, 1);
}
static inline void init_MUTEX_LOCKED (sturct semaphore *sem)
{
    sema_init(sem, 0);
}

故,改为用sema_init替代。


5、error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)

到/usr/src/linux-headers-2.6.32-22-generic下grep一下,终于找到头文件:#include <linux/sched.h> ,加上

6、error: ‘struct task_struct’ has no member named ‘uid’; error: ‘struct task_struct’ has no member named ‘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


7、error: macro "INIT_WORK" passed 3 arguments, but takes just 2

从kernel 2.6.20开始,workqueue中INIT_WORK的原型的参数由三个变为两个了。据说改动的原因是在64位平台上,work_queue这个常用的数据结构的占用内存过大( http://lwn.net/Articles/211279/ )。当然,你可以选择很生猛地将第三个参数直接删掉,据说这样也是可以编译通过的。但这样程序行为多半就会变得很诡异了。

目前较为流行的做法,是定义一个自己的数据结构包含work_struct和参数,然后在注册函数中用container_of来得到自己的数据结构地址,从而得到参数的地址。

以编译出错的jiq.c为例,修改代码如下。

新加数据结构:

   static struct my_work_struct_t {  
       void *              ptr;  
       struct work_struct  jiq_work;  
   } my_work_struct;  

jiq_init中加:

   my_work_struct.ptr = (void *)(&jiq_data);

然后INIT_WORK改为:

   INIT_WORK(&(my_work_struct.jiq_work), jiq_print_wq);

Jiq_print_wq的函数体变为:

   static void jiq_print_wq(struct work_struct *pwork)  
   {  
       struct my_work_struct_t * my_work_struct =   
           container_of(pwork, struct my_work_struct_t, jiq_work);  
       struct clientdata *pdata = (struct clientdata *)(my_work_struct->ptr);   
         
       if (! jiq_print (my_work_struct->ptr))  
           return;  
         
       if (pdata->delay)  
           schedule_delayed_work(pwork, pdata->delay);  
       else  
           schedule_work(pwork);  
   }  


8、error: ‘system_utsname’ undeclared

System_ustname的定义在较新的kernel中被删掉了(git commit id: 56b0a8c5ec7ee4f6cb48de587aa7d83d96d1f64d)。为了编译通过,可直接把这行在源文件中加回来了:

#define system_utsname init_uts_ns.name


参考:

http://www.cnblogs.com/fly-fish/archive/2011/08/18/2145134.html

http://blog.csdn.net/zhou1232006/article/details/6867584

http://archive.cnblogs.com/a/2152434/

http://www.linuxidc.com/Linux/2011-04/33962.htm

http://blog.csdn.net/ariesjzj/article/details/6780051