-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldd.c
59 lines (46 loc) · 1.5 KB
/
ldd.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
54
55
56
57
58
59
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
MODULE_LICENCE("GPL");
MODULE_AUTHOR("PRAGNESH");
MODULE_DESCRIPTION("Basic read loadable kernel module");
static struct proc_dir_entry *custom_proc_node;
static ssize_t read(struct file* file_pointer,
char* user_space_buffer,
size_t count,
loff_t* offset)
{
char msg[] = "Ack!\n";
size_t len = strlen(msg);
int result;
printk("basic read\n");
if(*offset == len){
return 0;
}
result = copy_to_user(user_space_buffer, msg, len);
*offset += len;
return len;
}
struct proc_ops driver_proc_ops={
.proc_read=read
};
static int custom_init(void){
printk("module_init: entry\n");
custom_proc_node = proc_create("pdriver",
0,
NULL,
&driver_proc_ops);
if (custom_proc_node == NULL){
printk("module_init: error");
return -1;
}
printk("module_init: exit\n");
return 0;
}
static void custom_exit(void){
printk("module_exit: entry\n");
proc_remove(custom_proc_node);
printk("module_exit: exit\n");
}
module_init(custom_init);
module_exit(custom_exit);