Chinaunix首页 | 论坛 | 博客
  • 博客访问: 722954
  • 博文数量: 66
  • 博客积分: 2418
  • 博客等级: 大尉
  • 技术积分: 1659
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-28 10:04
个人简介

keep moving

文章分类

全部博文(66)

文章存档

2015年(2)

2014年(6)

2013年(7)

2011年(7)

2010年(42)

2009年(2)

分类: 嵌入式

2010-04-26 20:17:51

在开发板上insmod模块时,没有问题;但在rmmod模块时,提示"No such file or directory"。lsmod时,该模块时存在的。
root@lingd-arm2410s:/tmp/lingd/gprs2.4# insmod gprs2.4.ko  
root@lingd-arm2410s:/tmp/lingd/gprs2.4# rmmod gprs2.4                    
rmmod: gprs2.4: No such file or directory  
问题出在rmmod,通过查看BusyBox-1.11.1源码中modutils/rmmod.c源文件,得知:
 * 对于2.6版本内核,rmmod对传递给它的模块文件名作了一些特殊处理(截取到第一个'.',并且将文件名中断的'-'换成'_'),再将处理后的模块名称传递给delete_module
 * 但对2.4版本内核,rmmod不对其模块文件名进行处理,而是直接将传递给它的模块文件名传递给delete_module
以上内容通过filename2modname函数实现

/* filename2modname:将模块文件名转换成模块名称 */
static inline void filename2modname(char *modname, const char *afterslash)
{
    unsigned int i;
    int kr_chk = 1;    /* 内核版本标志,1为2.6版本内核,0为2.4版本内核 */

    /* 若为2.4版本内核,将kr_chk置为0 */
    if (ENABLE_FEATURE_2_4_MODULES
            && get_linux_version_code() <= KERNEL_VERSION(2,6,0))
                kr_chk = 0;

    /* Convert to underscores, stop at first . */
    /* 循环处理模块文件名中各字符,直到遇到第一个'.' */
    for (i = 0; afterslash[i] && afterslash[i] != '.'; i++)
    {
        /* 若为2.6版本内核,将文件名中的'-'转换成'_' */
        if (kr_chk && (afterslash[i] == '-'))
            modname[i] = '_';
        else
            modname[i] = afterslash[i];
    }
    modname[i] = '\0';
}

因此,在执行rmmod gprs2.4rmmod gprs2.4.ko时,就变成执行rmmod gprs2。我并没有insmod过一个叫gprs2模块,当然就找到该文件啦!之所以反馈给我们的错误信息是"rmmod: gprs2.4: No such file or directory ",而不是"rmmod: gprs2: No such file or directory ",是因为rmmod打印错误信息时,用的是我们传给它的模块文件名(即gprs2.4),而不是经过处理的模块名称gprs2。

解决方法:

1、最简单的方法:重命名模块文件名,使其不包含'.'字符,除了后缀".ko"

2、比较好的方法(我们可能会在模块文件名里加上版本号,那就无法避免'.'的出现了):修改BusyBox-1.11.1源码中modutils/rmmod.c源文件filename2modname函数的实现:若模块文件名带后缀.ko,将后缀.ko截掉。修改后,filename2modname函数内容如下:

static inline void filename2modname(char *modname, const char *afterslash)
{
    unsigned int i;
    int kr_chk = 1;
    unsigned int len;    
//lingd


    if (ENABLE_FEATURE_2_4_MODULES
            && get_linux_version_code() <= KERNEL_VERSION(2,6,0))
                kr_chk = 0;

/********************* lingd ********************/

    /* 若模块文件名带.ko后缀,将后缀.ko截掉 */
    len = strlen(afterslash);
    if (strcmp(afterslash + len - 3, ".ko") == 0)
        len = len - 3;
    
    for (i=0; i<len; i++)
    {
    /* Convert to underscores, stop at first . */
//    for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) {

/********************* lingd ********************/
        if (kr_chk && (afterslash[i] == '-'))
            modname[i] = '_';
        else
            modname[i] = afterslash[i];
    }
    modname[i] = '\0';
}

其他原因引起的"rmmod: No such file or directory ",可参考以下两篇文章:

阅读(5357) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

kangear2013-02-15 21:49:52

原来如此,3Q。