Ex 14

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

EXP.

NO :
FILE ALLOCATION STRATEGIES

DATE :

A. FILE ALLOCATION TECHNIQUE-CONTIGUOUS

AIM :

To implement file allocation on free disk space in a contiguous manner.

ALGORITHM :

1. Start the program


2. Get the no of files,no of blocks occufied by files and starting block of files
3. Display file name, start block and length
4. Display blocks occupied by the no of files
5. Stop program

PROGRAM :

#include<stdio.h>

main()

int n,i,j,b[20],sb[20],t[20],x,c[20][20];

printf("Enter no.of files:");

scanf("%d",&n);

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

printf("Enter no. of blocks occupied by file%d",i+1);

scanf("%d",&b[i]);

printf("Enter the starting block of file%d",i+1);

scanf("%d",&sb[i]);

t[i]=sb[i];

for(j=0;j<b[i];j++)

KGISL INSTITUTE OF TECHNOLOGY 711722104062


c[i][j]=sb[i]++;

printf("Filename\tStart block\tlength\n");

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

printf("%d\t %d \t%d\n",i+1,t[i],b[i]);

printf("blocks occupied are:\n");

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

{ printf("file no %d",i+1);

for(j=0;j<b[i];j++)

printf("\t%d",c[i][j]);

printf("\n");

OUTPUT :

RESULT :

Thus contiguous allocation is done for files with the available free blocks.

KGISL INSTITUTE OF TECHNOLOGY 711722104062


B. FILE ALLOCATION TECHNIQUE – LINKED

AIM :

To implement file allocation on free disk space in a linked file memory allocation manner.

ALGORITHM :

1. Start the program.


2. Define the structure to get file name,starting block,size of the file and actual block
numbers
3. Get the number of files,file name,starting block,number of blocks and actual block
numbers
4. Display the file name,starting block and size of the file
5. Display block numbers occupied by file as linked blocks
6. Stop the program.

PROGRAM :

#include<stdio.h>

struct file

char fname[10];

int start,size,block[10];

}f[10];

main()

int i,j,n;

printf("Enter no. of files:");

scanf("%d",&n);

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

printf("Enter file name:");

scanf("%s",&f[i].fname);

printf("Enter starting block:");

KGISL INSTITUTE OF TECHNOLOGY 711722104062


scanf("%d",&f[i].start);

f[i].block[0]=f[i].start;

printf("Enter no.of blocks:");

scanf("%d",&f[i].size);

printf("Enter block numbers:");

for(j=1;j<=f[i].size;j++)

scanf("%d",&f[i].block[j]);}}

printf("File\tstart\tsize\tblock\n");

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

printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);

for(j=0;j<f[i].size;j++)

printf("%d--->",f[i].block[j]);

printf("%d",f[i].block[j]);

printf("\n");

} }

OUTPUT :

RESULT :

Thus Linked file allocation is done for files with the available free blocks.

KGISL INSTITUTE OF TECHNOLOGY 711722104062


C. FILE ALLOCATION TECHNIQUE - INDEXED

AIM :

To implement file allocation on free disk space using indexed file allocation method

ALGORITHM :

1. Start the program.


2. Get the number of files,index block and block numbers occupied by each file.
3. Display the file name,index and length of the file
4. Display index number and block numbers occupied by files
5. Stop the program.
.

PROGRAM:

#include<stdio.h>

main()

int n,m[20],i,j,ib[20],b[20][20];

printf("Enter no. of files:");

scanf("%d",&n);

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

{ printf("Enter index block :",i+1);

scanf("%d",&ib[i]);

printf("Enter blocks occupied by file%d:",i+1);

scanf("%d",&m[i]);

printf("enter blocks of file%d:",i+1);

for(j=0;j<m[i];j++)

scanf("%d",&b[i][j]);

} printf("\nFile\t index\tlength\n");

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

printf("%d\t%d\t%d\n",i+1,ib[i],m[i]);

printf("blocks occupied are:\n");

KGISL INSTITUTE OF TECHNOLOGY 711722104062


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

{ printf("fileno%d",i+1);

for(j=0;j<m[i];j++)

printf("\t%d--->%d\n",ib[i],b[i][j]);

printf("\n");

OUTPUT :

RESULT:

Thus indexed file allocation is done for files with the available free blocks.

KGISL INSTITUTE OF TECHNOLOGY 711722104062

You might also like