CS611
Spring 2003
Programming Assignment 7
Due Sunday May 18
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:
- 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.
- int drumSectorCount(void): Query the magnetic drum to get
the number of sectors.
- 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.
- 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.
- 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.
Your file system should assume that IAS words are stored in Little Endian
format in the memory of the C test programs.
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 IAS words.
The maximum file length is 320 words (i.e. 10 sectors).
A file can be empty, which means that its length is 0.
Files always have a "current position", the offset into the
file at which the next read or write operation will begin.
For an empty file the position is 0.
A read or a write operation updates the position by the number
of words read or written.
Your file system should support the following routines:
- void fileSystemInitialize(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.
- int fileRead(unsigned int fileNumber, void* memoryAddress, unsigned int length):
Read the next 'length' words in the given file.
The read starts at the current position, copying words from the file
to consecutive positions in memory starting at 'memoryAddress'.
The current position is updated by the number of words read.
If EOF is reached before 'length' words are read, then the read stops
at EOF.
The function returns the number of words actually read.
If an illegal file number is passed, then the function returns -1.
No error checking should be done for the address parameter.
- int fileWrite(unsigned int fileNumber, void* memoryAddress, unsigned int length):
Write the next 'length' words in the given file.
The write starts at the current position, copying words from memory starting
at 'memoryAddress'.
The current position is updated by the number of words written.
If the current position is before the EOF, then words in the file are
overwritten.
If the current position is at the EOF, then the file length is extended.
If the maximum file length is reached or there are no more free sectors
on the disk, then the write terminates.
The function returns the number of words actually written.
If an illegal file number is passed, then the function returns -1.
No error checking should be done for the address parameter.
- int fileRewind(unsigned int fileNumber): Reset the current
position of the given file to the beginning of the file.
If the parameter is in the range 0-9 then the routine returns 1;
otherwise it returns 0.
- int fileScratch(unsigned 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.
This routine should not "clear" the words in the freed sectors.
Sector 0 of the disk should contain control information for the file system.
The first thirty words of this sector should contain information about the ten
files.
These are ten triples of words, with the first triple describing file 0,
the next triple file 1, ..., and the last triple decribing file 9.
The first word in a triple indicates the file length and the current
position of the file.
The file length is in the low 20 bits of the word and the file position
is in the upper 20 bits.
The second and third words in a triple contain a sector list for the file.
The first sector number of the file will be in the bits 0-7 of the
second word, the second sector number will be in bits 8-15 of the second word,
..., the fifth sector number will be in bits 33-40 of the second word, the
sixth sector number will be in bits 0-7 of the third word, the seventh sector
number will be in bits 8-15 of the third word, ..., the tenth sector number
will be in bits 33-40 of the third word.
Unused elements of the sector list should contain 0.
If a file is empty, then all three words of its triple should contain 0.
The last two words of sector 0 contain a head and a tail pointer for a
linked list of the free sectors on the disk.
A free sector is one that is not allocated to any file.
The second to last word contains the head of the list.
The last word contains the tail of the list.
The sector numbers are stored in the low 8 bits of the words, with
the upper bits containing 0s.
Sectors are linked together by storing the next sector number in the
list in word 0 of the current sector.
Sector numbers are stored in the low 8 bits of the word 0, the
upper bits containing 0s.
The last sector in the list should have its word 0 set to 0.
When you are searching for a free sector, you should take the sector
at the head of the list.
When you are freeing a sector, place it at the end of the list.
When you initialize the drum, you should link all sectors (other than
sector 0, obviously) together in increasing numeric order.
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 five file system routines will each be worth 20 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 May 19.
Late submissions will be accepted at the penalty of 5 points per day up to
8am on Thursday May 22.
NO ASSIGNMENTS WILL BE ACCEPTED AFTER 8AM ON THURSDAY MAY 22.
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!
Last modified on May 1, 2003.
Comments and questions should be directed to
hatcher@unh.edu