CS 302 - Programming Assignment 7

This assignment makes use of four files contained in this zip file. This assignment has two parts.

This assignment is due Friday, April 20.

Part I

For this part of the assignment you are to write a program that accesses the sectors of a floppy disk at a fairly low level. (The second part will look at the "file allocation table" (i.e., FAT) that is on the floppy disk.)

You are to write implementations for the following three functions, which are described in comments in the file floppy.h which is contained in the above zip file.

HANDLE physicalDisk(char driveLetter);
void sectorRead(HANDLE theDisk, unsigned int logicalSectorNumber, unsigned char* buffer);
void sectorDump(HANDLE theDisk, unsigned int logicalSectorNumber);
Your definitions of the three functions must work with the driver program floppy.c which is also in the above zip file (you do not need to make any changes in the file floppy.c). Make sure that you error check all of the Win32 function calls that you make. For example, your program should produce meaningful error messages if there is no floppy disk in the drive, or if the floppy disk is not formatted.

When you have this program done, experiment with it. Take a blank floppy disk and look at a bunch of its sectors. Are they empty? Format the floppy and look at the sectors again. Add a small text file to the newly formatted disk. Find the sectors that the file's data are written to (the data sectors will be after sector 10). Now delete the file. Is the data still there in the sectors? If you have access to a "boot floppy", look at its sector 0 and compare it to sector 0 of a non boot disk.

Here are links to three of the Win32 API functions that you will need to use in this part of this assignment.

One of the things that you need to do in this part of the assignment is implement a hex dump of sectors from a floppy disk. It helps to have something that can verify for you that your hex dump is correct. You can do this using Microsoft Windows built in DOS debug command. At a command prompt, enter the following commands:

C:\>debug
-l 100 0 0 1
-d 100 1ff
These commands will dump the first half of sector zero from a floppy disk in drive A (only half a sector will fit in a command prompt window). You dump the second half of the sector using
-d 200 2ff
You can dump any sector from the floppy by using a "load" command of the following form.
-l 100 0 <sector-number> 1
where the sector number is a hexadecimal number. In the zip file there is a screen shot of what these commands look like.

Here are links to information about the DOS debug command.

Part II

For this part of the assignment you are to write a program that "unpacks" and displays the File Allocation Table (FAT) on a floppy disk so that the FAT can be more easily understood and manipulated. One of the points of this assignment is to emphasize why you want the operating system to provide "device abstractions" (because accessing a floppy disk at this low a level is not all that easy) and to also give you an idea of how an operating system can maintain a file system on a disk. This part of the assignment will use your floppy.h file from Part I above.

You are to write implementations for the following three functions, which are described in comments in the file floppyFAT.h which is contained in the above zip file.

BOOL fatRead(HANDLE theDisk, unsigned char *buffer);
void unpackFAT(unsigned char *buffer, int* unpackedFAT);
int countObjects(int* unpackedFAT);
Your definitions of the three functions must work with the driver program floppyFAT.c which is also in the above zip file (you do not need to make any changes in the file floppyFAT.c). Make sure that you error check all of the Win32 function calls that you make.

Notice that the third function in floppyFAT.h counts how many objects are on the floppy. An "object" is either a file or a directory. You need to read the references about the FAT12 file system and figure out a simple way to use the unpacked FAT to determine how many objects are on a floppy.

When you have this program done, experiment with it. Format a floppy and then look at its FAT. Compare the display of the FAT given by floppyFAT.c with dumping sectors 1 through 9 using floppy.c from Part I of this assignment. Add a small file to the floppy and look at the FAT again. Add a few small and medium size files to the floppy. Look at the FAT again. Delete the first couple of files that you put on the floppy. Look at the FAT again. Add a couple of new files to the floppy. Did they use up the FAT entries left empty by the deleted files? What does it mean for a floppy to become "fragmented"? Run floppyFAT.c and floppy.c simultaneously (in two different console windows) and use the display of the FAT given by floppyFAT.c to find and view, using floppy.c, the data sectors of a multi sector file.

In this part of the assignment you will need to make use of the following C operators.

Here are links to some web pages about the FAT file system.

Turn in a zip file containing your versions of the floppy.h and floppyFAT.h files and also the floppy.c and floppyFAT.c files.


Return to the main homework page.
Return to the CS 302 home page.


compliments and criticisms