For simplicity, we can assume a predefined maximum number of files allowed on our file system (MAX_FILES) which is defined as 128. This allows us to reserve enough disk space on our disk during a format operation to keep information about each file. We also specified a small fixed maximum file name length (MAX_FILE_NAME), which is defined as 8. This includes the zero byte terminator, so the effective maximum file name limit is 7 characters. We also assume a fixed limit on the number of files that can be open at once (MAX_FILESOPEN), set to 10.
As we said in class, you are to work in teams of two people. I want to be sure that every team has a proficient C programmer, since this is an operating systems course, not a C programming course. If you made less than 100 on program 1, you must work with someone who did score 100.
Next, define a C Structure to use for a "Directory" entry, to be stored on disk. I was able to create one that used exactly 16 bytes, which worked out nicely. Next choose a way to mark clusters as reserved (or alternately mark clusters as available), and choose a way to link clusters together. With those two decisions made, you can then determine apriori how much disk space to reserve for the Directory table and the Allocation table. Then, code the "FormatLow" and "FormatHigh" routines, which should simply zero out all disk sectors, and initialize the Directory Table and Cluster Allocation Table appropriately. You can test the format routine by running "testfs 1 2", which says to run test number 1 (FormatLow) followed by test number 2 (FormatHigh).
At this point, you can code the "Mount" procedure. This will be called every time we run "testfs", and allows you to do any initialization you might need (such as reading the Directory and Allocation tables into memory). Then code the "UnMount" procedure, which will be called in "testfs" when all tests are completed. This allows you to write any updates to the Directory and Allocation table back to the disk.
Next, you need to decide what information you need in an "Open File Table" entry, to keep track of open files. At a minimum, you need a pointer to the Directory entry, a pointer to a memory buffer for data (probably one cluster in size), a current offset into the buffer, and the current file position.
Next, code the OpenWrite routine, which needs to create a new Directory entry for the file specified and creates a corresponding Open File Table entry, and the Delete routine, which deletes an existing file. For Delete, be sure to mark any clusters that were assigned to that file as "available". Note that OpenWrite should automatically delete any previously existing file by the specified name.
Then, code the "Write" routine. Write should write the data first to a memory buffer (writing that buffer to disk only when it fills up or on a subsequent "flush" call).
Next should be flush, which causes the memory buffer to be written out to disk. Flush should NOT adujst the current file position.
The remaining routines can be coded in any order. THe requirements for all routines are clearly documented in "filesys.h" and "filesys.c". You should probably save "Seek" and "OpenExtend" until the last, as they are the most complicated.
testfs 1 2 3 4 5 6 7 8 9 10 11 12
testfs 7
testfs 8
The second two will insure "persistence" (you correctly updated the Directory and Allocation table on the disk).
mail namgeun@cc < filesys.c