
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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:
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.

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);](https://content.bartleby.com/qna-images/question/3738ec09-0bfd-4ba5-8193-f4cfd6716348/e429bf63-92d4-4b4a-96f6-a9453dd8772b/9ehpo09_thumbnail.png)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
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
- I need help with a C program /* Figure 6.2 */ /* Reads each number from an input file and writes it * rounded to 2 decimal places on a line of an output file. */ #include <stdio.h> int main(void) { FILE *inp; /* pointer to input file */ FILE *outp; /* pointer to ouput file */ double item; int input_status; /* status value returned by fscanf */arrow_forwardWrite a Python Program to perform file operations such as open read, write and close on text and numeric data files with examples.arrow_forwardWrite a C code to take input from an input .txt file and write into an output file. The input file should have int type values and the output file should contain the square of each inputfrom the input file. Must use file type pointers implementation. A sample input and output are given as follows:Input:1 2 3 4 5Output:1 4 9 16 25arrow_forward
- Write a C program that, given a text file, constructs Huffman code based on the character frequencies of the file and then encodes the file accordingly. The executable must accept the following command line options:• -i filename for the input file • -o filename for the output filearrow_forwardWrite a program (in C programming) cylinder.c that accomplishes the following: Read a list of radii and heights from a file(cylinder_input.data). For each pair of values, calculate the cylinder's volume and surface area. Display the results on the screen and save the results to a file. File: cylinder_input.data 1.5 10.2 2.21 20 3 30.243 55.23 2.2 12.1 45.989 The contents of the output file “cylinder_output.data” 1.500000 10.200000 72.099551 110.269902 2.210000 20.000000 306.877054 308.404496 3.000000 30.243000 855.100680 626.615787 55.230000 2.200000 21082.525775 19929.377237 12.100000 45.989000 21153.127133 4416.305811arrow_forwardPlease write this in c++ !!arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education