Session Module
Data Structures | Macros | Functions
/home/osboxes/Documenti/AOSV/aosv1819-federicoalfano/session_module.h File Reference

The header of the main functions that allows the user a session-based file access semantic. More...

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/fs_struct.h>
#include <linux/fdtable.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/uaccess.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/rbtree.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/dcache.h>
#include <linux/sched/signal.h>
#include <linux/file.h>
#include <linux/namei.h>
#include <linux/mount.h>

Go to the source code of this file.

Data Structures

struct  session_cdev
 The wrapper containing the char device used to manage sessions plus the kobject needed into the /sys to get info about the open sessions. More...
 
struct  session_file_node
 This is the structure into the rb_tree that contains all the open files with their counter. More...
 
struct  session_proc_node
 This is the structure into the rb_tree that contains all the processes which are currently using the sessions. More...
 
struct  session_priv_data
 This structure is linked to the original file through the field private_data and the main purpose is to keep the pointer to the session file. More...
 

Macros

#define SESSION_MAJOR_NUMBER   0
 
#define SESSION_BASE_MINOR   0
 
#define MAX_FILENAME_SIZE   128
 
#define MAX_PATH_SIZE   256
 
#define MAX_FILE_NUM   256
 
#define N_SESS_DIGITS   8
 
#define N_PROC_DIGITS   6
 

Functions

int session_release (struct inode *, struct file *)
 Closes the session related to filp, unlinking the temporary session node, it's called just after an unexpected close. The right way to close a session is with the SESSION_CLOSE from ioctl that replaces the file operations from the original file. More...
 
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 open and the session release are invisible to the read. More...
 
loff_t session_llseek (struct file *, loff_t, int)
 It seeks the position into the session file. More...
 
ssize_t session_write (struct file *, const char __user *, size_t, loff_t *)
 It writes only onto session file keeping immutate the original one. More...
 

Detailed Description

The header of the main functions that allows the user a session-based file access semantic.

Author
Federico Alfano
Date
2 May, 2020

Macro Definition Documentation

#define MAX_FILE_NUM   256

It indicates how many files can be represented, this macro is useful to indicate to the file_counter how many lines can show

#define MAX_FILENAME_SIZE   128

The maximum filename length, you can compile it with different values if you know the maximum length of your files

#define MAX_PATH_SIZE   256

The maximum length of the path

#define N_PROC_DIGITS   6

Indicates of how many digits the proc_counter can have, in other words are maximum number of digits needed to represent the number of per-process sessions

#define N_SESS_DIGITS   8

Indicates of how many digits the session_counter can have, (e.g. setting at 3, the subsystem cannot show more than 999 session)

#define SESSION_BASE_MINOR   0

This is the base minor, it's not critical as the driver is designed to work with just one instance

#define SESSION_MAJOR_NUMBER   0

The Major number of the driver if 0 it's chosen dynamically by the system, please change only if you know what you are doing

Function Documentation

loff_t session_llseek ( struct file *  ,
loff_t  ,
int   
)

It seeks the position into the session file.

Parameters
filpthe file structure pointer referred by the call
offthe seek offset
whencethe seek method
Returns
returns the resulting offset location as measured in bytes from the beginning of the file or an error code
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 open and the session release are invisible to the read.

Parameters
filpthe file structure pointer referred by the call
buffthe destination buffer with data to write
countmaximum number of bytes to read
offpwhere the read has to start
Returns
return the number of bytes read or error code
int session_release ( struct inode *  ,
struct file *   
)

Closes the session related to filp, unlinking the temporary session node, it's called just after an unexpected close. The right way to close a session is with the SESSION_CLOSE from ioctl that replaces the file operations from the original file.

Parameters
inodepthe inode structure pointer referred by the call
filpthe file structure pointer referred by the call
Returns
0 or error code
ssize_t session_write ( struct file *  ,
const char __user *  ,
size_t  ,
loff_t *   
)

It writes only onto session file keeping immutate the original one.

Parameters
filpthe file structure pointer referred by the call
buffthe buffer containing the data to write
countmaximum number of bytes to write
offpwhere the write has to start
Returns
the resulting offset location as measured in bytes from the beginning of the file or an error code