Indexed File Allocation


#include<stdio.h>

#include<stdlib.h>

int files[50], indexBlock[50], indBlock, n;
void recurse1(); void recurse2();
void recurse1(){
printf("Enter the index block: "); scanf("%d", &indBlock); if (files[indBlock] != 1){
printf("Enter the number of blocks and the number of files needed for the index %d on the disk:
", indBlock);
scanf("%d", &n);
}
else{
printf("%d is already allocated\n", indBlock);
recurse1();
}
recurse2();
}
void recurse2(){
int ch; int flag
= 0, i,j,k; for (i=0;
i<n; i++){
scanf("%d", &indexBlock[i]);
if (files[indexBlock[i]] == 0)
flag++;
}
if (flag == n){ for (j=0;
j<n; j++){
files[indexBlock[j]] = 1;
}
printf("Allocated\n");
printf("File Indexed\n"); for
(k=0; k<n; k++){
printf("%d ------> %d : %d\n", indBlock, indexBlock[k], files[indexBlock[k]]);

}

}
else{
printf("File in the index is already allocated\n");
printf("Enter another indexed file\n"); recurse2();
}
printf("Do you want to enter more files?\n");
printf("Enter 1 for Yes, Enter 0 for No: ");
scanf("%d", &ch); if (ch == 1) recurse1();
else exit(0); return;
}
int main()
{
int i;
for(i=0;i<50;i++)
files[i]=0;
recurse1();
return 0;
}