-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.c
More file actions
48 lines (39 loc) · 1.12 KB
/
proc.c
File metadata and controls
48 lines (39 loc) · 1.12 KB
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
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/proc_fs.h>
#include<asm/uaccess.h>
#define procfs_name "helloword"
struct proc_dir_entry *Our_Proc_File;
static ssize_t procfile_read(struct file *file, char *buffer, size_t length, loff_t *offset) {
static int finished = 0;
if (finished) {
printk(KERN_ALERT "Fully read");
finished = 0;
return 0;
}
finished = 1;
if (copy_to_user(buffer, "Hello", 6)) {
printk(KERN_ALERT "Nothing saved in the file");
return -EFAULT;
}
return 6;
}
static struct file_operations hello_fops = {
.owner = THIS_MODULE,
.read = procfile_read,
};
int init_module()
{
Our_Proc_File=proc_create(procfs_name, 0644, NULL,&hello_fops);
if(Our_Proc_File == NULL) {
remove_proc_entry(procfs_name,NULL);
printk(KERN_ALERT "Error : could not intialize /proc/%s\n",procfs_name);
return -ENOMEM;
}
printk(KERN_INFO "/proc/%s created\n",procfs_name);
return 0;
}
void cleanup_module () {
remove_proc_entry(procfs_name,NULL);
printk(KERN_INFO "/proc/%s removed \n",procfs_name);
}