CS611
Fall 2002
Programming Assignment 7
Due Sunday December 15


Implement a simple file system for the IAS machine.

Your file system will not actually execute on the IAS simulator. You will write your file system in C. Your code will interface with a simple emulation of an IAS-style magnetic drum. You will be given code for the emulation of the drum.

A magnetic drum has from 10 to 256 sectors. Sectors are numbered starting with 0. Each sector contains 32 40-bit words.

The emulation code includes the following routines:

  1. void drumCreate(int sectorCount, char* fileName): Start the emulation of a drum with the given number of sectors. The drum is actually implemented with a file of the given name.

  2. int drumSectorCount(void): Query the magnetic drum to get the number of sectors.

  3. int drumReadSector(int sectorNumber, void* memoryAddress): Read the given sector into memory starting at the given address. This routine returns 0 if an invalid sector number is given; otherwise it returns 1.

  4. int drumWriteSector(int sectorNumber, void* memoryAddress): Write the given sector from memory starting at the given address. This routine returns 0 if an invalid sector number is given; otherwise it returns 1.

  5. void drumShutdown(void): Dump the drum contents, print statistics and shutdown the emulation.

Your file system should only use the routines drumSectorCount, drumReadSector and drumWriteSector. The routine drumCreate will be called by a test program prior to calling any file system routines. And the routine drumShutdown will be called by a test program after it is done calling file system routines.

The first word in a sector is a control word that the user of the file system should not see. The control word should be used by the file system to link together the sectors of a file.

Your file system should assume that IAS words are stored in Little Endian format in the memory of the C test programs. This means, in particular, when you write sector numbers in sector 0 or in word 0 of data sectors, you should write them in Little Endian format.

Your file system should support up to ten files. Files are simply referred to by number, 0 to 9. A file is a sequence of sectors.

A file can be empty. If a file is not empty, then it has a current sector. This is the sector that will be read next.

Your file system should support the following routines:

  1. void drumInitialize(void): Initialize the drum to contain ten empty files. This routine always succeeds. It is the file system user's responsibility to be sure this routine is called prior to any other file system routine.

  2. int drumReadNextSector(int fileNumber, void* memoryAddress): Read the next sector in the given file. The user portion of the sector (not including the control word) is copied to the given memory address. The file's current sector number is advanced to its next sector. If the current sector is the last sector in the file then the current sector number is set to the first sector in the file. If the file is empty or the first parameter is not in the range 0-9, then the routine returns 0; otherwise the routine returns 1. No error checking should be done for the address parameter.

  3. int drumInsertSector(int fileNumber, void* memoryAddress): Insert a sector into the given file. A free sector is allocated and its user portion is set to contain the words pointed to by the given memory address. The new sector is inserted into the file by copying the control word of the current sector into the control word of the new sector and then changing the control word of the current sector to point to the new sector. If the file is empty, then the new sector becomes the file's current sector and the new sector's control word is set to zero. If a new sector cannot be allocated or the first parameter is not in the range 0-9 then this routine should return 0; otherwise it returns 1. No error checking should be done for the address parameter.

  4. int drumScratchFile(int fileNumber): Scratch the given file, which means free all its sectors and mark the file as being empty. If the parameter is in the range 0-9 then the routine returns 1; otherwise it returns 0. It is not an error to scratch an empty file.

Sector 0 of the disk should contain control information for the file system. The first twenty words of this sector should contain information about the ten files. These are ten pairs of values, with the first pair describing file 0, the next pair file 1, ..., and the last pair decribing file 9. The first value in a pair indicates the first sector in the file. The second value in a pair indicates the current sector in the file. If the file is empty, then both values should be 0.

The next seven words in sector 0 should contain a bit vector indicating which sectors in the disk are in use (bit is 1) and which are free (bit is 0). Increasing sector numbers are tracked by increasing bit position and then increasing word position. So bit 0 of the first word corresponds to sector 0 of the disk. This bit is always set to 1 because sector 0 is always in use containing the control information. Bit 10 of the first word corresponds to sector 10 of the disk. Bit 0 of the second word corresponds to sector 40 of the disk. Bit 10 of the second word corresponds to sector 50 of the disk. And so on.

Bits in the seven words that do not have a corresponding sector (because the disk is smaller than 280 sectors) should be set to 1.

When you are searching for a free sector, you should choose the free sector with the smallest sector number.

The last five words of sector 0 should all contain 0.

Your implementation should be performed using C. Put all your C code in a file called fs.c. Use the keyword static to mark all routines other than the mandatory routines listed above. Your code should not use any global variables or any static local variables. All information to be remembered between calls to the file system must be stored only on the drum.

The four file system routines will each be worth 25 points.

The magnetic drum emulation code is available in ~cs611/public/prog7. This directory also contains a Makefile and some test programs that can be used to exercise your file system.

Your programs will be graded using a CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment.

Your program will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented.

Your assignment should be submitted for grading from a CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs611/bin/submit prog7 fs.c

Submissions can be checked from a CIS Linux machine by typing:
~cs611/bin/scheck prog7

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday December 16. Late submissions will be accepted at the penalty of 5 points per day up to one week late.

Remember: as always you are expected to do your own work on this assignment. Copying code from another student or from sites on the internet is explicitly forbidden!

If you developed your code on a DOS/Windows system, be sure to appropriately transfer your files to a CIS Linux system before submitting them. You need to convert the DOS ASCII file format to UNIX format. If you need help with this, please see me.


Last modified on November 27, 2002.

Comments and questions should be directed to hatcher@unh.edu