We know that there are different disk allocation methods tha
We know that there are different disk allocation methods that help the operating system decide how disk blocks are allocated for files. In the contiguous disk allocation method, each file occupies a set of consecutive addresses on the disk. While this makes file allocation easier, an increase in the file size means that it has to be assigned elsewhere on the disk. The linked disk allocation method requires including a pointer in the current file, which points to the location of the next file. This method makes better use of disk space, but can make file access times longer. Consider this scenario - A file has 100 blocks.
Write a program in C to calculate the disk I/O operations required for each allocation method - contiguous and linked, assuming the following:
1. For the contiguous allocation method, one block is added to the end.
2. For the linked allocation method, one block is added to the end and only the address of the starting block is in the memory.
Solution
#include <stdio.h>
int main()
{
int choice=0; \\\\ user choice variable
printf(\"Number of disk I/O to access 100 block file\ \");
while(choice!=3) \\\\ while loop exit when user press 3
{
printf(\"\ \ Please choose allocation method\ 1. contiguous\ 2. Linked\ 3. exit program\ \");\\\\Display prompt
scanf(\"%d\",&choice); // take user choice
if(choice==1)
{
printf(\"1 I/O operation\ \\t1 write operation\");
}
else if(choice==2)
{
printf(\"102 I/O operation\ \\t1 write operation of new block and storing its address in memory\ \");
printf(\"\\t100 read operation to reach to last block\ \");
printf(\"\\t1 write operation of the new block address in 100th block\ \");
}
else
if(choice!=3)
{
printf(\"Invalid choice\ \");
}
}
printf(\"exiting program\ \");
return 0;
}

