Project 3 - Part 2: File Systems

Deadline (part 2): August 23, 2003 23:59 PST

Contents

Overview

The goal of part 2 of this project is to implement /proc file system for your nachos kernel. In project 2, you have implemented basic system calls for file operations (Create, Open, Read, Write, and Close). In this project, you will add few more system calls (again, just as stubs using Unix file system) and implement your own /NachosProc file system to enable user-level processes to get more details about kernel data structures.

System calls: You need to add the following system calls:

  1. int MkDir(char *dirname); Creates a new directory in current dir. Returns -1 in case of error and 0 if successful.
  2. int ChDir(char *path); Changes current directory to relative or absolute path.
  3. int ReadDir(char *filename); and int ReadNext(char *filename); In order to find out which files are in the current directory you will implement ReadDir which returns filename of the first file and ReadNext which returns filename of the next file. Filenames are copied to user memory at char *filename address. If return value is 0 filename contains a name of a regular file, if it's 1, it contains a name of a directory, and if it's -1 then there are no more files in a directory (and the filename is unchanged).

You need to have one more data structure in your PCB: current_path for each process. To make sure you do not change wrong files in your Linux home directory, you should create directory NACHOS_DISK in your test directory, and restrict all nachos system calls to work only inside that directory. This means that you will initialize current_path of each process to be /, but operate it relative to NACHOS_DISK directory. (NACHOS_DISK/../../../.. shouldn't work -> you should not be able to get bellow NACHOS_DISK from your user-level processes.)

If you ChDir to a special directory named: /NachosProc (which doesn't actually exists anywhere on disk) you should move to a different file system - your /NachosProc file system. User program can move back to the regular file system by using ChDir system call. In this file system you will have different implementation of your system calls for file manipulation. Your /NachosProc should contain one file for each process, filenames should be SpaceId's (integers). You can get these names in user-space with ReadDir and ReadNext system calls. You can open these files and you can read from them in user-level processes. Each time when you read, you will send the following data to user process' read buffer: [pid][parent=ppid][memory_size=size][physical_pages=number of physical pages used by pid]. If the buffer in Read system call is too small, then write what you can. If it is too large, write 0 to finish string. System calls like Write or Delete have no meaning in NachosProc file system and should return an error. ChDir and Close should work as expected.

Suggested Steps

Stage 1:
Add new system calls to start.s and syscall.h. Similar to project2, you need to add few more system calls to nachos. (Please notice that I have removed Delete system call from specs- just to make sure you don't shoot yourself in the foot. Also, please do not test using system call Write in this project: you will not need it, and we don't want you to rewrite some of your important files by mistake...)

Stage 2:
Implement stubs for new system calls using glibc functions for file system interface. Check glibc manual (you have link on cs170 home page) and use the following functions: mkdir, chdir, opendir, and readdir.

Stage 3:
For all file related system calls you will need to add one switch at the beginning:
if (!strcmp(current_path,"//NachosProc"){
handle files in proc file system - not from the disk
} else {
existing code which uses disk files
}

The /proc file system calls Write, MkDir, Create don't do anything except returning error. ReadDir gives a name of the currently running process (it's pid converted to string filename) with the smallest SpaceId. ReadNext gives a name of the next process in the increasing order of SpaceId's.

Stage 4:
Implement ReadDir, ReadNext, Open, Read, and Close for your /proc file system. Remember, these files do not exist on the disk: this is just an interface to your kernel data structures (in our case mostly your array of all processes and some simple info in their PCBs (ppid and memory size).

What to submit

What to Turnin

  1. Go to the directory that contains the top level code directory of your nachos.
  2. Turn in your code directory by typing turnin project3-2@cs170 code.
  3. In addition to the code, include a file called reports/project3-2.txt that briefly explains the design of your code and how it works. If some parts of your code do not run, you need to say this outright in report and to describe your design, implementation and difficulties. This is needed for partial credit.

You can turnin multiple times per project. Earlier versions will be discarded. The timestamp of turnin has to be before midnight of the due date.

Required Output

Credit