CS 702 - Operating Systems - Spring 2005
Project 4


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

Due

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

Objectives

Assignment

(Basic) 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.

(Advanced) 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 is a partial list of the files in the image. Directories are listed followed by the files and subdirectories they contain. Most of these files should be human-readable.

F2003
  EXAMPLES
    EXECVP.C
    ZOMBIE.C
    ADDRES~1.C
  INDEX~1.HTM
  HOMEWORK
    INDEX~1.HTM
    HWK4~1.HTM
    SCORES
  PROJECTS
    P1
      PROJ1~1.HTM
      FACTOR~1.CPP
      INTQUEUE.CPP
    INDEX~1.HTM
    P2
      PROJ2.TAR
      PROJ2~1.HTM
      MAIN.CPP
      HTML
        DOXYGEN.PNG
        INDEX~1.HTM
        ANNOTA~1.HTM
      P2.OUT
    P3
      PROJ3~1.HTM
S2004
    INDEX~1.HTM
    PROJECTS
      INDEX~1.HTM
      P2
        PROJ2~1.HTM
        BUFFER.H
        BUFFER.CPP
      P1
         PROJ1~1.HTM
      P3
        P3TAR~1.GZ
        PROJ3~1.HTM
SCORES
IPC~1.HTM
DEADLO~1.HTM

Here are copies of a few of the files to compare your output to:

You can also mount the image in Knoppix with the commands
mkdir /mnt/image
mount -o loop ~knoppix/disk.img /mnt/image
and then browse the /mnt/image directory to see what other files are in the image. These commands must be issued in the root shell, so press Control-Alt-F2 to switch to the root shell and then Alt-F5 to switch back.

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 jglenn@cs.loyola.edu. Files with a .zip extension should be renamed to ensure that they will pass through Loyola's e-mail filters.