diff --git a/lkmpg/Makefile b/lkmpg/Makefile new file mode 100644 index 0000000..2020e2c --- /dev/null +++ b/lkmpg/Makefile @@ -0,0 +1,7 @@ +obj-m += hello_proc.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/lkmpg/hello_proc.c b/lkmpg/hello_proc.c new file mode 100644 index 0000000..ff75eec --- /dev/null +++ b/lkmpg/hello_proc.c @@ -0,0 +1,40 @@ +/** + * Original site + * + * http://pointer-overloading.blogspot.com/2013/09/linux-creating-entry-in-proc-file.html + * + */ + +#include +#include +#include + +static int hello_proc_show(struct seq_file *m, void *v) { + seq_printf(m, "Hello proc!\n"); + return 0; +} + +static int hello_proc_open(struct inode *inode, struct file *file) { + return single_open(file, hello_proc_show, NULL); +} + +static const struct file_operations hello_proc_fops = { + .owner = THIS_MODULE, + .open = hello_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init hello_proc_init(void) { + proc_create("hello_proc", 0, NULL, &hello_proc_fops); + return 0; +} + +static void __exit hello_proc_exit(void) { + remove_proc_entry("hello_proc", NULL); +} + +MODULE_LICENSE("GPL"); +module_init(hello_proc_init); +module_exit(hello_proc_exit);