Thread Synch AOSV 2020  1.2
LKM for exchanging messages between threads
Data Structures | Macros | Functions | Variables
main_device.h File Reference

Handles all procedures releated to the main synch device file. More...

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/semaphore.h>
#include <linux/ioctl.h>
#include <linux/idr.h>
#include "group_manager.h"
#include "sysfs.h"
Include dependency graph for main_device.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_main_sync
 Main device structure. More...
 

Macros

#define INVALID_IOCTL_COMMAND   -1
 
#define ALLOC_ERR   -2
 
#define USER_COPY_ERR   -3
 
#define IDR_ERR   -4
 
#define MEM_ACCESS_ERR   -5
 
#define CLASS_EXISTS   -10
 
#define CLASS_ERR   -11
 
#define DEV_CREATION_ERR   -12
 
#define CDEV_ALLOC_ERR   -13
 
#define GROUP_EXISTS   -14
 
#define IOCTL_INSTALL_GROUP   _IOW('X', 99, group_t*)
 
#define IOCTL_GET_GROUP_ID   _IOW('X', 100, group_t*)
 
#define D_DEV_NAME   "main_thread_synch"
 
#define D_DEV_MAJOR   (0)
 
#define D_DEV_MINOR   (0)
 
#define D_DEV_NUM   (1)
 
#define CLASS_NAME   "thread_synch"
 
#define GRP_MIN_ID   0
 
#define GRP_MAX_ID   255
 

Functions

int mainInit (void)
 Kernel Module Init. More...
 
void mainExit (void)
 Kernel Module Exit. More...
 
void initializeMainDevice (void)
 Init Main Device members. More...
 
int installGroup (const group_t new_group)
 Install a group for the provided 'group_t' descriptor. More...
 

Variables

struct class * group_device_class
 

Detailed Description

Handles all procedures releated to the main synch device file.

Macro Definition Documentation

◆ ALLOC_ERR

#define ALLOC_ERR   -2

Returned when a 'kmalloc' fails

◆ CLASS_EXISTS

#define CLASS_EXISTS   -10

Returned when the class name already exists

◆ CLASS_NAME

#define CLASS_NAME   "thread_synch"

Main device class name

◆ D_DEV_MAJOR

#define D_DEV_MAJOR   (0)

Main device major#

◆ D_DEV_MINOR

#define D_DEV_MINOR   (0)

Main device minor#

◆ D_DEV_NAME

#define D_DEV_NAME   "main_thread_synch"

Main device name

◆ D_DEV_NUM

#define D_DEV_NUM   (1)

Number of main device

◆ GRP_MAX_ID

#define GRP_MAX_ID   255

Group's max ID

◆ GRP_MIN_ID

#define GRP_MIN_ID   0

Group's min ID

◆ IDR_ERR

#define IDR_ERR   -4

Returned when the IDR fails

◆ MEM_ACCESS_ERR

#define MEM_ACCESS_ERR   -5

Returned when 'access_ok' fails

◆ USER_COPY_ERR

#define USER_COPY_ERR   -3

Returned when copy_to_user/copy_from_user fails

Function Documentation

◆ initializeMainDevice()

void initializeMainDevice ( void  )

Init Main Device members.

Parameters
nothing
Return values
nothing
Note
If a new structure is addedd to 't_main_sync' all init procedures should be perfomed here

◆ installGroup()

int installGroup ( const group_t  new_group_descriptor)

Install a group for the provided 'group_t' descriptor.

Parameters
[in]new_group_descriptorThe group descriptor
Return values
Theinstalled group's ID
ALLOC_ERRif some memory allocation fails
IDR_ERRIf the IDR fails to allocate the ID
Note
For error codes meaning see 'main_device.h'

◆ mainExit()

void mainExit ( void  )

Kernel Module Exit.

Todo:
Check that every structure is correctly deallocated
Parameters
nothing
Return values
nothing

◆ mainInit()

int mainInit ( void  )

Kernel Module Init.

Parameters
nothing
Return values
0success
CLASS_EXISTSif the class already exists
othersfailure