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 8 int...



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 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);="">
if (blockStatus[i] == 0)
count++;
if (count <>
return 1; // not enough free blocks
count = 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; // 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);
---
}








File allocation method: SEQUENTIAL<br>Total blocks: 32<br>File allocation start at block: 8<br>File allocation end at block: 31<br>Size (kB) of each block: 1<br>Enter no of files: 3<br>Enter the name of file #1: data.csv<br>Enter the size (kB) of file #1: 3<br>Enter the name of file #2: info.doc<br>Enter the size (kB) of file #2: 5<br>Enter the name of file #3: music.mp3<br>Enter the size (kB) of file #3: 4<br>FILE_fileName<br>data.csv<br>info.doc<br>music.mp3<br>File allocation completed. Exiting.<br>FILE_SIZE<br>BLOCKS_OCCUPIED<br>3<br>14-15-16<br>5<br>19-20-21-22-23<br>4<br>27-28-29-30<br>

Extracted text: File allocation method: SEQUENTIAL Total blocks: 32 File allocation start at block: 8 File allocation end at block: 31 Size (kB) of each block: 1 Enter no of files: 3 Enter the name of file #1: data.csv Enter the size (kB) of file #1: 3 Enter the name of file #2: info.doc Enter the size (kB) of file #2: 5 Enter the name of file #3: music.mp3 Enter the size (kB) of file #3: 4 FILE_fileName data.csv info.doc music.mp3 File allocation completed. Exiting. FILE_SIZE BLOCKS_OCCUPIED 3 14-15-16 5 19-20-21-22-23 4 27-28-29-30
File Name<br>File size (kB)<br>data.csv<br>3<br>info.doc<br>5<br>music.mp3<br>4<br>Block Number 0 1 2<br>3.<br>4<br>5<br>6<br>7<br>Sequential allocation<br>File Name File size (kB) Start block<br>data.csv<br>info.doc<br>music.mp3<br>X<br>X<br>Blocks allocated<br>Block Number<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16 17<br>18<br>19<br>14-15-16<br>19-20-21-22-23<br>27-28-29-30<br>14<br>19<br>Block Number 20<br>21 22 23 24<br>25<br>26<br>27 28 29 30 31<br>4<br>27<br>Task:<br>1. Write a C program to simulate the sequential file allocation in a very simple file system.<br>2. Assume a disk of 32 blocks, each block is of 1 KB size<br>3. First 8 blocks (0 to 7) are allocated to the

Extracted text: File Name File size (kB) data.csv 3 info.doc 5 music.mp3 4 Block Number 0 1 2 3. 4 5 6 7 Sequential allocation File Name File size (kB) Start block data.csv info.doc music.mp3 X X Blocks allocated Block Number 9 10 11 12 13 14 15 16 17 18 19 14-15-16 19-20-21-22-23 27-28-29-30 14 19 Block Number 20 21 22 23 24 25 26 27 28 29 30 31 4 27 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 Program need not implement file deletion or modification. exit.
Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here