原文地址:http://hi.baidu.com/andio/item/b8be9810282841433a176e86

rmmod chdir no such file or directory

说明:

1. 此文档基于 linux 2.6.32,TQ2440上测试通过,

2. arm-linux-gcc版本

Thread model: posix
gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203)

一. 问题描述及追踪分析

使用 rmmod时候发现如下错误

rmmod chdir no such file or directory

追踪该错误信息,发现busybox rmmod.c   位置  busybox-1.xxx/modutils/rmmod.c

函数框架如下

int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

int rmmod_main(int argc UNUSED_PARAM, char **argv)
{
//.......
    if (!*argv)
        bb_show_usage();

//......

while (*argv) {
        char modname[MODULE_NAME_LEN];
        const char *bname;

bname = bb_basename(*argv++);
        if (n)
            safe_strncpy(modname, bname, MODULE_NAME_LEN);
        else
            filename2modname(bname, modname);
        if (bb_delete_module(modname, flags))
            bb_error_msg_and_die("can't unload '%s': %s",
                         modname, moderror(errno));
    }

return EXIT_SUCCESS;
}

研究 这个函数,我们发现删除模块的 核心函数 是 bb_delete_module,追踪这个函数,在 /modutils/modutils.c中,我们得到如下函数

int FAST_FUNC bb_delete_module(const char *module, unsigned int flags)
{
    errno = 0;
    delete_module(module, flags);
    return errno;
}
这个表明rmmod实现是依靠 delete_module

继续跟踪delete_module,

#ifdef __UCLIBC__
extern int delete_module(const char *module, unsigned int flags);
#else
# include <sys/syscall.h>
# define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
#endif

这个 是什么意思呢?

如果定义了 __UCLIBC__  则使用uClibc中的  delete_module(const char *module, unsigned int flags)函数

否则,则用系统调用内核的 sys_delete_module函数 该函数原型如下

asmlinkage long sys_delete_module(const char __user *  name_user,  unsigned int  flags);

我们 再来看 safe_strncpy(modname, bname, MODULE_NAME_LEN); 函数和 filename2modname(bname, modname);函数

这俩个函数 的作用都是获得 模块名称 ,使用的核心实现方式是  strrchr(name, '/');

char *strchr(const char *s, int c);
The strrchr() function returns a pointer to the last occurrence of  the character c in the string s.

这个意思时说strrchr函数返回字符C在 字符串S中最后一次出现的位置。

假如我们使用如下指令

#rmmod  /lib/modules/2.6.32/adc.ko

经过函数处理后, modname 将变回 adc.ko

值得注意的是 bb_basename() 函数如下

const char* FAST_FUNC bb_basename(const char *name)
{
    const char *cp = strrchr(name, '/');
    if (cp)
        return cp + 1;
    return name;
} 该函数 已经进行了一次处理

另外, filename2modname 函数

char * FAST_FUNC filename2modname(const char *filename, char *modname)
{
    int i;
    char *from;
 if (filename == NULL)
        return NULL;
    if (modname == NULL)
        modname = xmalloc(MODULE_NAME_LEN);
    from = bb_get_last_path_component_nostrip(filename);
    for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '\0' &&from[i] != '.'; i++)
        modname[i] = (from[i] == '-') ? '_' : from[i];
    modname[i] = '\0';

return modname;
}

注意

from[i] != '.' ,这个意味着 adc.ko 会被解析成adc

from[i] == '-'? '_' : from[i]这个意味着 adc-xyz会被解析成adc_xyz

分析到这里,我们也就知道了rmmod的全过程,核心在于利用sys_delete_module函数卸载驱动模块

下面给出解决方法

二. 解决方法

 建立rmmod.c ,内容如下

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
int ret = -1;
int left_time =5;
int i=0;
if(!argv[1])
{
    printf("usage: rmmod modename\n");
    return -1;

}

char *modname = argv[1];

while(argv[1][i]!='\0')

{

//如下这个 是为了 rmmod adc.ko 与 rmmod adc效果一致

if(argv[1][i]=='.'){argv[1][i]='\0';break;}
i++;
};

while (left_time-- > 0) {
ret = delete_module(modname, O_NONBLOCK | O_EXCL);//系统调用sys_delete_module
if (ret < 0 && errno == EAGAIN)
sleep(1);
else
break;
}
if (ret != 0) printf("Error when rmmod module %s: %s\n",modname, strerror(errno));
return 0;

}

