linuxドライバ開発--カーネルモジュールパラメータ
1412 ワード
カーネルモジュールのパラメータ、検証の例:
/**
*Copyright (c) 2013.TianYuan
*All rights reserved.
*
* : Modparma.c
* :
*
* :1.0
* :wuyq
*
* :xxx
* :xxx
* :2013-11-18
*/
#include <linux/init.h>
#include <linux/module.h>
/* : */
/* , :\
insmod modparam.ko mpshort=100 mpint=200 mpstring="nihao" mparray=300,400*/
/*ls /sys/module/modparam/parameters*/
/*cat mparray; echo 55 > mpshort;cat mpshort*/
MODULE_LICENSE("GPL");
/* */
static short mpshort = 1;
static int mpint = 10;
static char *mpstring = "hello";
static int mparray[2] = {100, 200};
/* */
module_param(mpshort ,short, S_IRWXU);
module_param(mpint, int , S_IRUSR);
module_param(mpstring, charp, 00400);/*char* */
module_param_array(mparray, int, NULL, 00400);
static int __init modparam_init(void)
{
printk("mpshort = %d
", mpshort);
printk("mpint = %d
", mpint);
printk("mpstring = %s
", mpstring);
printk("mparray = %d, %d
", mparray[0], mparray[1]);
return 0;
}
static void __exit modparam_exit(void)
{
printk("mpshort = %d
", mpshort);
printk("mpint = %d
", mpint);
printk("mpstring = %s
", mpstring);
printk("mparray = %d, %d
", mparray[0], mparray[1]);
}
module_init(modparam_init);
module_exit(modparam_exit);