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:

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
Topic Video
Question
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.
o Program need not implement file deletion or modification.
 
 
 
Sample program output:
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
FILE_SIZE
BLOCKS_OCCUPIED
3
14-15-16
info.doc
19-20-21-22-23
music.mp3
File allocation completed. Exiting.
4
27-28-29-30
Transcribed Image Text:Sample program output: 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 FILE_SIZE BLOCKS_OCCUPIED 3 14-15-16 info.doc 19-20-21-22-23 music.mp3 File allocation completed. Exiting. 4 27-28-29-30
Code snippet:
Fincludecstdio.hs
Fincludecstdiib.hs
Edefine TÜTAL_DISK_BLOCKS 32
Edefine TOTAL_DISK_INODES 8
int blockstatus[TOTAL_DISK_ELOCKS): // fres - 8
int blockstart;
struct file_table {
char filenane[20];
int startslock,
int filesire;
int allotstatu
struct file table filerable[ TOTAL_DISK_BLOCKS - TÜTAL_0ISK_NOoes];
int Allocateslocks (int Size) {
int i - 0, count-, inList - 0, nextelock - 8;
int alloeStartslock - TOTAL_DISK_INOceS;
int allocendelock - TOTAL_DISK_BLOCKS - 1;
// check whether sufficient free blocks are available
For (1 - 8; 1€ (TOTAL_DISK_ELOCKS - TŪTAL_DISK_INÕDE5); 1+4)
if (blockstatus[1] -- 0)
countt;
if (count šize)
return 1;// not enough free blocks
count - 0:
while (count e Size) {
nextslock - (rand() X (allocEndelock - allocStartslock + 1)) + allocstartslock;
for (1 - nextslock, i € (nxteloek + Size); 1++)
if (blockstatus(1] - 0)
count - count + 1;
slse {
count -
beeak
blockstart - nextelock;
if (count - Size)
return 8; / SuccRss
else
return 1; // not succR6sful
void main()
int i -, 1 - 8, nuriles - 8, nextslock - 0, ret - 1;
char s(20];
---
for(i - e; ie nuriles, i++) {
---
ret - Allocatesloeks(f11eTable[1].filasize);
//Seed the pstudo-randon nutber generator uied by rand() with the value seed
srand(1234);
Transcribed Image Text:Code snippet: Fincludecstdio.hs Fincludecstdiib.hs Edefine TÜTAL_DISK_BLOCKS 32 Edefine TOTAL_DISK_INODES 8 int blockstatus[TOTAL_DISK_ELOCKS): // fres - 8 int blockstart; struct file_table { char filenane[20]; int startslock, int filesire; int allotstatu struct file table filerable[ TOTAL_DISK_BLOCKS - TÜTAL_0ISK_NOoes]; int Allocateslocks (int Size) { int i - 0, count-, inList - 0, nextelock - 8; int alloeStartslock - TOTAL_DISK_INOceS; int allocendelock - TOTAL_DISK_BLOCKS - 1; // check whether sufficient free blocks are available For (1 - 8; 1€ (TOTAL_DISK_ELOCKS - TŪTAL_DISK_INÕDE5); 1+4) if (blockstatus[1] -- 0) countt; if (count šize) return 1;// not enough free blocks count - 0: while (count e Size) { nextslock - (rand() X (allocEndelock - allocStartslock + 1)) + allocstartslock; for (1 - nextslock, i € (nxteloek + Size); 1++) if (blockstatus(1] - 0) count - count + 1; slse { count - beeak blockstart - nextelock; if (count - Size) return 8; / SuccRss else return 1; // not succR6sful void main() int i -, 1 - 8, nuriles - 8, nextslock - 0, ret - 1; char s(20]; --- for(i - e; ie nuriles, i++) { --- ret - Allocatesloeks(f11eTable[1].filasize); //Seed the pstudo-randon nutber generator uied by rand() with the value seed srand(1234);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
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
  • SEE MORE 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