您的位置:首页 > 其它

带参数的可加载模块

2014-04-18 21:34 411 查看
宏MODULE_PARAM(var,type,right) 用于向模块传递命令行参数。参数类型可以是整数、长整型、字符串等类型。

例1.2 带参数的内核模块实例

代码见光盘\src\1drivermodel\1-2module。本实例演示了如何向模块传递整型、长整型、字符串型等参数。核心代码如下所示:

static int itype=0;
module_param(itype, int, 0);
static int btype = 0;
module_param(btype, bool, 0);
static unsigned char ctype=0;
module_param(ctype, byte, 0);
static char *stype=0;
module_param(stype, charp, 0);
//模块初始化
static int __init demo_module_init(void)
{
printk("simple module init\n");
printk("itype=%d\n",itype);
printk("btype=%d\n",btype);
printk("ctype=%d\n",ctype);
printk("stype='%s'\n",stype);
return 0;
}
//模块卸载
static void __exit demo_module_exit(void)
{
printk("simple module exit\n");
}
module_init(demo_module_init);
module_exit(demo_module_exit);


接下来编写一个makefile文件,同例1.1。执行make后生成smodule.ko,运行结果如下:
[root@urbetter /home]# insmod  smodule.ko  itype=2 btype=1 ctype=0xAC stype='a'
simple module init
itype=2
btype=1
ctype=172
stype='a'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: