Due Date: May 1, 2008. 100 points
Single person project. Do your own work!
In this project, you will implement file system functions on a RAM disk file system that is provided. The ideas behind this project were discussed in the April 8th lecture and are described in the OSC book in Chapter 11. While this code is not based directly on any OS implementation, it does share the common concepts from a UNIX file system.
In particular, you are going to be required to implement four functions in the file system implementation:
fileSeek( unsigned int fd, unsigned int offset ): Set the offset in the per-process file structure (fstat_t) for the file specified by the file descriptor fd. You will need to look up the file for the file descriptor. Your implementation must be able to seek to any location in the file.
fileRead( unsigned int fd, char *buf, unsigned int bytes): This function reads bytes bytes from the current position of the file offset (e.g., set by fileSeek above). Read must find the file blocks to read and collect the data into the buffer. The function diskRead is provided to retrieve the bytes from the block when the correct block is found. Your file read must be able to read the entire file or any subset. Files may span multiple data blocks.
diskWrite( fcb_t *fcb, unsigned int block, char *buf, ...): Writes the data from the buffer buf into the RAM disk at the appropriate block for the file referenced by the file control block fcb. You need the fcb to maintain the correct size of the file on the disk. The function diskRead is similar, so please use that as a hint. This file only writes to one block at a time.
fileWrite( unsigned int fd, char *buf, unsigned int bytes ): This function writes bytes of data from buffer buf into the file from the current position of the file offset (e.g., set by fileSeek above). Your function diskWrite performs the actual writing to the RAM disk. This function and fileRead share a number of similarities: both require finding the appropriate blocks (to write in this case) and call the disk-level version to update the RAM disk. Your file write must be able to write to any location in the file and beyond the current end of the file (i.e., can make the file larger). Files may span multiple data blocks.
You need data to test fileRead, so you may build a simplified version of fileWrite first (e.g., writes to only one block) before going to the full versions necessary.
The challenge in this project is to understand the concepts in the file system. The file system structures are defined in the file cse473-filesys.h. Please study these structures -- most map to the structures discussed in Chapter 11. The full tarball for the project is available here.
The other challenge is to understand the layout of these structures in blocks on the RAM disk. Below is a diagram outlining the blocks in the on-disk file system.
The first block (block 0) is the file system (partition) control block. All the blocks have a bit of block information at the beginning (dblock_t), but after that are the block contents. Block 0 specifies the number of blocks in the file system (bsize), the current first free block (firstfree), and the block number for the root directory (only directory). There is only one file system block.
Block 1 is the block that stores the directory. A directory refers to its hash table of directory entries (i.e., dentry) by its number of buckets which fill the remainder of the block and the location of the next free spot for a dentry (freeblk and free (slot)). Only the heads of the hash table are stored in the hash table. Each dentry has a next reference that is used to traverse the hash table lists. There are usually multiple directory blocks, but in this project there is only one.
Block 2 is the first dentry block, and it contains a set of dentries which each refer to a specific file by its name and (first) block. A next reference specifies the next entries to access for the dentry hash table. There can be multiple of these.
Block 3 is the file control block (FCB) which refers to the file meta data and actual data blocks. There are only 10 blocks in a file currently. There is one FCB per file.
Block 4 is a typical file data block. Other than the block header these blocks contain only file data. There should be lots of these.
In the assignment, an output file shows the sequence of commands and responses for your file system. You will run 5 commands to generate this output: ./cse473-p4 your_fs cmdi where cmdi is the ith command for (e.g., cmd1 for the first). This program is deterministic, so your output should match mine (bug disclaimer here).