<模块申明>
MODULE_LICENSE ():
声明该模块遵守的许可证协议,如“GPL”“GPL V2”
MODULE_AUTHOR(“姓名”)
MODULE_DESCREPTION(“功能描述”)
MODULE_VERSION(“版本号”)
<使用方式>
#include<linux/init.h>
#include<linux/modules.h>
MODULE_LICENSE(“GPL”) ;
static int hello_init(void)
{
pintk(KERN_WARNING“hello,word ”);
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO“goodby,word ”);
}
module_init(hello_int);
module_exit(hello_exit);
<内核模块参数>
通过宏:module_param() 指定保存模块参数的变量,模块参数用在加载模块是传递参数给模块。
module_param(name,type,perm)
参数说明:
name:变量名称
type:变量类型,如bool ,int ,char
perm:访问权限,S_IRUGO:读权限 S_IWUSR:写权限
例:
#include<linux/init.h>
#include<linux/modules.h>
MODULE_LICENSE(“GPL”) ;
int a = 3;
module_param(a , int , S_IRUGO|S_IWUSR);
static int hello_init(void)
{
pintk(KERN_WARNING“hello,word ”);
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO“goodby,word ”);
}
module_init(hello_int);
module_exit(hello_exit);
分析:
这样就这一在加载内核模块时使用传递参数,并且与int a = 3;没有任何关系
#include<linux/init.h>
#include<linux/modules.h>
MODULE_LICENSE(“GPL”) ;
int a = 3;
char *p;
module_param(a , int , S_IRUGO|S_IWUSR);
module_param(p,char *p,S_IRUGO}S_IWUSR);
static int hello_init(void)
{
pintk(KERN_WARNING“hello,word ”);
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO“goodby,word ”);
}
module_init(hello_int);
module_exit(hello_exit);
<符号输出>
一个内核模块部分功能活函数想要提供给另外的模块使用,首先需要将该函数声明为extern 类型,并使用宏EXPORT_SYMBOL(函数名),指明可以别外部使用
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">