Sequential (contiguous) file allocation.
Adding on to below C code to print the attached sample program output.
#include#include#define TOTAL_DISK_BLOCKS 32#define TOTAL_DISK_INODES 8int blockStatus[TOTAL_DISK_BLOCKS]; // free = 0int blockStart;struct file_table {char fileName[20];int startBlock;int fileSize;int allotStatus;};struct file_table fileTable[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES];int AllocateBlocks(int Size) {int i = 0, count = 0, inList = 0, nextBlock = 0;int allocStartBlock = TOTAL_DISK_INODES;int allocEndBlock = TOTAL_DISK_BLOCKS - 1;// check whether sufficient free blocks are availablefor (i = 0; i < (total_disk_blocks="" -="" total_disk_inodes);="">if (blockStatus[i] == 0)count++;if (count <>return 1; // not enough free blockscount = 0;while (count < size)="">nextBlock = (rand() % (allocEndBlock - allocStartBlock + 1)) + allocStartBlock;for (i = nextBlock; i < (nextblock="" +="" size);="">{if (blockStatus[i] == 0)count = count + 1;else {count = 0;break;}}}blockStart = nextBlock;if (count == Size)return 0; // successelsereturn 1; // not successful}void main(){int i =0, j = 0, numFiles = 0, nextBlock = 0, ret = 1;char s[20];---for(i = 0; i < numfiles;="" i++)="">---ret = AllocateBlocks(fileTable[i].fileSize);---}---//Seed the pseudo-random number generator used by rand() with the value seedsrand(1234);---}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here