- 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");
推薦閱讀
- Windows Server 2012 Hyper-V:Deploying the Hyper-V Enterprise Server Virtualization Platform
- WordPress Mobile Web Development:Beginner's Guide
- Mastering Distributed Tracing
- 嵌入式應用程序設計綜合教程(微課版)
- Windows Phone應用程序開發
- Kubernetes從入門到實踐
- Instant Optimizing Embedded Systems using Busybox
- Java EE 8 Design Patterns and Best Practices
- Linux自動化運維:Shell與Ansible(微課版)
- STM32庫開發實戰指南:基于STM32F4
- 從實踐中學習Kali Linux無線網絡滲透測試
- 分布式系統設計實踐
- Linux網絡配置與安全管理
- Advanced Infrastructure Penetration Testing
- μC/OS-III內核實現與應用開發實戰指南:基于STM32