简单驱动——helloworld驱动
驱动分为四个部分
头文件
驱动模块的入口和出口
声明信息
功能实现
第一步,包含头文件
#include
#include
第二部,驱动模块的入口和出口
module_init(hello_init);//模块入口
module_exit(hello_exit);//模块出口
第三步,声明模块拥有开源许可证
MODULE_LICENSE(“GPL”);
第四部,功能实现
static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}
static int hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}
内核模块加载的时候打印hello world,内核模块卸载的时候打印bye bye
注意:内核打印函数不能用printf,因为内核没有办法使用C语言库
整体代码如下:
#include
#include
#include
static int hello_init(void)
{
printk(“hello world\n”);
return 0;
}
static void hello_exit(void)
{
printk(“bye bye\n”);
return 0;
}
module_init(hello_init);//模块入口
module_exit(hello_exit);//模块出口
MODULE_LICENSE(“GPL”);
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