Nachos supports two different filesystems, a ``stub'' that simply maps Nachos file operations into ones the access Unix files in the current directory, and a Nachos file system that users can modify. Use of the stub filesystem makes it possible to implement paging and swapping before implementing a Nachos file system. The -DFILESYS_STUB compilation flag controls which version gets used.
The FileSystem object supports the following operations:
The FileSystem constructor is called once at ``boot time.'' It assumes that a synchDisk instance has already been created and uses it to store the file system.
Argument initialSize specifies the actual size of the file. (Note: initialSize is ignored in the stub filesystem; Unix doesn't require that a file's maximum size be specified at the time it is created.) For the regular filesystem, specifying the file's size at creation time simplifies implementation. Sufficient disk sectors can be allocated in advance to hold the entire (potential) file contents, and appending data to the file requires nothing more than accessing the appropriate blocks. Of course, one possible variation for the assignment is to implement extensible files whose actual size grows dynamically.
Another thing to note is that Open does not truncate a file's contents (it can't since you might be reading the file). However, when writing a file, it is sometimes the case that the file's existing contents should be deleted before new data is written. In Nachos, invoking Create before Open insures that a file is zero-length.
Note that in Unix, the disk sectors associated with a deleted file are not actually returned to the free list as long as there are any processes that still have the file open. Only after all open file descriptors for a file are closed does Unix deallocate the disk blocks associated with the file and return them to the free list. The Unix semantics prevent certain types of undesirable situations. For example, deleting a binary file cannot cause processes paging off of that file's text segment to terminate unexpectedly when the paging system attempts to load an instruction page from non-existent file.
One suggested Nachos assignment is to provide Unix-style file deletion.