CS 702 - Operating Systems - Spring 2008
Project 4


Loyola College > Department of Computer Science > Dr. James Glenn > CS 702 > Projects > Project 4

Due

Thursday, May 8th at 11:59pm. This project will not be accepted late.

Objectives

Assignment

Write a program that copies files out of an image of a FAT16 file system. Your program should take two command line arguments: the name of the image file and the name of the file to read. The file should be copied into a new file with the same name in the current directory. For example
./p4.x disk.img IPC~1.HTM
should copy the file named IPC~1.HTML from the root directory of the file system whose image is stored in disk.img. The files copied can be of any length.

For files not in the root directory, the path will be given in upper case with a forward slash (/) separating the directories. There should be no separator at the beginning of the path. For example,

./p4.x disk.img F2003/INDEX~1.HTM
should copy the INDEX~1.HTM file from the F2003 subdirectory of the image file to a file called INDEX~1.HTM in the current directory.

Files

There is an compressed disk image in the ZIP archive disk.zip. The image file is disk.img and is 32MB uncompressed. Note that this is not the same image file as given in the lecture notes.

Here are copies of a few of the files to compare your output to; check the complete directory for other files to test.

You can also mount the image in Linux with the commands (as root)
mkdir /mnt/image
mount -o loop ~knoppix/disk.img /mnt/image
and then browse the /mnt/image directory to see the contents of other files in the image.

Beware that the MS-DOS names may be different than the long file names. For example, the file processes.html would be called PROCES~1.HTM.

Advice

You can use the open, read, and lseek system calls to read from the file. lseek(fd, pos, SEEK_SET) will position the file carat so that the next read happens from position pos.

Read all relevant file system parameters from the boot sector -- don't assume parameters will be the same for every file system.

Under g++, short is the 16-bit integer type and char can be used for a 8-bit integer.

If you read data into a char array but you need to get a 16-bit or larger value, you will have to use some typecasts. For example if boot is an array of chars containing data read from the boot sector, then *((unsigned short *)(boot + 11)) will get the sector size (a 16-bit integer stored at offset 11 in the boot sector). An alternate method is to use a struct whose fields are aligned in the same way as the fields on disk. Beware, however, that g++ insists on aligning arrays and 16-bit (or larger) values on even offsets. See the example of reading the boot sector in read_boot.cpp.

Remember that normal directory entries won't have 15 (0F hex) as their attribute byte and won't have names that start with a null character (which is used to indicate the end of a directory) or character 229 (E5 hex) (which is used to mark deleted files).

Grading

For partial credit, try to do the following:

Submissions

Submit an archive containing the files necessary to build and run your completed program. Send the archive as an attachment to an e-mail sent to [first-initial][last-name]@cs.loyola.edu. Files with a .zip extension should be renamed to ensure that they will pass through Loyola's e-mail filters.