FAT – Indexed

File Allocation Technique

Indexed File Allocation


// Program

// Indexed File Allocation

#include<stdio.h>

struct Dir

{

char Name[10] ;

int IndexBlock;

int Ind[8] ;

}

main( )

{

struct Dir F[10] ;

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

clrscr ();

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

scanf(“%d”,&len);

while(1)

{

R=rand( )%32;

if(FA[R]==-1)

{

FA[R] = -10;

F[i].IndexBlock = R;

for(j=0; j<8; j++)

F[i].Ind[j]=-1;

Tmp=0;

break;

}

}

while(1)

{

R=rand( )%32;

if(FA[R]==-1)

{

FA[R]=i ;

F[i].Ind[Tmp]=R;

Tmp++;

if(Tmp==len)

break;

}

}

}

printf (“\n\nFile\t Index Block\n”);

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

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

printf (“\n\n\nIndex Blocks \n”);

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

{

printf (“\nIndex Block : %d\n”, F[i].IndexBlock);

for(j=0; j<8; j++)

printf (“\t%d\n”, F[i].Ind[j]);

}

getch( );

}