The /proc file system

In Linux, 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. Indeed, even the /proc directory contents don't exist on disk. Instead, the contents of the directory is dynamically generated every time it is read.

In this homework, we introduce the /proc file system to xv6.

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. The function namei() returns a struct inode* given a path. To populate the struct (read in inode contents from disk), use ilock().

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.

automatically create /proc folder and then mount proc

When you're testing, it's fine to start by manually creating the proc folder, rebooting and having main() do the mounting. However, during grading, the /proc folder won't exist, and you'll lose points if your program doesn't work right on the first run.

So, have init.c create the /proc folder using mkdir(). But on the first run, you still don't have a /proc when main() runs. So, for full points, create a sys_mount() system call, and call that from init.c. Of course, once you have that, it's a hop, skip and a jump to the bonus points below:

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.

FYI, we'll be testing this on a folder name other than /proc.

Topic revision: r4 - 2017-04-25 - 20:10:13 - Main.jakob
CS385.Homework8 moved from CS385.Homework9 on 2016-11-15 - 19:38 by 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