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?

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

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.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
 
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
 

Ä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 (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

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Kürzlich hochgeladen (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

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)