Project 3: Write a simple device driver

Due date

Dec 6, 2016, 11:59pm (Please demo your project on Dec 07)

Goal

The goal of this project is (1) to obtain a good understanding of device drivers and file systems, (2) to learn the uses of a Loadable Kernel Module, and (3) to understand the difference between regular file I/O and memory-mapped file I/O.

Details

The project consists of three sub-projects.

The first sub-project is very simple; you only need to follow the steps to create a file system within a file. You will be asked to point out the meaning of each step during the demo. In particular, you need to distinguish the concepts of "device", "file system", and "mount point".

The second sub-project is to write two programs. The first is to use regular file I/O to count the number of each character (e.g., in "see", there is one 's' and two 'e's) in link. The second is to use memory-mapped file I/O to do the same thing. Compare the execution time of the two.

In the third sub-project, you need to write a device driver as well as a user program that uses it. Please follow the first article in the references to develop a device driver that registers a pseudo device and that implements the driver functions. So that in the user program you can open the pseudo device and read it. The read call should return the path name of the current working directory. You are not allowed to use the API getcwd. Instead, you have to write some kernel code to retrieve the path name. One of the purposes of this sub-project is to illustrate that, by writing a kernel module, your can add functionalities to the kernel without recompiling and reinstalling it, which is very different from what you did in the second project.

The graph below shows where the current working directory, pwd, is stored (current->fs->pwd): it is a path struct field inside fs_struct.

Hints

Submission

Your submission should include the code, a readme file briefly describing your design, how to compile/use your code and the contribution in the case of pair programming, and a report which consists of the following parts:

Environment

Linux (any kernel after 2.6 is fine) and C/C++.

References

You only need the first reference for coding. If you have time and interest, you can read other articles.

.