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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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);
---
}

 

 
 
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
Transcribed Image 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
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.
Transcribed Image 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.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Software Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education