官术网_书友最值得收藏!

How to do it...

Let's see how to do it by following these steps:

  1. First, let's define our module parameters, as follows:
static int var = 0x3f;
module_param(var, int, S_IRUSR | S_IWUSR);
MODULE_PARM_DESC(var, "an integer value");

static char *str = "default string";
module_param(str, charp, S_IRUSR | S_IWUSR);
MODULE_PARM_DESC(str, "a string value");

#define ARR_SIZE 8
static int arr[ARR_SIZE];
static int arr_count;
module_param_array(arr, int, &arr_count, S_IRUSR | S_IWUSR);
MODULE_PARM_DESC(arr, "an array of " __stringify(ARR_SIZE) " values");
  1. Then, we can use the following init and exit functions:
static int __init module_par_init(void)
{
int i;

pr_info("loaded\n");
pr_info("var = 0x%02x\n", var);
pr_info("str = \"%s\"\n", str);
pr_info("arr = ");
for (i = 0; i < ARR_SIZE; i++)
pr_cont("%d ", arr[i]);
pr_cont("\n");

return 0;
}

static void __exit module_par_exit(void)
{
pr_info("unloaded\n");
}

module_init(module_par_init);
module_exit(module_par_exit);
  1. Finally, at the end, we can add module description macros as usual:
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Rodolfo Giometti");
MODULE_DESCRIPTION("Module with parameters");
MODULE_VERSION("0.1");
主站蜘蛛池模板: 汝南县| 清苑县| 西乌珠穆沁旗| 台湾省| 仙桃市| 承德县| 合山市| 逊克县| 五大连池市| 尚义县| 图们市| 达日县| 通河县| 双城市| 池州市| 都匀市| 乐都县| 东乌珠穆沁旗| 平远县| 马尔康县| 托克逊县| 溧阳市| 日照市| 西乌珠穆沁旗| 天台县| 东平县| 文成县| 安远县| 建瓯市| 桦甸市| 新巴尔虎右旗| 调兵山市| 乌恰县| 聂拉木县| 自治县| 江陵县| 沛县| 绿春县| 丹巴县| 永新县| 六枝特区|