FAT – Contiguous

File Allocation Technique

Contiguous File Allocation


// Program

// Contiguous File Allocation

#include<stdio.h>

struct Dir

{

char Name[10];

int Start, Length;

}

main()

{

struct Dir F[10];

int FA[32], N, st, len, i, j;

for(i=0;i<32;i++)

FA[i]=-1;

printf(“\nCreate directory : \n”);

printf(“\nEnter number of files to be loaded : “);

scanf(“%d”, &N);

for(i=0;i<N;i++)

{

printf(“\nEnter File name : “);

scanf(“%s”,F[i].Name);

printf(“\nEnter starting block : “);

scanf(“%d”,&st);

printf(“\nEnter Length : “);

scanf(“%d”,&len);

for(j=st; j<(st+len); j++)

{

if(FA[j]==-1)

FA[j]=1;

else

{

printf(“\nBlock not empty. Cannot allocate”);

exit();

}

}

F[i].Start=st;

F[i].Length=len;

}

printf (“\n\nFile\tStart\tLength\n”);

for(i=0; i<N; i++)

printf (“\n%s\t%d\t%d”, F[i].Name, F[i].Start, F[i].Length);

printf (“\nDisk allocation\n”);

for(i=0; i<32; i++)

{

if(FA[ i]==-1)

continue;

printf (“%d\t”, i) ;

}

}