FAT – Linked

File Allocation Technique

Linked File Allocation


// Program

// Linked File Allocation

#include<stdio.h>

struct Dir

{

char Name[10] ;

int Start ;

}

main( )

{

struct Dir F[10] ;

int FAT[32], Tmp, N, R1, R, len, i , j ;

clrscr ();

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

FAT[i]=-11;

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 number of blocks : “);

scanf(“%d”,&len);

Tmp=0;

while(1)

{

R=rand( )%32;

if(FAT[R]==-11)

{

if(Tmp==len)

{

F[i].Start=R;

R1=R;

Tmp++;

}

else

{

FAT[R1]=R;

R1=R;

Tmp++;

}

if(Tmp==len)

break;

}

}

FAT[R1]=-1;

}

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

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

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

printf (“\n\n\nDisk allocation\n”);

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

{

if(FAT[ i] !=-11)

printf (“\n%d\t%d”, i, FAT[i]);

}

getch( );

}