-
Notifications
You must be signed in to change notification settings - Fork 5
/
lkm_proc.c
79 lines (65 loc) · 2.13 KB
/
lkm_proc.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* LKM Sandbox::Proc
* <https://github.com/tpiekarski/lkm-sandbox>
* ---
* Copyright 2020 Thomas Piekarski <[email protected]>
*
* This file is part of LKM Sandbox.
*
* LKM Sandbox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* LKM Sandbox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LKM Sandbox. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Thomas Piekarski");
MODULE_DESCRIPTION("Module for accesing the /proc filesystem");
MODULE_VERSION("0.1");
static int lkm_proc_show(struct seq_file *seq, void *v);
#define LKM_PROC_FILE_NAME "lkm_proc"
#define LKM_PROC_MESSAGE "Hello, /proc!"
#define LKM_PROC_PARENT NULL // root of /proc
#define LKM_PROC_PERMISSION 0444
static int __init lkm_proc_init(void)
{
struct proc_dir_entry *lkm_proc_entry = NULL;
printk(KERN_INFO
"lkm_proc: Initializing module for accessing /proc/%s.\n",
LKM_PROC_FILE_NAME);
lkm_proc_entry =
proc_create_single(LKM_PROC_FILE_NAME, LKM_PROC_PERMISSION,
LKM_PROC_PARENT, lkm_proc_show);
if (lkm_proc_entry == NULL) {
printk(KERN_ALERT
"lkm_proc: Failed to create entry '%s' in /proc.\n",
LKM_PROC_FILE_NAME);
}
return 0;
}
static void __exit lkm_proc_exit(void)
{
printk(KERN_INFO "lkm_proc: Removing /proc/%s.\n", LKM_PROC_FILE_NAME);
remove_proc_entry(LKM_PROC_FILE_NAME, LKM_PROC_PARENT);
}
static int lkm_proc_show(struct seq_file *seq, void *v)
{
seq_puts(seq, LKM_PROC_MESSAGE);
seq_putc(seq, '\n');
return 0;
}
module_init(lkm_proc_init);
module_exit(lkm_proc_exit);