Program 5: /proc
CS 3210 Design of Operating Systems
Spring 2000 * Hutto
Georgia Tech College of Computing
DUE: noon Wednesday 3 May 2000
Basic Assignment
For your fifth programming assignment, you will implement a simple file in the /proc filesystem. What does it mean to "implement" a file? Recall that the contents of files in /proc are "generated on-demand". Files in /proc can be implemented as loadable modules that register themselves and provide an appropriate implementation of the file interface. In our case, you must simply implement a "read" method that is registered and called indirectly by higher filesystem layers. In addition, you will need simple init_module and cleanup_module methods as usual when writing a loadable kernel module.
I realize you are probably not happy about the late due date on this assignment, so to make things really easy, all you need to do is get the sample code in Chapter 3 of Linux Kernel Module Programming Guide (LKMPG) working. The LKMPG has been recently updated by the author Ori Pomerantz and the given code should run properly without modification. Ori's program simply generates a "Go away!" message in the file /proc/test. He uses a static counter in the implementing module to remember how many times he has told you to "Go away!" So "reading" /proc/test should generate output like this:
pwh> cat /proc/test
For the 1st time, go away!
pwh> cat /proc/test
For the 2nd time, go away!
pwh> cat /proc/test
For the 3rd time, go away!
pwh>
Extra Credit
For extra credit, get the more ambitious program in Chapter 4 of the LKMPG working. Chapter 4 presents a module implementing /proc/rw_test. This file can be both read and written, showing how a proc file can be used to control or configure kernel facilities. To keep the example simple, the rw_test file simply "remembers" the text previously written and supplies it on the next read (gee, like a real file). This simple example could easily be generalized. It includes a "module_permission" function that is called each time a read or write operation is requested to authorize the operation.
The /proc filesystem makes it very easy to implement a small read-only proc file. Supporting input requires using the general Linux filesystem infrastructure. You must supply "struct file_operations" and "struct inode_operations" function pointer tables to "customize" the filesystem and implement the /proc/rw_test functionality. This exercise clearly reveals the filesystem layers Jason discussed in class (up to but not including the VFS layer).
pwh> cat >/proc/rw_test
I don't want to go away!
^D
pwh> cat /proc/rw_test
I don't want to go away!
pwh>
Resources
Rubini has a short discussion of implementing a something similar to Ori's /proc/test for the scull project. See pages 74-76.
Beck has a nice discussion of the overall implementation of the /proc filesystem in section 6.3 (pages 173-179).
And, of course, linux/fs/proc/*.
Turnin
Schedule a demo time with Jason as usual. In addition, you need to submit source and a README file describing any modifications or additions.
Graduating Seniors
This is a very easy assignment and I expect graduating seniors to make some effort on this project. Two groups have only one non-graduating member. I recommend that David Spiller and Tim Sotack join groups and work together on this final project.
Final Thought
Expect the final exam to include at least one challenging question related to the /proc filesystem implementation!
Good luck!