Write a device driver for a character device which


Task

Write a device driver for a character device which implements a simple way of message passing. The kernel maintains a list of messages. To limit memory usage, we impose a limit of 4KB for each message, and also impose a limit of the size of all messages, which is initially 2MB.

Your device driver should perform the following operations:

Creating the device, which has to be /dev/opsysmem, creates an empty list of messages.

Removing the device deallocates all messages and removes the list of messages.

Reading from the device returns one message, and removes this message from the kernel list. If the list of messages is empty, the reader returns -EAGAIN.

Writing to the device stores the message in kernel space and adds it to the list if the message is below the maximum size, and the limit of the size of all messages wouldn't be surpassed with this message. If the message is too big, -EINVAL is returned, and if the limit of the size of all messages was surpassed, -EAGAIN is returned.

You should also provide an ioctl which sets a new maximum size of all messages. This operation should succeed only if the new maximum is bigger than the old maximum, or if the new maximum is bigger than the size of all messages currently held. The ioctl should return 0 on success and -EINVAL on failure.

The kernel module which implements this driver must be called charDeviceDriver.ko.

Your solution must not use the kernel fifo.

You need to ensure that your code deals with multiple attempts at reading and writing at the same time. Your code should minimise the time spent in critical sections. The reader should obtain the message in the same order as they were written.

Extra task

You should implement blocking reads and writes: instead of returning -EAGAIN when reading and writing from the device, you should block the reader until a message is available. Similarly, you should block the writer until there is room for the message (in case of the writer).

For the available kernel mechanisms to achieve blocking, see the section Wait queues and Wake events'' in the device driver documentation.

Attachment:- test.rar

Solution Preview :

Prepared by a verified Expert
Operating System: Write a device driver for a character device which
Reference No:- TGS02497072

Now Priced at $45 (50% Discount)

Recommended (90%)

Rated (4.3/5)