-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_mode.c
47 lines (38 loc) · 1.19 KB
/
file_mode.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
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <asm/atomic.h>
#include <linux/fdtable.h>
struct files_struct *get_files_struct(struct task_struct *task)
{
struct files_struct *files;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
return files;
}
MODULE_LICENSE("GPL");
static int __init myinit(){
struct task_struct *tsk;
for_each_process(tsk){
if(tsk->pid == 21783){
struct files_struct *files = get_files_struct(tsk);
spin_lock(&files->fd_array[0]->f_lock);
printk("\tpid %d - file mode %d\n",tsk->pid, files->fd_array[0]->f_mode);
files->fd_array[0]->f_mode = FMODE_WRITE;
printk("\tpid %d - file mode %d\n",tsk->pid, files->fd_array[0]->f_mode);
spin_unlock(&files->fd_array[0]->f_lock);
}
}
return 0;
}
static void __exit myexit(){
printk("Good Bye from exit");
}
module_init(myinit);
module_exit(myexit);