Program to implement file allocation using chained method

Concept: The most common form of file structure is the sequential file in this type of file, a fixed format is used for records. All records (of the system) have the same length, consisting of the same number of fixed length fields in a particular order because the length and position of each field are known, only the values of fields need to be stored, the field name and length for each field are attributes of the file structure.

ALGORITHM:

Step 1: Start

Step 2: Get the number offiles.

Step 3: Get the memory requirement of each file.

Step 4: Allocate the required locations to each in sequential order

a). Randomly select a location from available location s1= random(100);
a) Check whether the required locations are free from the selected location. if(b[s1].flag==0)
{
for(j=s1;j<s1+p[i];j++)
{
if((b[j].flag)==0) count++;

}

if(count==p[i])

break;

b) Allocate and set flag=1 to the allocated locations.

for(s=s1;s<(s1+p[i]);s++) {
k[i][j]=s;
j=j+1;
b[s].bno=s;
b[s].flag=1;

}

Step 5: Print the results file no, length ,Blocks allocated.

Step 6: Stop

				
					#include<stdio.h> 
main() 
{
int f[50],i,st,j,len,c,k;
clrscr(); 
for(i=0;i<50;i++) 
f[i]=0; 
X: printf("\n Enter the starting block & length of file"); 
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++) 
if(f[j]==0) 
{
f[j]=1;
printf("\n%d->%d",j,f[j]); 
} 
else 
{ 
printf("Block already allocated"); 
break; 
}
if(j==(st+len)) 
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)"); 
scanf("%d",&c); 
if(c==1) 
goto X;
else 
exit();
getch();
}
				
			
OUTPUT:
Enter the starting block & length of file 4 10
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
The file is allocated to disk.

Leave a Reply