在PC中

#arm-linux-gcc rmmod.c -o rmmod

在板子中

#mv /sbin/rmmod /sbin/rmmod2

#mv rmmod /sbin/rmmod

OK6410 rmmod卸载模块失败:No such file or directory -- 转的更多相关文章

  1. rmmod: chdir(/lib/modules): No such file or directory

    内核版本:linux3.4.20 交叉编译器:arm-linux-gcc 4.3.3 busybox :  busybox 1.20 问题: 使用rmmod会出现 rmmod : chdir(/lib ...

  2. [转载]rmmod: can't change directory to '/lib/modules': No such file or directory

    转载网址:http://blog.csdn.net/chengwen816/article/details/8781096 在我新移植的kernel(3.4.2)和yaffs2文件中,加载新编译的内核 ...

  3. rmmod: can't change directory to '/lib/modules': No such file or directory

    [root@iTOP-4412]# mount /dev/sda1 /mnt/udisk/ [root@iTOP-4412]# insmod /mnt/udisk/linux/hello.ko  [ ...

  4. Angular问题02 创建模块失败、 angular-cli名称问题、升级angular-cli

    1 创建模块失败 1.1 问题描述 利用 ng g m 模块名 创建新模块时出错 1.2 错误信息 1.3 问题原因 angular-cli 版本出现问题 1.4 解决办法 卸载掉之前使用的 angu ...

  5. Sql Server 2008 卸载重新安装失败的解决办法!(多次偿试,方法均有效!)

    Sql Server 2008 卸载重新安装失败的解决办法!(多次偿试,方法均有效!) 1.控制面板中卸载所有带sql server的程序. 2.在C盘C:\Program Files中sqlserv ...

  6. ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

    命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_2 ...

  7. 5.python之pip安装模块失败

    本文是篇水文,主要是在学习python过程中总是遇到使用pip安装一些模块失败,记录一下安装模块解决办法 第一种方法: 首先安装wheel模块: pip install wheel 如果wheel都安 ...

  8. busybox rmmod error — rmmod: chdir(2.6.25): No such file or directory

    busybox rmmod error rmmod: chdir(2.6.25): No such file or directory 1. install your modules in dir / ...

  9. cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,

    1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://reg ...

随机推荐

  1. teamcity执行jmeter脚本使用Executable with parameters方式不能正确运行解决思路

    如下图是选择command Line:Executable with parameters设置启动jmeter.bat  命令如下 command Executable: D:\apache-jmet ...

  2. 性能分析_linux服务器CPU_Load Average

    CPU度量Load Average 1.  概念介绍 1.1  Linux系统进程状态 在linux中,process有以下状态: runnable (就绪状态):blocked waiting fo ...

  3. mysql二进制日志的开启和使用

    二进制日志(BINLOG)记录了所有的ddl和dml语句,但不包括数据查询语句.语句以“事件”的形式保存,描述数据更改过程. 环境:win8   mysql5.6.23 1.mysql开启二进制日志 ...

  4. Jackson 使用

    // 序列化出来的 JSON, 不包含值为 NULL 类型字段. mapper.setSerializationInclusion(Include.NON_NULL); Jackson provide ...

  5. KMP之Z-function (扩展kmp)

    http://codeforces.com/blog/entry/3107 // s[0, ..., n-1], z[0] = 0// z[i] is the length of the longes ...

  6. Linux相关——记录gdb基本操作(持续更新)

    -----------2018.9.26更新标记----------- gdb的确是个很强大的东西啊,这里记录一下gdb的基本操作吧 后续可能会补充,但暂时感觉够用了就不写多了. 首先是ubuntu终 ...

  7. hdu6057 Kanade's convolution 【FWT】

    题目链接 hdu6057 题意 给出序列\(A[0...2^{m} - 1]\)和\(B[0...2^{m} - 1]\),求所有 \[C[k] = \sum\limits_{i \; and \; ...

  8. Xpack集成LDAP

    支持两种配置方式: The ldap realm supports two modes of operation, a user search mode and a mode with specifi ...

  9. Android Studio 使用VCS版本控制

    1.SVN的配置: 如果项目使用的是SVN配置,那么除了乌龟SVN GUI工具外,你还得下载Subversion, 因为AS要用其中的xx.exe命令行执行程序, 下载地址:https://www.v ...

  10. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...