

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Complete the following seven low-level functions:
A zip file (lab5.zip) is included on the class web site with this assignment. The zip file contains eight files:
Test your functions with the provided test1.cpp and test2.cpp files; test1 does not modify the simulated file system but test2 does (you may wish to maintain a backup copy of filesystem). Both readBlock and loadFAT must be written before testing may begin and both must be correct before testing other functions. Remove the comments from main in test1 to test allocate and getByName.
When test1 is complete and correct, then begin implementing functions 5 - 7. The unlink function (called in test2) will remove a file from the FAT (however, the entry will remain in the root directory for now). The file system destructor will save the FAT when test2 ends, which will call saveFAT, which calls wriateBlock - testing all three functions. View the results of test by re-running test1.
The two most difficult functions in this assignment are loadFAT and saveFAT. The FAT is 4K in size: int FAT[BLOCKSZ]; (BLOCKSZ is 1K, so why is the FAT 4K?). The simulated file system reads and writes blocks 1K in size, implying that it takes four reads or writes to load or save the FAT. The challenge is calculating the parameters to readBlock and writeBlock.
The parameters are the same for both functions:
readBlock(int block, void* buffer) writeBlock(int block, void* buffer) “block” is the LBA of the disk block being read or written; “buffer” is the memory address of the transfer buffer (data is either coming from or going to this address). loadFAT calls readBlock four times and saveFAT calls writeBlock four times. The challenge is calculating the correct LBA (relatively easy) and the correct memory address (done with address arithmetic and a little more difficult until you’ve done it once).
The calculations use two symbolic constants defined in FileSystem.h: FATBLK the LBA of the beginning of the FAT on the simulated hard drive QBLK one-quarter of a BLOCKSZ
So, the LBA of any part of the FAT is: FATBLK + i; 0 # i < 4 The buffer address is calculated as an offset from the FAT (a variable defined in the FileSystem class) using address arithmetic: FAT + i * QBLK; 0 # i < 4
Upload your completed FileSystem.cpp to WSU Online for grading.