-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrammodule.c
executable file
·76 lines (65 loc) · 1.66 KB
/
rammodule.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
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/sysinfo.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/timekeeping.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jose Eduardo Moran");
MODULE_DESCRIPTION("Modulo que muestra propiedades de ram");
struct sysinfo memstruct;
long total;
long freer;
long used;
long per;
static int procShow(struct seq_file *m, void *v)
{
si_meminfo(&memstruct);
total = memstruct.totalram * 4;
freer = memstruct.freeram * 4;
used = total - freer;
per = ((used * 100) / total);
seq_printf(m, "{\"Total\":\"%lu\", \"Libre\":\"%lu\", \"Usada\":\"%lu\", \"Porcentaje\":\"%lu\"}", total, freer, used, per);
return 0;
}
static ssize_t procWrite(struct file *file, const char __user *buffer, size_t count, loff_t *f_pos)
{
return 0;
}
static int procOpen(struct inode *inode, struct file *file)
{
return single_open(file, procShow, NULL);
}
static struct file_operations my_fops = {
.owner = THIS_MODULE,
.open = procOpen,
.read = seq_read,
.write = procWrite};
static int __init test_init(void)
{
struct proc_dir_entry *entry;
entry = proc_create("rammodule", 0777, NULL, &my_fops);
if (!entry)
{
return -1;
}
else
{
printk(KERN_INFO "@rammodule corriendo\n");
}
return 0;
}
static void __exit test_exit(void)
{
remove_proc_entry("rammodule", NULL);
printk(KERN_INFO "@rammodule finalizado\n");
}
module_init(test_init);
module_exit(test_exit);