/* 2.simulate all File allocation strategies
a. Linked file Allocation Method */
#include<stdio.h>
#include<conio.h>
#include<string.h>
int n;
void main()
{
int b[20],b1[20],i,j,blocks[20][20],sz[20];
char F[20][20],S[20],ch;
int sb[20],eb[20],x;
clrscr();
printf("\n Enter no. of Files ::");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter file %d name ::",i+1);
scanf("%s",&F[i]);
printf("\n Enter file%d size(in kb)::",i+1);
scanf("%d",&sz[i]);
printf("\n Enter blocksize of File%d(in bytes)::",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
b1[i]=(sz[i]*1024)/b[i];
printf("\n Enter Starting block of file%d::",i+1);
scanf("%d",&sb[i]);
printf("\n Enter Ending block of file%d::",i+1);
scanf("%d",&eb[i]);
printf("\nEnter blocks for file%d::\n",i+1);
for(j=0;j<b1[i]-2;)
{
printf("\n Enter the %dblock ::",j+1);
scanf("%d",&x);
if(x>sb[i]&&x<eb[i])
{
blocks[i][j]=x;
j++;
}
else
printf("\n Invalid block::");
}
}
do
{
printf("\nEnter the Filename ::");
scanf("%s",&S);
for(i=0;i<n;i++)
{
if(strcmp(F[i],S)==0)
{
printf("\nFname\tFsize\tBsize\tNblocks\tBlocks\n");
printf("\n---------------------------------------------\n");
printf("\n%s\t%d\t%d\t%d\t",F[i],sz[i],b[i],b1[i]);
printf("%d->",sb[i]);
for(j=0;j<b1[i]-2;j++)
printf("%d->",blocks[i][j]);
printf("%d->",eb[i]);
}
}
printf("\n---------------------------------------------\n");
printf("\nDo U want to continue (Y:n)::");
scanf("%d",&ch);
}while(ch!=0);
}
/*Input and Output;-
Enter file1 size(in kb)::1
Enter blocksize of File1(in bytes)::512
Enter file 2 name ::sudee
Enter file2 size(in kb)::1
Enter blocksize of File2(in bytes)::1024
Enter Starting block of file::1100
Enter Ending block of file::1600
Enter blocks for file1::
Enter the 1block ::102
Enter the 2block ::104
Enter Starting block of file::2200
Enter Ending block of file::2500
Enter blocks for file2::
Enter the 1block ::201
Enter the Filename ::daya
Fname Fsize Bsize Nblocks Blocks
---------------------------------------------
daya 1 512 2 100->102->104->600->
---------------------------------------------
Do U want to continue ::(Y:n)1
Enter the Filename ::sudee
Fname Fsize Bsize Nblocks Blocks
---------------------------------------------
sudee 1 1024 1 200->201->500->
---------------------------------------------
Do U want to continue ::(Y:n)0
*/
No comments:
Post a Comment