SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
File Organization
Files are normally stored on the disks. So the main problem is how to allocate space to those files.
So that disk space is utilized effectively and files can be accessed quickly. Three major strategies
of allocating disc space are in wide use. Sequential, indexed and linked.
Sequential Allocation
In this allocation strategy, each file occupies a set of contiguously blocks on the disk. This strategy
is best suited. For sequential files, the file allocation table consists of a single entry for each file.
It shows the filenames, starting block of the file and size of the file. The main problem with this
strategy is, it is difficult to find the contiguous free blocks in the disk and some free blocks could
happen between two files.
Sequential File Allocation Algorithm
STEP 1: Start the program.
STEP 2: Gather information about the number of files.
STEP 3: Gather the memory requirement of each file.
STEP 4: Allocate the memory to the file in a sequential manner.
STEP 5: Select any random location from the available location.
STEP 6: Check if the location that is selected is free or not.
STEP 7: If the location is allocated set the count = 1.
STEP 8: Print the file number, length, and the block allocated.
STEP 9: Gather information if more files have to be stored.
STEP 10: If yes, then go to STEP 2.
STEP 11: If no, Stop the program
Sample Code
#include <stdio.h>
#include<conio.h>
void main()
{
int f[50], i, st, len, j, c, k, count = 0;
for(i=0;i<50;i++)
f[i]=0;
printf("Files Allocated are : n");
x:count=0;
printf("Enter starting block and length of files:");
scanf("%d%d",&st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0)
count++;
if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("%dt%dn",j,f[j]);
}
if(j!=(st+len-1))
printf("The file is allocated to diskn");
}
else
printf("The file is not allocated n");
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Sample Output
Case 1:
Files Allocated are :
Enter starting block and length of files:14 3
14 1
15 1
16 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files:14 1
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files:14 4
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)
Case 2:
Files Allocated are :
Enter starting block and length of files:17 4
17 1
18 1
19 1
20 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files:21 3
21 1
22 1
23 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files:19 4
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files:25 5
25 1
26 1
27 1
28 1
29 1
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)
Indexed File Allocation
The Indexed File Allocation stores the file in the blocks of memory, each block of memory has an
address and the address of every file block is maintained in a separate index block. These index
blocks point the file allocation system to the memory blocks which actually contains the file.
Indexed File Allocation Algorithm
STEP 1: Start the program.
STEP 2: Get information about the number of files.
STEP 3: Get the memory requirement of each file.
STEP 4: Allocate the memory to the file by selecting random locations.
STEP 5: Check if the location that is selected is free or not.
STEP 6: If the location is allocated set the count = 1, and if free set count = 0.
STEP 7: Print the file number, length, and the block allocated.
STEP 8: Gather information if more files have to be stored.
STEP 9: If yes, then go to STEP 2.
STEP 10: If no, Stop the program.
Sample Code
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int f[50], index[50],i, n, st, len, j, c, k, ind,count=0;
for(i=0;i<50;i++)
f[i]=0;
x:printf("Enter the index block: ");
scanf("%d",&ind);
if(f[ind]!=1)
{
printf("Enter no of blocks needed and no of files for the index %d
on the disk : n",ind);
scanf("%d",&n);
}
else
{
printf("%d index is already allocated n",ind);
goto x;
}
y: count=0;
for(i=0;i<n;i++)
{
scanf("%d", &index[i]);
if(f[index[i]]==0)
count++;
}
if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
printf("Allocatedn");
printf("File Indexedn");
for(k=0;k<n;k++)
printf("%d-------->%d : %dn",ind,index[k],f[index[k]]);
}
else
{
printf("File in the index is already allocated n");
printf("Enter another file indexed");
goto y;
}
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Sample Output
Case 1:
Enter the index block: 5
Enter no of blocks needed and no of files for the index 5 on the disk :
4
1 2 3 4
Allocated
File Indexed
5-------->1 : 1
5-------->2 : 1
5-------->3 : 1
5-------->4 : 1
Do you want to enter more file(Yes - 1/No - 0)1
Enter the index block: 4
4 index is already allocated
Enter the index block: 6
Enter no of blocks needed and no of files for the index 6 on the disk :
2
7 8
Allocated
File Indexed
6-------->7 : 1
6-------->8 : 1
Do you want to enter more file(Yes - 1/No - 0)
Case 2:
Enter the index block: 4
Enter no of blocks needed and no of files for the index 4 on the disk :
3
1 2 3
Allocated
File Indexed
4-------->1 : 1
4-------->2 : 1
4-------->3 : 1
Do you want to enter more file(Yes - 1/No - 0)
Linked File Allocation
Linked File Allocation is a Non-contiguous memory allocation method where the file is stored in
random memory blocks and each block contains the pointer (or address) of the next memory block
as in a linked list. The starting memory block of each file is maintained in a directory and the rest
of the file can be traced from that starting block.
Linked File Allocation Algorithm
STEP 1: Start the program.
STEP 2: Gather information about the number of files.
STEP 3: Allocate random locations to the files.
STEP 4: Check if the location that is selected is free or not.
STEP 5: If the location is free set the count=0 a location is allocated set the count = 1.
STEP 6: Print the file number, length, and the block allocated.
STEP 7: Gather information if more files have to be stored.
STEP 8: If yes, then go to STEP 2.
STEP 9: If no, Stop the program.
Sample Code
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int f[50], p,i, st, len, j, c, k, a;
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks already allocated: ");
scanf("%d",&p);
printf("Enter blocks already allocated: ");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
x: printf("Enter index starting block and length: ");
scanf("%d%d", &st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(st+k);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("%d-------->%dn",j,f[j]);
}
else
{
printf("%d Block is already allocated n",j);
k++;
}
}
}
else
printf("%d starting block is already allocated n",st);
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}
Sample Output
Case 1:
Enter how many blocks already allocated: 3
Enter blocks already allocated: 1 3 5
Enter index starting block and length: 2 2
2-------->1
3 Block is already allocated
4-------->1
Do you want to enter more file(Yes - 1/No - 0)
Case 2:
Enter how many blocks already allocated: 6
Enter blocks already allocated: 2 4 6 8 10 12
Enter index starting block and length: 3 10
3-------->1
4 Block is already allocated
5-------->1
6 Block is already allocated
7-------->1
8 Block is already allocated
9-------->1
10 Block is already allocated
11-------->1
12 Block is already allocated
13-------->1
14-------->1
15-------->1
16-------->1
17-------->1
Do you want to enter more file(Yes - 1/No - 0)1
Enter index starting block and length: 5 1
5 starting block is already allocated
Do you want to enter more file(Yes - 1/No - 0)1
Enter index starting block and length: 18 2
18-------->1
19-------->1
Do you want to enter more file(Yes - 1/No - 0)

