Assignment 5: File Allocation Table Checker
Assignment 5: File Allocation Table Checker
Largest chain has length 3. Possible starting locations Largest chain has length 3. Possible starting locations are
are blocks 3 or 6. blocks 0, 3, 9 or 10.
In both FATs above, the longest possible chain has length 3. The FAT on the left contains 2 such chains
– one starting on block 3, and the other starting on block 6. In the FAT on the right, there are also two
chains of length 3 – the first starting on either block 3 or 0, the other starting either on block 9 or 10.
Starter code
Start by downloading and compiling the starter code:
$ git clone https://gitlab.com/cpsc457w23/fatsim.git
$ cd fatsim
$ make
The driver (main.cpp) included in this repository expects the FAT table on standard input, which should
consist of integers separated by white spaces. The driver code parses the FAT contents and then calls the
fat_check() function defined in fatsim.cpp. After fat_check() returns, the driver displays the results.
Your job is to implement the fat_check() function, as described below. Only modify and submit
fatsim.cpp. Do not modify any other files.
The fat parameter will contain the entries of the file allocation table. The meaning of these integers will
be the same as we discussed during lectures, i.e. fat[b] represents block b’s next pointer. Every entry in
fat will be in the range [−1, 𝑁), where N is the size of the FAT, and (-1) denotes a NULL pointer (an
end of chain). The fat_check() function must return all block numbers where the longest chain of blocks
could start, sorted in ascending order.
Below is a sample FAT test file, the expected output, and a graphical representation of the FAT:
$ cat tests/fat3.txt
6 12 7 7 -1 15 9 15 6 10
14 0 -1 11 13 1 12 -1 11 18
For example, the first integer ‘6’ in the above FAT represents the fact that the next pointer of block ‘0’ is
block ‘6’. The longest chain has length 5, and starts either on block 2 or 3. Therefore, for the above
input, the fat_check() function should return [2,3].
Limits:
The number of entries in FAT will be in the range [1…10,000,000].
Marking
• Your code will be marked for correctness and efficiency.
• Your mark will be based on the number of tests your solution will pass.
• To get full marks, you will need to implement an 𝑂(𝑛) solution, so that it can finish on inputs
with 10 million FAT entries under 10s, or inputs with 1 million entries under 1s.
• For partial marks (around 60%), your solution will need to be able to finish under 10s for any
inputs with up to 40,000 FAT entries.
• Small number of test inputs are provided for you in the tests subdirectory, but you should create
your own test inputs as well.
Submission
Submit your fatsim.cpp file to D2L.