Task: 1. Write a C program to simulate the sequential file allocation in a very simple file system. 2. Assume a disk of 32 blocks, each block is of 1 KB size 3. First 8 blocks (0 to 7) are allocated to the "iNodes" and can't be used by the file system. Hence blocks available for allocation are from block 8 to block 31. 4. Minimum file size is 1 KB. Hence the file system can have minimum of one file of size 24 KB or maximum of 24 files. 5. At the start, it is assumed that the file system has no files. 6. The program shall ask the user to input the number of files to allocate and their respective names and file sizes. 7. The program shall randomly (set a seed with srand(seed) to replicate the randomness) select any free block as a start block. Check that the start block and the required contiguous blocks are free. If free, allocate those blocks to the file. If not free, find next available contiguous blocks. 8. After allocating blocks for all the files, the program shall print file name, file size, and the contiguously allocated blocks for each file. Refer to the program output shown below. 9. Required test case: Use the example file names and sizes shown above 10. Not required test cases: o If there are not enough contiguous blocks available for a file, the program can exit. Program need not implement file deletion or modification.
Sequential (contiguous) file allocation.
Adding on to below C code to print the attached sample program output.
#include<stdio.h>
#include<stdlib.h>
#define TOTAL_DISK_BLOCKS 32
#define TOTAL_DISK_INODES 8
int blockStatus[TOTAL_DISK_BLOCKS]; // free = 0
int 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 available
for (i = 0; i < (TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES); i++)
if (blockStatus[i] == 0)
count++;
if (count < Size)
return 1; // not enough free blocks
count = 0;
while (count < Size) {
nextBlock = (rand() % (allocEndBlock - allocStartBlock + 1)) + allocStartBlock;
for (i = nextBlock; i < (nextBlock + Size); i++)
{
if (blockStatus[i] == 0)
count = count + 1;
else {
count = 0;
break;
}
}
}
blockStart = nextBlock;
if (count == Size)
return 0; // success
else
return 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 seed
srand(1234);
---
}



Step by step
Solved in 2 steps









