LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1518|回复: 0

请教request_module()函数用法

[复制链接]
发表于 2008-4-29 22:35:32 | 显示全部楼层 |阅读模式
各位大侠好:


    我在书上看到可以使用request_module(module_name)函数加载内核模块,所以我写了2个模块,分别是hello2.ko与hello3.ko。

    在hello3.ko中使用到了hello2.ko的导出符号data2,并且在hello2.ko中的初始化函数中用到request_module函数去首先加载hello2.ko模块。

    但是当我用insmod ./hello3.ko加载hello3.ko模块时,却出现:
“insmod: error inserting './hello3.ko': -1 Unknown symbol in module”的错误,似乎request_module函数未能成功加载hello2.ko模块,导致找不到data2变量。

问题:
    我不明白为什么“request_module函数未能成功加载hello2.ko模块”?是不是我对requeset_module的使用有问题,那正确的使用方式是什么呢?


简略的代码如下:

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//hello2.c
int data2=10;
EXPORT_SYMBOL(data2);


module_init(hello2_init);
module_exit(hello2_exit);

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//hello3.c

extern int data2;

static int __init hello3_init(void)
{
    request_module("hello2.ko");
    printk(KERN_ALERT"Hello,World %d\n",data2);
    return 0;
}
........
module_init(hello3_init);


期待各位大侠的答案!
谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表