Weitere ähnliche Inhalte

Was ist angesagt?

basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
Data file handling
Data file handlingData file handling
Data file handling
TAlha MAlik
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 

Was ist angesagt? (20)

File handling in c
File handling in cFile handling in c
File handling in c
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
file handling, dynamic memory allocation
file handling, dynamic memory allocationfile handling, dynamic memory allocation
file handling, dynamic memory allocation
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
Data file handling
Data file handlingData file handling
Data file handling
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Python-files
Python-filesPython-files
Python-files
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
File management
File managementFile management
File management
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
(150124) #fitalk advanced $usn jrnl forensics (english)
(150124) #fitalk   advanced $usn jrnl forensics (english)(150124) #fitalk   advanced $usn jrnl forensics (english)
(150124) #fitalk advanced $usn jrnl forensics (english)
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
Files nts
Files ntsFiles nts
Files nts
 
File in C language
File in C languageFile in C language
File in C language
 

Ähnlich wie File organization

There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docx
susannr
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docx
susannr
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docx
susannr
 
C++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docxC++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docx
marions12
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
theodorelove43763
 

Ähnlich wie File organization (20)

There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docx
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docx
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docx
 
A SURVEY ON MULTIMEDIA FILE CARVING
A SURVEY ON MULTIMEDIA FILE CARVINGA SURVEY ON MULTIMEDIA FILE CARVING
A SURVEY ON MULTIMEDIA FILE CARVING
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
 
data hiding techniques.ppt
data hiding techniques.pptdata hiding techniques.ppt
data hiding techniques.ppt
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Lab 1 Essay
Lab 1 EssayLab 1 Essay
Lab 1 Essay
 
Python File functions
Python File functionsPython File functions
Python File functions
 
How to design a file system
How to design a file systemHow to design a file system
How to design a file system
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
Processing files sequentially in mule
Processing files sequentially in muleProcessing files sequentially in mule
Processing files sequentially in mule
 
C++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docxC++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docx
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.js
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
File Management System in Shell Script.pptx
File Management System in Shell Script.pptxFile Management System in Shell Script.pptx
File Management System in Shell Script.pptx
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 

