Skip to content

Commit f710beb

Browse files
committed
refactored the naming
1 parent 3c48c54 commit f710beb

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

src/elf_det.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int user_pid; //the desired pid that we get from user
2222
static int numberOpens = 0; //number of opens(writes) to the pid file
2323

2424
//skip these instances (will be described bellow)
25-
static struct proc_dir_entry *topsDir, *topsFile, *topsWrite;
25+
static struct proc_dir_entry *elfdet_dir, *elfdet_det_entry, *elfdet_pid_entry;
2626

2727
static int procfile_open(struct inode *inode, struct file *file);
2828
static ssize_t procfile_read(struct file*, char*, size_t, loff_t*);
@@ -32,7 +32,7 @@ static ssize_t procfile_write(struct file*, const char*, size_t, loff_t*);
3232
//det proc file_operations starts
3333

3434
//this function is the base function to gather information from kernel
35-
static int tops_show(struct seq_file *m, void *v) {
35+
static int elfdet_show(struct seq_file *m, void *v) {
3636
struct task_struct *task;
3737
unsigned long bss_start = 0, bss_end = 0;
3838
unsigned long elf_header = 0;
@@ -87,13 +87,13 @@ static int tops_show(struct seq_file *m, void *v) {
8787
}
8888

8989
//runs when openning file
90-
static int tops_open(struct inode *inode, struct file *file) {
91-
return single_open(file, tops_show, NULL); //calling tops_show
90+
static int elfdet_open(struct inode *inode, struct file *file) {
91+
return single_open(file, elfdet_show, NULL); //calling elfdet_show
9292
}
9393

9494
//file operations of det proc (using proc_ops for kernel 5.6+)
95-
static const struct proc_ops tops_pops = {
96-
.proc_open = tops_open,
95+
static const struct proc_ops elfdet_det_ops = {
96+
.proc_open = elfdet_open,
9797
.proc_read = seq_read,
9898
.proc_lseek = seq_lseek,
9999
.proc_release = single_release,
@@ -152,19 +152,19 @@ static const struct proc_ops write_pops = {
152152
};
153153

154154

155-
static int tops_init(void) {
156-
topsDir = proc_mkdir("elf_det", NULL); //creating the directory: elf_det in proc
155+
static int elfdet_init(void) {
156+
elfdet_dir = proc_mkdir("elf_det", NULL); //creating the directory: elf_det in proc
157157

158-
if (!topsDir) {
158+
if (!elfdet_dir) {
159159
return -ENOMEM;
160160
}
161161
//0777 means full premmisions for the file
162-
topsFile = proc_create("det", 0777, topsDir, &tops_pops); //create proc file det with tops_pops proc operations
163-
printk("det initiated; /proc/elf_det/det created\n");
164-
topsWrite = proc_create("pid",0777, topsDir, &write_pops);////create proc file pid with write_pops proc operations
165-
printk("pid initiated; /proc/elf_det/pid created\n");
162+
elfdet_det_entry = proc_create("det", 0777, elfdet_dir, &elfdet_det_ops); //create proc file det with elfdet_det_ops
163+
printk("det initiated; /proc/elf_det/det created\n");
164+
elfdet_pid_entry = proc_create("pid", 0777, elfdet_dir, &write_pops); //create proc file pid with write_pops
165+
printk("pid initiated; /proc/elf_det/pid created\n");
166166

167-
if (!topsFile) {
167+
if (!elfdet_det_entry) {
168168
return -ENOMEM;
169169
}
170170

@@ -173,14 +173,14 @@ static int tops_init(void) {
173173
}
174174

175175
//the remove operations done by module(cleaning up)
176-
static void tops_exit(void) {
177-
proc_remove(topsFile);
178-
printk("tops exited; /proc/elf_det/det deleted\n");
179-
proc_remove(topsWrite);
180-
printk("tops exited; /proc/elf_det/pid deleted\n");
181-
proc_remove(topsDir);
176+
static void elfdet_exit(void) {
177+
proc_remove(elfdet_det_entry);
178+
printk("elf_det exited; /proc/elf_det/det deleted\n");
179+
proc_remove(elfdet_pid_entry);
180+
printk("elf_det exited; /proc/elf_det/pid deleted\n");
181+
proc_remove(elfdet_dir);
182182
}
183183

184184
//macros for init and exit
185-
module_init(tops_init);
186-
module_exit(tops_exit);
185+
module_init(elfdet_init);
186+
module_exit(elfdet_exit);

0 commit comments

Comments
 (0)