/dev/random and /proc file system

In most Linuxes, /dev/ holds a number of "device" files. These "files" are not backed by file storage. Instead, device numbers (shown with ls -l) describe what driver should handle read and write requests to this file.

Similarly, the /proc directory holds a number of files that don't have a representation on disk. These "virtual" files describe the state and configuration of the system, its processes, and more. In contrast with /dev, the /proc files do not have device numbers, and even the /proc directory does not exist on disk. Instead, the contents of the directory is dynamically generated every time it is read.

In this homework, we experiment with device files, and introduce the /proc file system to xv6.

Random number device file

The system call mknod() creates a device file. However, no user space program exists to take advantage of it. Create a mknod executable, then use it to create a new device file called random with major=2, minor=1.

Modify xv6 so that when a process reads from random, an infinite series of random bytes is produced. Reading from this with cat won't work well since some numbers don't come out well as characters. To test, write a small program to read from random and print them out in decimal form.

Virtual directory listing

Create a directory /proc using mkdir. Modify xv6 so that when ls /proc is executed, it shows a list of "virtual" files - files that don't actually exist on disk. There should be one directory per running process, and a file called meminfo.

To help you with this part, the hw8 template in the git repository includes some changes to the file system code. Specifically, struct inode now contains a pointer to a struct inode_functions, which in turn holds functions for reading and writing file contents, and for populating inode data.

To get started, change the i_func pointer of the inode for "/proc", so that when we try to read "/proc", your functions are called. To provide a directory listing, see how "ls.c" reads it, and write a procfs_readi function to match.

Make sure "ls /proc" displays the appropriate names listed above, and sensible types and sizes. For this, you'll need to implement procfs_ipopulate. Watch out for iget() here: use a different device number for "proc" files to avoid reusing the wrong inode.

meminfo and cpuinfo files

Update xv6 so that meminfo shows the total amount of memory and the amount of memory currently free. cpuinfo shows how many cores are available.

process directories and files

For each running process, the corresponding directory (named by pid) should contain several files, including name, and parent.

Bonus Points: Flexible user-space mounting

Add a system call mount(), and an executable mount that allows the user to mount any named file system (proc being the only one supported at the moment), on any directory.

Topic revision: r6 - 2014-11-11 - 04:23:29 - Main.jakob
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF