- Linux Device Driver Development Cookbook
- Rodolfo Giometti
- 146字
- 2021-06-24 13:54:15
How to do it...
Let's see how to do it by following these steps:
- 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");
- 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);
- 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");
推薦閱讀
- Linux設備驅動開發詳解(第2版)
- Linux運維實戰:CentOS7.6操作系統從入門到精通
- 網絡操作系統:Windows Server 2003管理與應用
- SOA實踐者說
- Linux Shell編程從入門到精通(第2版)
- macOS效率手冊
- Linux系統安全基礎:二進制代碼安全性分析基礎與實踐
- Linux使用和管理指南:從云原生到可觀測性
- Ceph分布式存儲實戰
- RHCSARHCE 紅帽Linux認證學習指南(第7版)EX200 & EX300
- 精解Windows 10
- Building Telephony Systems With Asterisk
- Linux 從入門到項目實踐(超值版)
- Azure Resource Manager Templates Quick Start Guide
- Mastering Sass