OpSys Fall 2006 - HW4

HW4 - File System

Due Date: 11/21/06 by 11:55PM

Submit to WebCT drop box labeled HW4

Late Policy

This counts as two homeworks!

- Minimal Filesystem

The objectives of this assignment are:

  1. Understanding of the basic concepts related to the implementation of a simple filesystem.
  2. Experience writing kernel-like code.

You are to design and partially implement a filesystem that is either a FAT (File Allocation Table) or inode based filesystem. We won't be actually adding the code to Unix kernel, instead we will develop a number of Unix programs that provide access to the filesystem (which will actually occupy a single Unix file).

Your filesystem must support a number of operations (listed below), and must be based on either:

Chapter 6 has a description of both approaches.

For this assignment you only need to support a single directory for the entire filesystem. File names can be alphanumeric strings of up to 255 characters, you do not need to support white space in file names. There should not be any artificial limit on the size of any file (as long as there is enough room in your file system, it should allow a file of any size to be created).

Your filesystem will be stored in a single 2MB Unix file named "myfs". All of the programs described below should assume this file is in the current working directory. The file itself must be a sequence of 4096 blocks of size 512 bytes. Every part of the filesystem must be held in these 2048 blocks (including the FAT or inodes and the single directory).

There is no fixed format for your filesystem other than those described above, the general idea is that you pretend you have a 2MB hard disk with block size 512 bytes, you decide how to represent the FAT or inodes and the single directory. It is not expected that your code will work with anyone else's file.

- File system programs

You must provide all of the programs listed below using the command line parameters indicated. Feel free to support additional command line options. We will use test scripts based on the command lines shown below!

fscreate

The fscreate command must create the file named "myfs" in the current working directory and initialize this file to represent an empty file system (a file system that doesn't happen to hold any files).

fsinsert filename:

The fsinsert command adds a new file to your filesystem. The name of the new file is given as the only command line argument. This program should read the Unix file of the same name (in the current working directory) and add it to your filesystem (assuming there is sufficient room). The program should return a 0 if the file has been added successfully (either have main return(0), or call exit(0)). If there is no room for the file, or if there is no such Unix file, the program should print an error message (and have main return(1)). Our scripts will use the program status (return value from main), so you must make sure you set the exit status correctly!

fsremove filename:

The fsremove command removes a file from your filesystem. This command should free up any blocks used by this file and update all data structures (and write the updates to the file "myfs"). This command has nothing to do with the Unix filesystem, you should not delete any Unix files. The program should set the exit status to 0 if there removal works, 1 if there are any problems (perhaps the named file doesn't exist) and print an error message.

fscat filename:

The fscat command prints the contents of the named file (in your filesystem) to stdout. Use write, not printf or cout (so you can handle binary files). Set the exit status as in the other commands (0 if everything is OK, 1 if there is any problem).

fsls:

The fsls command should print out the names and sizes of all files contained in your filesystem.

fsmap:

The fsmap command should print out a string that depicts the block usage of your filesystem. For each of the 4096 blocks you should print either a "*" meaning the block is currently used, or a '-' (minus) if the block is free. The output of this command should look something like this:

***************************--***************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
***********------------------------***------------------------**----------------
---------****-------------------------****------------------------***-----------
-------------**------------------------***---******-***-------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----------------

fsinfo filename:

The fsinfo command should print information about the named file to standard output. The information printed must include:

If the named file does not exist in your filesystem, print an error message and set the exit status to 1.

- Project Requirements

The following are the requirements for the project:

Grading: Your code will be graded according to the formula below. Note that to get full credit we must be able to understand your code (it must be commented!)

60% fscreate, fsinsert, fsremove and fscat commands (these provide minimal functionality). Partial credit is available.
30% fsls, fsmap and fsinfo commands are worth 10% each).
10%Code quality (comments, organization, how hard is it to understand ?).

You can get partial credit for any part.

If your code does not compile and run under FreeBSD, you will lose at least 1/2 the relevant points ( partial credit will be awarded based on visual inspection of the code).

- How to Submit

Log in to WebCT at webct.rpi.edu using your RCS id and password. Once you get to MyWebCT click on "Operating Systems", and from there go to the homework drop boxes. Submit your files (individually, zipped or tarred) to the drop box labeled HW4.

- Notes:

The bulk of the code you need should be shared by your programs. For example, you might create a file named "fat.c" that holds all the FAT related code, a file named "dir.c" that contains all the code related to the single directory you need to support, and a file named "fio.c" that supports actual file I/O to the myfs file. The following might then be a Makefile that would build all your programs:

all: fscreate fsinsert fsremove fscat fsls fsmap fsinfo

SHARED=fat.c dir.c fio.c

fscreate: fscreate.c ${SHARED}
      gcc -o fscreate fscreate.c ${SHARED}

fsinsert: fsinsert.c ${SHARED}
      gcc -o fsinsert fsinsert.c ${SHARED}

fsremove: fsremove.c ${SHARED}
      gcc -o fsremove fsremove.c ${SHARED}

... and so on...

Note that the partial Makefile above compiles all the shared .c files for each executable (which is inefficient!). If you read up on Make you can certainly build a better Makefile that links object modules (.o files) instead...

SPEND SOME TIME PLANNING! You will save lots of time on this assignment if you take the time to design your filesystem first, then build parts of the support code (and test each part individually when possible). This project is not particularly hard (there is no difficult programming) as long as you are organized. If you try to write each program as a single main() function you will waste lots of time!!!

There is probably very little use for any str functions (and C library function starting with the prefix "str")! File names are strings, but you should never treat the contents of a file as a string. We will test your code on binary files (images, executables, etc).