File allocation method: LINKED LIST 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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

With linked allocation, each file is a linked list of disk blocks; the disk blocks may be scattered anywhere
on the disk. The directory contains a pointer to the first and last blocks of the file. Each block contains a pointer
to the next block. Refer to the illustration below. 

Need help to fill in the codes in void main() ---

 #include<stdio.h>
#include<stdlib.h>
#define TOTAL_DISK_BLOCKS 32
#define TOTAL_DISK_INODES 8
int blockStatus[TOTAL_DISK_BLOCKS]; // free = 0
int blockList[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES]; // list of blocks of a file
struct file_table {
char fileName[20];
int fileSize;
struct block *sb;
};
struct file_table fileTable[TOTAL_DISK_BLOCKS - TOTAL_DISK_INODES];
struct block {
int blockNumber;
struct block *next;
};
int AllocateBlocks(int Size) {
---
}
void main()
{
int i = 0, j = 0, numFiles = 0, nextBlock= 0, ret = 1;
char s[20]; struct block *temp;
---
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 Name
File size (kB)
data.csv
3
info.doc
music.mp3
4
Block Number
2
3
4
6
7.
Linked list allocation
File Name File size (kB) Start node
data.csv
info.doc
music.mp3
X.
Blocks allocated
Block Number
8
10
11 12
13 14 15
16 17
18 19
3
14
14-19-11
12
12-29-27-10-28
Block Number 20
21 22
23
2475
26
28 29
30
31
4
21
21-23-17-30
Task:
1. Write a C program to simulate the Linked list 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. Subsequent blocks shall be randomly picked (based on file size) if free.
8. All selected blocks of a file shall be maintained in a linked list.
9. Afterallocating buffers for all the files, the program shall print file name, file size, and the allocated
linked list of blocks for each file. Refer to the program output shown below.
10. Required test case: Use the example file names and sizes shown above
11. Not required test cases:
If there are not enough contiguous blocks available for a file, the program can exit.
Program need not implement file deletion or modification.
1.
Transcribed Image Text:File Name File size (kB) data.csv 3 info.doc music.mp3 4 Block Number 2 3 4 6 7. Linked list allocation File Name File size (kB) Start node data.csv info.doc music.mp3 X. Blocks allocated Block Number 8 10 11 12 13 14 15 16 17 18 19 3 14 14-19-11 12 12-29-27-10-28 Block Number 20 21 22 23 2475 26 28 29 30 31 4 21 21-23-17-30 Task: 1. Write a C program to simulate the Linked list 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. Subsequent blocks shall be randomly picked (based on file size) if free. 8. All selected blocks of a file shall be maintained in a linked list. 9. Afterallocating buffers for all the files, the program shall print file name, file size, and the allocated linked list of blocks for each file. Refer to the program output shown below. 10. Required test case: Use the example file names and sizes shown above 11. Not required test cases: If there are not enough contiguous blocks available for a file, the program can exit. Program need not implement file deletion or modification. 1.
Sample program output:
File allocation method: LINKED LIST
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 NAME
data.csv
NO_OF_BLOCKS
BLOCKS OCCUPIED
3
14-19-11
info.doc
music.mp3
File allocation completed. Exiting.
5
12-29-27-1e-28
4
21-23-17-30
Transcribed Image Text:Sample program output: File allocation method: LINKED LIST 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 NAME data.csv NO_OF_BLOCKS BLOCKS OCCUPIED 3 14-19-11 info.doc music.mp3 File allocation completed. Exiting. 5 12-29-27-1e-28 4 21-23-17-30
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY