linux驱动学习笔记(2.3) scull模块 init_MUTEX被废除

一、今天在编译ldd3上的scullc的时候,出现如下错误:

clip_image006

刚开始我以为没有包含头文件,然后我就去查2.6.39.1的源代码,结果在所有的符号中都没有发现init_MUTEX,后面在网站上发现了init_MUTEX的定义,如下所示:

clip_image007

源码衔接:

http://lxr.oss.org.cn/source/include/asm-i386/semaphore.h#L89

上面的源码是2.6.16以前的,在2.6.25以后就再也找不到这个宏了,原因我目前不清楚,根据定义就已经可以把问题解决了,将代码改成下面的就行了:

clip_image008

二.排出此问题,出现例外一个问题

image

原因:在2.6.32 linux/fs/ntfs/ChangeLog 看到如下片段

01672.1.26 - Minor bug fixes and updates.
02 68
03 69        - Fix a potential overflow in file.c where a cast to s64 was missing in
04 70          a left shift of a page index.
05 71        - The struct inode has had its i_sem semaphore changed to a mutex named
06 72          i_mutex.
07<font style="background-color: #ffff00"> 73        - We have struct kmem_cache now so use it instead of the typedef
08 74          kmem_cache_t.  (Pekka Enberg)</font>
09 75        - Implement support for sector sizes above 512 bytes (up to the maximum
10 76          supported by NTFS which is 4096 bytes).
11 77        - Do more detailed reporting of why we cannot mount read-write by
12 78          special casing the VOLUME_MODIFIED_BY_CHKDSK flag.

解决 修改main.c中的 52 53 54行

1/* declare one cache pointer: use it for all devices */
2//kmem_cache_t *scullc_cache;
3struct kmem_cache *scullc_cache;

三,问题又来了

01home/allen/share/ldd3/src/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
02/home/allen/share/ldd3/src/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
03/home/allen/share/ldd3/src/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’
04/home/allen/share/ldd3/src/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’
05/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_getwritespace’:
06/home/allen/share/ldd3/src/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
07/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_p_write’:
08/home/allen/share/ldd3/src/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
09/home/allen/share/ldd3/src/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
10/home/allen/share/ldd3/src/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
11/home/allen/share/ldd3/src/scull/pipe.c: At top level:
12/home/allen/share/ldd3/src/scull/pipe.c:319:2: error: unknown field ‘ioctl’ specified in initializer
13/home/allen/share/ldd3/src/scull/pipe.c:319:2: warning: initialization from incompatible pointer type
14/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_p_init’:
15/home/allen/share/ldd3/src/scull/pipe.c:365:3: error: implicit declaration of function ‘init_MUTEX’
16make[2]: *** [/home/allen/share/ldd3/src/scull/pipe.o] Error 1
17make[1]: *** [_module_/home/allen/share/ldd3/src/scull] Error 2

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

 

unknown field ‘ioctl’ specified in initializer

是因为ioctl接口更换的问题。

使用.unlocked_ioctl =    scull_ioctl,

 

error: implicit declaration of function ‘init_MUTEX’

此问题前面也曾提到

 

四.做如下替换

//int scull_ioctl(struct inode *inode, struct file *filp,
//                unsigned int cmd, unsigned long arg)

long scull_ioctl( struct file *filp,
                 unsigned int cmd, unsigned long arg)

五。到此编译成功

01root@ubuntu:/home/allen/share/ldd3/src/scull# make
02make -C /usr/src/linux-headers-2.6.38-8-generic/ M=/home/allen/share/ldd3/src/scull LDDINC=/home/allen/share/ldd3/src/scull/../include modules
03make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
04  CC [M]  /home/allen/share/ldd3/src/scull/main.o
05  CC [M]  /home/allen/share/ldd3/src/scull/pipe.o
06  CC [M]  /home/allen/share/ldd3/src/scull/access.o
07  LD [M]  /home/allen/share/ldd3/src/scull/scull.o
08  Building modules, stage 2.
09  MODPOST 1 modules
10  CC      /home/allen/share/ldd3/src/scull/scull.mod.o
11  LD [M]  /home/allen/share/ldd3/src/scull/scull.ko
12make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值