1 | 12 |
2 | 7 |
3 | -3 |
4 | -2 |
5 | 14 |
6 | -1 |
7 | 6 |
8 | -1 |
9 | -2 |
10 | -2 |
11 | -3 |
12 | 2 |
13 | 16 |
14 | 13 |
15 | 5 |
16 | -1 |
FAT
The DOS file allocation table (FAT), is stored as
an INTEGER vector fat [] indexed by block number.
In the FAT, an entry -3 indicates a bad block,
-2 indicates a free block, and -1 indicates an
end of file (last block in the file).
Consider the following declaration of the class
FileSystem
class FileSystem
{
public:
void makefs();
vector<int> allocate(int needed);
int numfiles();
int free(int first_block);
private:
vector<int> fat;
vector<string> filename;
Vector<int> firstblock;
}
Note that files are stored as a linked list
embedded in the FAT, but there is no list of
free blocks. Free blocks are indicated with
a -2 entry in the FAT.
1. (25 points)
Using the interface for the class Filesystem above,
write the member function free. This function accepts
first_block which is the first block number of a file
in the FAT and changes all the blocks in fat (FAT)
belonging to that file (linked list) to -2.
NOTE : Use the vector function size() to compute
the number of elements in the vector fat.
2. (25 points)
Write the function allocate which takes the argument \"int needed\", and
returns a vector of size \"needed\" of free blocks. For example, if the
variable \"needed\" is 4, The function would return 4, 9, 10, 12 using the FAT
in the diagram above.