Access over 20 million homework & study documents
search

Assume the DOS file allocation table FAT, is stored as an INTEGER vec

Content type

User Generated

Rating

Showing Page:
1/3
Assume the DOS file allocation table FAT, is stored as an
INTEGER vector fat() indexed by block number where the
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(); int allocate(int
number_of_blocks); int numfiles(); int free(int first_block);
private: vector fat;}; How many files are embedded in the
FAT on the left. Using the interface for the class
Filesystem above, write the member function numfiles
which computes the number of files in the file system.
Using the interface for the class Filesystem above, write
the member function free. This function accept first_block
which is the first block number of a fil in the FAT and
changes all the blocks in fat (FAT) belonging to that file
(linked list) to -2.
Solution
1)
a) as given -1 represents the EOF (end of file) ..... To find
number of files involved in the FAT, can be given by
number if indices containing the value -1 here in the given
FAT table there are 3 entries of -1
hence there are three files involved
b)
int numfiles()

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
{
int count=0;
for(int i=1;i<fat.size();i++)
{
if(fat[i]==-1)
count++;
}
return count;
}
this implementation finds the number of files involved in
the FATtable
2)
int free(int first_block)
{
int index=1;
for(;index<fat.size();index++)
{
if(fat[index] == -1)
break;
else
fat[index]=-2;
}
return index; //this returns the end of file
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up

Unformatted Attachment Preview

Assume the DOS file allocation table FAT, is stored as an INTEGER vector fat() indexed by block number where the 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(); int allocate(int number_of_blocks); int numfiles(); int free(int first_block); private: vector fat;}; How many files are embedded in the FAT on the left. Using the interf ace for the class Filesystem above, write the member function numfiles which computes the number of files in the file system. Using the interface for the class Filesystem above, write the member function free. This function accept first_block which is the first block number of a fil in the FAT and changes all the blocks in fat (FAT) belonging to that file (linked list) to -2. Solution 1) a) as ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really helpful material, saved me a great deal of time.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4