Session Module
/home/osboxes/Documenti/AOSV/aosv1819-federicoalfano/session_module.h
Go to the documentation of this file.
1 
8 #ifndef SESSION_HEADER
9 #define SESSION_HEADER
10 
11 #include <linux/module.h>
12 #include <linux/fs.h>
13 #include <linux/fs_struct.h>
14 #include <linux/fdtable.h>
15 #include <linux/cdev.h>
16 #include <linux/slab.h>
17 #include <linux/err.h>
18 #include <linux/uaccess.h>
19 #include <linux/kobject.h>
20 #include <linux/sysfs.h>
21 #include <linux/rbtree.h>
22 #include <linux/list.h>
23 #include <linux/mutex.h>
24 #include <linux/dcache.h>
25 #include <linux/sched/signal.h>
26 #include <linux/file.h>
27 #include <linux/namei.h>
28 #include <linux/mount.h>
29 #include <linux/uaccess.h>
30 
31 #define DEVICE_NAME "session-module"
32 
33 #define SESSION_INSTANCES 1
34 
35 #define SESSION_MAJOR_NUMBER 0
36 #define SESSION_BASE_MINOR 0
38 #define SESSION_CLASS "session-class"
39 
40 #define SESSION_MAGIC 'S'
41 #define SESSION_OPEN_SEQ_NO 0X1
42 #define SESSION_CLOSE_SEQ_NO 0X2
43 
44 #define MAX_FILENAME_SIZE 128
45 #define MAX_PATH_SIZE 256
46 #define MAX_FILE_NUM 256
47 #define FILE_SESSIONS_SIZE (MAX_PATH_SIZE*MAX_FILE_NUM)
48 #define N_SESS_DIGITS 8
49 #define N_PROC_DIGITS 6
51 #define PROC_NAME_LENGTH 8
52 
53 
54 #define SESSION_OPEN _IOW(SESSION_MAGIC, SESSION_OPEN_SEQ_NO, unsigned int)
55 #define SESSION_CLOSE _IOW(SESSION_MAGIC, SESSION_CLOSE_SEQ_NO, unsigned int)
56 
57 
63 struct session_cdev {
64  struct cdev cdev;
65  struct kobject *kobj;
66 
67  };
68 
75 {
76  char key[MAX_PATH_SIZE];
77  struct rb_node node;
78  struct rw_semaphore *rw_sem;
79  atomic_t counter;
81 };
82 
89 {
90  int key;
91  struct rb_node node;
92  atomic_t session_counter;
93 };
100 {
101  struct rw_semaphore *rw_sem;
102  struct file *session_filp;
103  char *abs_path;
105 };
106 
107 
108 int module_open(struct inode *, struct file *);
109 int module_release(struct inode *, struct file *);
110 long module_ioctl(struct file *, unsigned int, unsigned long );
111 
122 int session_release(struct inode *, struct file *);
123 
135 ssize_t session_read(struct file *, char __user *, size_t ,loff_t *);
136 
145 loff_t session_llseek(struct file *, loff_t, int);
146 
157 ssize_t session_write(struct file *, const char __user *, size_t, loff_t *);
158 
159 int clear_proc_node(void);
160 
161 void clear_sysfs_file(struct file *);
162 
163 void traverse(struct rb_node*, char*);
164 void traverse_proc(struct rb_node *, char *);
165 
166 void read_file(struct file *);
167 int rb_insert(struct rb_root *, struct session_proc_node *, rwlock_t *);
168 int rb_insert_file(struct rb_root *, struct session_file_node *, rwlock_t *);
169 struct session_proc_node *rb_search(struct rb_root *, int, rwlock_t *);
170 struct session_file_node *rb_search_file(struct rb_root *, char*, rwlock_t *);
171 int session_exit(struct session_proc_node *);
172 int setup_sys_tree(void);
173 int flush(struct inode *, struct file *);
174 ssize_t file_counter_show(struct kobject *, struct kobj_attribute *, char *);
175 ssize_t proc_counter_show(struct kobject *, struct kobj_attribute *, char *);
176 ssize_t path_show(struct kobject *, struct kobj_attribute *, char *);
177 ssize_t path_store(struct kobject *, struct kobj_attribute *, const char *, size_t );
178 ssize_t session_counter_show(struct kobject *, struct kobj_attribute *, char *);
179 
180 
181 #endif
182 
int key
Definition: session_module.h:90
struct rw_semaphore * rw_sem
Definition: session_module.h:78
The wrapper containing the char device used to manage sessions plus the kobject needed into the /sys ...
Definition: session_module.h:63
#define MAX_PATH_SIZE
Definition: session_module.h:45
ssize_t session_read(struct file *, char __user *, size_t, loff_t *)
It reads is onto the session file, every concurrent change onto the original file between the session...
Definition: session_module.c:53
This is the structure into the rb_tree that contains all the open files with their counter...
Definition: session_module.h:74
int session_exit(int)
session_exit expresses the whish of terminating the session
Definition: libsession.c:33
This structure is linked to the original file through the field private_data and the main purpose is ...
Definition: session_module.h:99
ssize_t session_write(struct file *, const char __user *, size_t, loff_t *)
It writes only onto session file keeping immutate the original one.
Definition: session_module.c:34
int session_release(struct inode *, struct file *)
Closes the session related to filp, unlinking the temporary session node, it&#39;s called just after an u...
Definition: session_module.c:176
struct rw_semaphore * rw_sem
Definition: session_module.h:101
This is the structure into the rb_tree that contains all the processes which are currently using the ...
Definition: session_module.h:88
atomic_t session_counter
Definition: session_module.h:92
loff_t session_llseek(struct file *, loff_t, int)
It seeks the position into the session file.
Definition: session_module.c:74
atomic_t counter
Definition: session_module.h:79
struct file * session_filp
Definition: session_module.h:102
char * abs_path
Definition: session_module.h:103