Mehr von A. S. M. Shafi

Mehr von A. S. M. Shafi (20)

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer Graphics
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Projection
ProjectionProjection
Projection
 
2D Transformation
2D Transformation2D Transformation
2D Transformation
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithm
 
Fragmentation
FragmentationFragmentation
Fragmentation
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority scheduling
 
Fcfs and sjf
Fcfs and sjfFcfs and sjf
Fcfs and sjf
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
1D Array
1D Array1D Array
1D Array
 
2D array
2D array2D array
2D array
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Queue
QueueQueue
Queue
 
Searching
SearchingSearching
Searching
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problem
 
Quick sort
Quick sortQuick sort
Quick sort
 
N queens problem
N queens problemN queens problem
N queens problem
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Pharmaceutical Biotechnology VI semester.pdf
Pharmaceutical Biotechnology VI semester.pdfPharmaceutical Biotechnology VI semester.pdf
Pharmaceutical Biotechnology VI semester.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

File organization

  • 1. File Organization Files are normally stored on the disks. So the main problem is how to allocate space to those files. So that disk space is utilized effectively and files can be accessed quickly. Three major strategies of allocating disc space are in wide use. Sequential, indexed and linked. Sequential Allocation In this allocation strategy, each file occupies a set of contiguously blocks on the disk. This strategy is best suited. For sequential files, the file allocation table consists of a single entry for each file. It shows the filenames, starting block of the file and size of the file. The main problem with this strategy is, it is difficult to find the contiguous free blocks in the disk and some free blocks could happen between two files. Sequential File Allocation Algorithm STEP 1: Start the program. STEP 2: Gather information about the number of files. STEP 3: Gather the memory requirement of each file. STEP 4: Allocate the memory to the file in a sequential manner. STEP 5: Select any random location from the available location. STEP 6: Check if the location that is selected is free or not. STEP 7: If the location is allocated set the count = 1. STEP 8: Print the file number, length, and the block allocated. STEP 9: Gather information if more files have to be stored. STEP 10: If yes, then go to STEP 2. STEP 11: If no, Stop the program
  • 2. Sample Code #include <stdio.h> #include<conio.h> void main() { int f[50], i, st, len, j, c, k, count = 0; for(i=0;i<50;i++) f[i]=0; printf("Files Allocated are : n"); x:count=0; printf("Enter starting block and length of files:"); scanf("%d%d",&st,&len); for(k=st;k<(st+len);k++) if(f[k]==0) count++; if(len==count) { for(j=st;j<(st+len);j++) if(f[j]==0) { f[j]=1; printf("%dt%dn",j,f[j]); } if(j!=(st+len-1)) printf("The file is allocated to diskn"); } else printf("The file is not allocated n");
  • 3. printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1) goto x; else exit(0); getch(); } Sample Output Case 1: Files Allocated are : Enter starting block and length of files:14 3 14 1 15 1 16 1 The file is allocated to disk Do you want to enter more file(Yes - 1/No - 0)1 Enter starting block and length of files:14 1 The file is not allocated Do you want to enter more file(Yes - 1/No - 0)1 Enter starting block and length of files:14 4 The file is not allocated Do you want to enter more file(Yes - 1/No - 0) Case 2: Files Allocated are : Enter starting block and length of files:17 4 17 1 18 1
  • 4. 19 1 20 1 The file is allocated to disk Do you want to enter more file(Yes - 1/No - 0)1 Enter starting block and length of files:21 3 21 1 22 1 23 1 The file is allocated to disk Do you want to enter more file(Yes - 1/No - 0)1 Enter starting block and length of files:19 4 The file is not allocated Do you want to enter more file(Yes - 1/No - 0)1 Enter starting block and length of files:25 5 25 1 26 1 27 1 28 1 29 1 The file is allocated to disk Do you want to enter more file(Yes - 1/No - 0)
  • 5. Indexed File Allocation The Indexed File Allocation stores the file in the blocks of memory, each block of memory has an address and the address of every file block is maintained in a separate index block. These index blocks point the file allocation system to the memory blocks which actually contains the file. Indexed File Allocation Algorithm STEP 1: Start the program. STEP 2: Get information about the number of files. STEP 3: Get the memory requirement of each file. STEP 4: Allocate the memory to the file by selecting random locations. STEP 5: Check if the location that is selected is free or not. STEP 6: If the location is allocated set the count = 1, and if free set count = 0. STEP 7: Print the file number, length, and the block allocated. STEP 8: Gather information if more files have to be stored. STEP 9: If yes, then go to STEP 2. STEP 10: If no, Stop the program.
  • 6. Sample Code #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], index[50],i, n, st, len, j, c, k, ind,count=0; for(i=0;i<50;i++) f[i]=0; x:printf("Enter the index block: "); scanf("%d",&ind); if(f[ind]!=1) { printf("Enter no of blocks needed and no of files for the index %d on the disk : n",ind); scanf("%d",&n); } else { printf("%d index is already allocated n",ind); goto x; } y: count=0; for(i=0;i<n;i++)
  • 7. { scanf("%d", &index[i]); if(f[index[i]]==0) count++; } if(count==n) { for(j=0;j<n;j++) f[index[j]]=1; printf("Allocatedn"); printf("File Indexedn"); for(k=0;k<n;k++) printf("%d-------->%d : %dn",ind,index[k],f[index[k]]); } else { printf("File in the index is already allocated n"); printf("Enter another file indexed"); goto y; } printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1)
  • 8. goto x; else exit(0); getch(); } Sample Output Case 1: Enter the index block: 5 Enter no of blocks needed and no of files for the index 5 on the disk : 4 1 2 3 4 Allocated File Indexed 5-------->1 : 1 5-------->2 : 1 5-------->3 : 1 5-------->4 : 1 Do you want to enter more file(Yes - 1/No - 0)1 Enter the index block: 4 4 index is already allocated Enter the index block: 6 Enter no of blocks needed and no of files for the index 6 on the disk : 2 7 8
  • 9. Allocated File Indexed 6-------->7 : 1 6-------->8 : 1 Do you want to enter more file(Yes - 1/No - 0) Case 2: Enter the index block: 4 Enter no of blocks needed and no of files for the index 4 on the disk : 3 1 2 3 Allocated File Indexed 4-------->1 : 1 4-------->2 : 1 4-------->3 : 1 Do you want to enter more file(Yes - 1/No - 0)
  • 10. Linked File Allocation Linked File Allocation is a Non-contiguous memory allocation method where the file is stored in random memory blocks and each block contains the pointer (or address) of the next memory block as in a linked list. The starting memory block of each file is maintained in a directory and the rest of the file can be traced from that starting block. Linked File Allocation Algorithm STEP 1: Start the program. STEP 2: Gather information about the number of files. STEP 3: Allocate random locations to the files. STEP 4: Check if the location that is selected is free or not. STEP 5: If the location is free set the count=0 a location is allocated set the count = 1. STEP 6: Print the file number, length, and the block allocated. STEP 7: Gather information if more files have to be stored. STEP 8: If yes, then go to STEP 2. STEP 9: If no, Stop the program.
  • 11. Sample Code #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], p,i, st, len, j, c, k, a; for(i=0;i<50;i++) f[i]=0; printf("Enter how many blocks already allocated: "); scanf("%d",&p); printf("Enter blocks already allocated: "); for(i=0;i<p;i++) { scanf("%d",&a); f[a]=1; } x: printf("Enter index starting block and length: "); scanf("%d%d", &st,&len); k=len; if(f[st]==0) { for(j=st;j<(st+k);j++)
  • 12. { if(f[j]==0) { f[j]=1; printf("%d-------->%dn",j,f[j]); } else { printf("%d Block is already allocated n",j); k++; } } } else printf("%d starting block is already allocated n",st); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1) goto x; else exit(0); getch(); }
  • 13. Sample Output Case 1: Enter how many blocks already allocated: 3 Enter blocks already allocated: 1 3 5 Enter index starting block and length: 2 2 2-------->1 3 Block is already allocated 4-------->1 Do you want to enter more file(Yes - 1/No - 0) Case 2: Enter how many blocks already allocated: 6 Enter blocks already allocated: 2 4 6 8 10 12 Enter index starting block and length: 3 10 3-------->1 4 Block is already allocated 5-------->1 6 Block is already allocated 7-------->1 8 Block is already allocated 9-------->1 10 Block is already allocated 11-------->1 12 Block is already allocated
  • 14. 13-------->1 14-------->1 15-------->1 16-------->1 17-------->1 Do you want to enter more file(Yes - 1/No - 0)1 Enter index starting block and length: 5 1 5 starting block is already allocated Do you want to enter more file(Yes - 1/No - 0)1 Enter index starting block and length: 18 2 18-------->1 19-------->1 Do you want to enter more file(Yes - 1/No - 0)