Reorder and add module params example
This commit is contained in:
parent
2c8ab5e48f
commit
a30ba27a3f
11 changed files with 62 additions and 1 deletions
2
.envrc
2
.envrc
|
@ -1 +1 @@
|
|||
use flake
|
||||
use flake .#other
|
||||
|
|
53
02_module_params/test_module.c
Normal file
53
02_module_params/test_module.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
#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;
|
||||
|
||||
module_param(myshort, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
|
||||
MODULE_PARM_DESC(myshort, "A short integer");
|
||||
|
||||
module_param(myint, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
MODULE_PARM_DESC(myint, "An integer");
|
||||
|
||||
module_param(mylong, long, S_IRUSR);
|
||||
MODULE_PARM_DESC(mylong, "A long integer");
|
||||
|
||||
module_param(mystring, charp, 0000);
|
||||
MODULE_PARM_DESC(mystring, "A character string");
|
||||
|
||||
module_param_array(myintarray, int, &arr_argc, 0000);
|
||||
MODULE_PARM_DESC(myintarray, "An array of integers");
|
||||
|
||||
static int __init module_params_init(void) {
|
||||
int i;
|
||||
|
||||
pr_info("myshort: %hd\n", myshort);
|
||||
pr_info("myint: %d\n", myint);
|
||||
pr_info("mylong: %ld\n", mylong);
|
||||
pr_info("mystring: %s\n", mystring);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(myintarray); i++)
|
||||
pr_info("myintarray[%d] = %d\n", i, myintarray[i]);
|
||||
|
||||
pr_info("%d arguments for myintarray.\n", arr_argc);
|
||||
|
||||
pr_info("Module avec paramètre chargé.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit module_params_exit(void) {
|
||||
pr_info("Module avec paramètre déchargé.\n");
|
||||
}
|
||||
|
||||
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");
|
7
05_packet_filter/Makefile
Normal file
7
05_packet_filter/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
obj-m += test_module.o
|
||||
|
||||
all:
|
||||
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules
|
||||
|
||||
clean:
|
||||
make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) clean
|
|
@ -54,6 +54,7 @@ sudo rmmod [module_name].ko
|
|||
- https://www.kernel.org/doc/html/latest/
|
||||
- https://elixir.bootlin.com/linux/v6.13/source/
|
||||
- https://static.lwn.net/images/pdf/LDD3/ch01.pdf
|
||||
- https://sysprog21.github.io/lkmpg
|
||||
|
||||
## Notes
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue