-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcb_params.c
53 lines (42 loc) · 1.31 KB
/
cb_params.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* cb_params.c - Register the callback whenever the argument (parameter) got changed.
*
* $insmod params.ko myint=100
* $echo 200 > /sys/module/params/parameters/myint
* $dmesg
*/
#include <linux/module.h>
//#include <linux/moduleparam.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sohaib <[email protected]>");
static int myint = 420;
/*----------------------Module_param_cb()--------------------------------*/
int notify_param(const char *val, const struct kernel_param *kp)
{
int res = param_set_int(val, kp); // Use helper for write variable
if(res==0) {
printk(KERN_INFO "Call back function called...\n");
printk(KERN_INFO "New value of myint = %d\n", myint);
return 0;
}
return 0;
}
const struct kernel_param_ops my_param_ops =
{
.set = ¬ify_param, // Use our setter ...
.get = ¶m_get_int, // .. and standard getter
};
module_param_cb(myint, &my_param_ops, &myint, S_IRUGO|S_IWUSR );
/*-------------------------------------------------------------------------*/
static int hello_init(void)
{
pr_cont("params.ko: module loaded!");
printk(KERN_INFO "myint is an integer: %d\n", myint);
return 0;
}
static void hello_exit(void)
{
pr_err("Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);