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

时间:2021-06-26 23:35:44

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

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

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

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

源码衔接:

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

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

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

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

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

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

  672.1.26 - Minor bug fixes and updates.
68
69 - Fix a potential overflow in file.c where a cast to s64 was missing in
70 a left shift of a page index.
71 - The struct inode has had its i_sem semaphore changed to a mutex named
72 i_mutex.
73 - We have struct kmem_cache now so use it instead of the typedef
74 kmem_cache_t. (Pekka Enberg)

75 - Implement support for sector sizes above 512 bytes (up to the maximum
76 supported by NTFS which is 4096 bytes).
77 - Do more detailed reporting of why we cannot mount read-write by
78 special casing the VOLUME_MODIFIED_BY_CHKDSK flag.

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

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

三,问题又来了

home/allen/share/ldd3/src/scull/pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/allen/share/ldd3/src/scull/pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
/home/allen/share/ldd3/src/scull/pipe.c:131:3: error: implicit declaration of function ‘signal_pending’
/home/allen/share/ldd3/src/scull/pipe.c:131:3: error: implicit declaration of function ‘schedule’
/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_getwritespace’:
/home/allen/share/ldd3/src/scull/pipe.c:168:38: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_p_write’:
/home/allen/share/ldd3/src/scull/pipe.c:219:2: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/allen/share/ldd3/src/scull/pipe.c:223:34: error: ‘SIGIO’ undeclared (first use in this function)
/home/allen/share/ldd3/src/scull/pipe.c:223:41: error: ‘POLL_IN’ undeclared (first use in this function)
/home/allen/share/ldd3/src/scull/pipe.c: At top level:
/home/allen/share/ldd3/src/scull/pipe.c:319:2: error: unknown field ‘ioctl’ specified in initializer
/home/allen/share/ldd3/src/scull/pipe.c:319:2: warning: initialization from incompatible pointer type
/home/allen/share/ldd3/src/scull/pipe.c: In function ‘scull_p_init’:
/home/allen/share/ldd3/src/scull/pipe.c:365:3: error: implicit declaration of function ‘init_MUTEX’
make[2]: *** [/home/allen/share/ldd3/src/scull/pipe.o] Error 1
make[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)

五。到此编译成功

root@ubuntu:/home/allen/share/ldd3/src/scull# make
make -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
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
CC [M] /home/allen/share/ldd3/src/scull/main.o
CC [M] /home/allen/share/ldd3/src/scull/pipe.o
CC [M] /home/allen/share/ldd3/src/scull/access.o
LD [M] /home/allen/share/ldd3/src/scull/scull.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/allen/share/ldd3/src/scull/scull.mod.o
LD [M] /home/allen/share/ldd3/src/scull/scull.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'

 

参考文章:http://www.cnblogs.com/justinzhang/archive/2011/07/18/2109617.html

http://hi.baidu.com/%B3%C1%BC%C5%B5%C4%B9%C2%B3%C7/blog/item/570c3c52760aa62843a75b2a.html/cmtid/2fcadaf301a692cc7831aa4d