kernel_module_learn/02_module_params/test_module.c

56 lines
1.4 KiB
C
Raw Normal View History

2025-02-18 17:06:38 +01:00
#include <linux/module.h>
#include <linux/kernel.h>
static short int myshort = 1;
static int myint = 420;
static long int mylong = 9999;
static char *mystring = "blah";
static int myintarray[2] = { 420, 420 };
static int arr_argc = 0;
2025-02-25 13:32:53 +01:00
module_param(myshort, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(myshort, "A short integer");
2025-02-18 17:06:38 +01:00
2025-02-25 13:32:53 +01:00
module_param(myint, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(myint, "An integer");
2025-02-18 17:06:38 +01:00
2025-02-25 13:32:53 +01:00
module_param(mylong, long, S_IRUSR);
MODULE_PARM_DESC(mylong, "A long integer");
2025-02-18 17:06:38 +01:00
2025-02-25 13:32:53 +01:00
module_param(mystring, charp, 0000);
2025-02-18 17:06:38 +01:00
MODULE_PARM_DESC(mystring, "A character string");
2025-02-25 13:32:53 +01:00
module_param_array(myintarray, int, &arr_argc, 0000);
MODULE_PARM_DESC(myintarray, "An array of integers");
2025-02-18 17:06:38 +01:00
2025-02-25 13:32:53 +01:00
static int __init module_params_init(void)
{
2025-02-23 13:14:54 +01:00
int i;
2025-02-18 17:06:38 +01:00
2025-02-23 13:14:54 +01:00
pr_info("myshort: %hd\n", myshort);
pr_info("myint: %d\n", myint);
pr_info("mylong: %ld\n", mylong);
pr_info("mystring: %s\n", mystring);
2025-02-18 17:06:38 +01:00
2025-02-23 13:14:54 +01:00
for (i = 0; i < ARRAY_SIZE(myintarray); i++)
pr_info("myintarray[%d] = %d\n", i, myintarray[i]);
2025-02-18 17:06:38 +01:00
2025-02-23 13:14:54 +01:00
pr_info("%d arguments for myintarray.\n", arr_argc);
2025-02-18 17:06:38 +01:00
2025-02-23 13:14:54 +01:00
pr_info("Module avec paramètre chargé.\n");
return 0;
2025-02-18 17:06:38 +01:00
}
2025-02-25 13:32:53 +01:00
static void __exit module_params_exit(void)
{
2025-02-23 13:14:54 +01:00
pr_info("Module avec paramètre déchargé.\n");
2025-02-18 17:06:38 +01:00
}
module_init(module_params_init);
module_exit(module_params_exit);
MODULE_LICENSE("MIT License");
MODULE_AUTHOR("Florian RICHER");
MODULE_DESCRIPTION("Un module noyau avec paramètre déchargé.");
MODULE_VERSION("1.0");