SlideShare a Scribd company logo
1 of 14
Download to read offline
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)

More Related Content

What's hot

File handling in c
File handling in cFile handling in c
File handling in caakanksha s
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsingFelix Z. Hoffmann
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5Vikram Nandini
 
file handling, dynamic memory allocation
file handling, dynamic memory allocationfile handling, dynamic memory allocation
file handling, dynamic memory allocationindra Kishor
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Data file handling
Data file handlingData file handling
Data file handlingTAlha MAlik
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
FILES IN C
FILES IN CFILES IN C
FILES IN Cyndaravind
 
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)Abdullah khawar
 
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 CAshim Lamichhane
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
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 CMahendra Yadav
 
(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)INSIGHT FORENSIC
 
Files nts
Files ntsFiles nts
Files ntskalyani66
 

What's hot (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
 

Similar to 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.docxsusannr
 
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 .docxsusannr
 
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.docxsusannr
 
A SURVEY ON MULTIMEDIA FILE CARVING
A SURVEY ON MULTIMEDIA FILE CARVINGA SURVEY ON MULTIMEDIA FILE CARVING
A SURVEY ON MULTIMEDIA FILE CARVINGIJCSES Journal
 
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 handlingRai University
 
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 handlingRai University
 
data hiding techniques.ppt
data hiding techniques.pptdata hiding techniques.ppt
data hiding techniques.pptMuzamil Amin
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in pythonLifna C.S
 
How to design a file system
How to design a file systemHow to design a file system
How to design a file systemNikhil Anurag VN
 
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.docxmarions12
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.jsChris Cowan
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptxVishuSaini22
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2Tanmay Baranwal
 
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.docxtheodorelove43763
 

Similar to 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
 

More from A. S. M. Shafi

2D Transformation in Computer Graphics
2D Transformation in Computer Graphics2D Transformation in Computer Graphics
2D Transformation in Computer GraphicsA. S. M. Shafi
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer GraphicsA. S. M. Shafi
 
2D Transformation
2D Transformation2D Transformation
2D TransformationA. S. M. Shafi
 
Line drawing algorithm
Line drawing algorithmLine drawing algorithm
Line drawing algorithmA. S. M. Shafi
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithmA. S. M. Shafi
 
RR and priority scheduling
RR and priority schedulingRR and priority scheduling
RR and priority schedulingA. S. M. Shafi
 
Applications of stack
Applications of stackApplications of stack
Applications of stackA. S. M. Shafi
 
Sum of subset problem
Sum of subset problemSum of subset problem
Sum of subset problemA. S. M. Shafi
 
N queens problem
N queens problemN queens problem
N queens problemA. S. M. Shafi
 

More from 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
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

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)