Sunday, November 25, 2012

File allocation strategies ---- Sequential file Allocation

/* 2.simulate all File allocation strategies
    a. Sequential file Allocation               */


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int st[20],b[20],b1[20],ch,i,j,n,blocks[20][20],sz[20];
    char F[20][20],S[20];
    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 Starting block of %d::",i+1);
        scanf("%d",&st[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];
    for(i=0;i<n;i++)
    {
        for(j=0;j<b1[i];j++)
            blocks[i][j]=st[i]+j;
    }
    do
    {
        printf("\nEnter the Filename ::");
        scanf("%s",S);
        for(i=0;i<n;i++)
        {
            if(strcmp(S,F[i])==0)
            {
                printf("\nFname\tStart\tNblocks\tBlocks\n");
                printf("\n---------------------------------------------\n");
                printf("\n%s\t%d\t%d\t",F[i],st[i],b1[i]);
                for(j=0;j<b1[i];j++)
                    printf("%d->",blocks[i][j]);
            }

        }
        printf("\n---------------------------------------------\n");
        printf("\nDo U want to continue ::(Y:n)");
        scanf("%d",&ch);
        if(ch!=1)
            break;
    }while(1);
}
/*Input and Output;-

 Enter no. of Files ::2
 Enter file 1 name ::x.c
 Enter file1 size(in kb)::4
 Enter Starting block of 1::100
 Enter blocksize of File1(in bytes)::512
 Enter file 2 name ::y.c
 Enter file2 size(in kb)::2
 Enter Starting block of 2::500
 Enter blocksize of File2(in bytes)::256
    Enter the Filename ::y.c

Fname   Start   Nblocks Blocks
---------------------------------------------
y.c     500     8       500->501->502->503->504->505->506->507->
---------------------------------------------
Do U want to continue ::(Y:n) n             */

No comments:

Post a Comment