Notes [ Linux Device Drivers, 3rd Edition ( Ch02 ) - Module Parameters ]
来源:互联网 发布:淘宝平面模特工资 编辑:程序博客网 时间:2024/05/01 22:58
今天看了一下模块参数,试着模仿书中的例子写了hellop.c的程序代码:
dolphin@dolphin-laptop:~/Documents/LDD/hellop$ cat hellop.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
MODULE_LICENSE( "Dual BSD/GPL" );
static char *whom = "dolphin";
static int howmany = 3;
module_param( howmany, int, S_IRUGO );
module_param( whom, charp, S_IRUGO );
static int __init hello_init( void ) {
int i;
for ( i = 0; i < howmany; i++ )
printk( KERN_ALERT "Hello, %s!/n", whom );
return 0;
}
static void __exit hello_exit( void ) {
printk( KERN_ALERT "Goodbye, %s!/n", whom );
}
module_init( hello_init );
module_exit( hello_exit );
其中S_IRUGO表示权限,charp是类似于字符串的类型。
所有的模块参数应该被赋予一个默认值,如果在insmod的时候不带任何参数,则按默认的值输出,如果要传参数,则使用如下方式:
sudo insmod hellop.ko howmany=2 whom="angel"
输出的结果也相应的发生改变,当然,也可以只传一个参数,另一个则按照默认值设置。
- Notes [ Linux Device Drivers, 3rd Edition ( Ch02 ) - Module Parameters ]
- Notes [ Linux Device Drivers, 3rd Edition ( Ch02 ) - The Hello World Module ]
- Linux Device Drivers 3rd Edition Preface
- Linux Device Drivers (3rd) - Study Notes
- Linux Device Drivers 3rd Edition Char Drivers
- Linux Device Drivers 3rd Edition PCI Drivers
- Linux Device Drivers 3rd Edition USB Drivers
- Linux Device Drivers 3rd Edition Block Drivers
- Linux Device Drivers 3rd Edition Network Drivers
- Linux Device Drivers 3rd Edition TTY Drivers
- Linux Device Drivers 3rd Edition The Linux Device Model
- Linux Device Drivers(3rd Edition)--reading digest
- Linux Device Drivers 3rd Edition About the Authors
- Linux Device Drivers 3rd Edition An Introduction to
- Linux Device Drivers 3rd Edition Building and Running
- Linux Device Drivers 3rd Edition Debugging Techniques
- Linux Device Drivers 3rd Edition Concurrency and Race Conditions
- Linux Device Drivers 3rd Edition Advanced Char Driver Operations
- 怀念的三年
- 技术员要
- Struts2配置文件之default.properties
- 通过FetionVM实现无.net框架环境下运行.NET程序
- CSDN第一篇文章!
- Notes [ Linux Device Drivers, 3rd Edition ( Ch02 ) - Module Parameters ]
- Overlay简介
- JAVA使用XML作为持久存储介质
- 敏捷开发中最基本的分支管理模式解析
- 传统工业提升到智能工业的关键------物联网在工业领域中的应用
- DOM4J 例子
- ArcSDE常用命令
- Java操作XML
- constraint name uniqueness