The kernel device driver /dev/serene allows the user to read, write, replace, clear, empty, display data from a kernel buffer.
Please make sure the kernel version is blah to avoid compilation issues.
- Kernel module
chardev.cneeds to be compiled using the given Makefile with the commandmake - Insert the kernel module before executing the userprocess.c with
insmod chardev.ko - Once the kernel module is inserted, it can be removed using
rmmod chardev.ko
-
The compiled userprocess
gcc userprocess.c(a.out) must be executed withsudo ./a.outto avoid permission issues -
The user must specify the kernel
buffer_sizeand the read/writedata_sizebefore proceeding with any device operations. The implemented char device gives the user with the following options:- Write (1)
- Read (2)
- Empty (3)
- Display (4)
- The buffer write is always sequential. At any given time, the user can only write
data_sizebytes. If the write input size is greater thandata_size, only the firstdata_sizebytes will be considered. If the buffer is full, the subsequent writes will overwrite the exisiting buffer content.
- Unlike write, the read doesn't have to be sequential, it reads only the valid data by skipping the holes (Zeroes). This option lets the user to read valid
data_sizebytes at a time. The subsequent read point to the next available valid data. If all the data in the buffer has been read, the read operation starts again from beginning of the buffer. The user is also provided with the following options on what to do with the read data:- Clear the read data [c]: User can clear the currently read data. This option frees up the buffer space for some new writes.
- Replace the read data [r]: User can replace the currently read data with a new data of
data_sizebytes. - Simply Ignore the read data [n]: No action is taken, only for the monitoring purpose.
- The user can clear the entire content of buffer.
- The user can view the current content of the buffer at any point in time.
make
insmod chardev.ko
gcc userprocess.c -o user
./user
buffer size emptydata size allocator larger than buffer size3.writing into full/empty buffer with below caseswriting lesser than data-sizewriting size greater than data-sizereplacing lesser than data-sizereplacing size greater than data-sizeReading into full/empty buffer with below casesreading size greater than data-sizereading size lesser than data-sizeclearclearing data size == datasizeclearing data size < datasizeRead from empty bufferClearing empty buffer
buffer size emptydata size allocator larger than buffer size3.writing into full/empty buffer with below caseswriting lesser than data-sizewriting size greater than data-sizereplacing lesser than data-sizereplacing size greater than data-sizeReading into full/empty buffer with below casesreading size greater than data-sizereading size lesser than data-sizeclearclearing data size == datasizeclearing data size < datasizeRead from empty bufferClearing empty buffer