11 #include <linux/module.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> 31 #define DEVICE_NAME "session-module" 33 #define SESSION_INSTANCES 1 35 #define SESSION_MAJOR_NUMBER 0 36 #define SESSION_BASE_MINOR 0 38 #define SESSION_CLASS "session-class" 40 #define SESSION_MAGIC 'S' 41 #define SESSION_OPEN_SEQ_NO 0X1 42 #define SESSION_CLOSE_SEQ_NO 0X2 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 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) 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 );
135 ssize_t
session_read(
struct file *,
char __user *,
size_t ,loff_t *);
157 ssize_t
session_write(
struct file *,
const char __user *,
size_t, loff_t *);
159 int clear_proc_node(
void);
161 void clear_sysfs_file(
struct file *);
163 void traverse(
struct rb_node*,
char*);
164 void traverse_proc(
struct rb_node *,
char *);
166 void read_file(
struct file *);
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 *);
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'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