0% found this document useful (0 votes)
480 views6 pages

12 File Allocation

The document describes three C programs that implement different file allocation methods: 1. The first program implements sequential file allocation by allocating blocks sequentially using first-fit, best-fit, and worst-fit algorithms. 2. The second program implements indexed file allocation by linking files to index blocks which then link to child index blocks. 3. The third program implements linked file allocation by linking the starting block of a file to subsequent free blocks in a linked list structure.

Uploaded by

Vasantha Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
480 views6 pages

12 File Allocation

The document describes three C programs that implement different file allocation methods: 1. The first program implements sequential file allocation by allocating blocks sequentially using first-fit, best-fit, and worst-fit algorithms. 2. The second program implements indexed file allocation by linking files to index blocks which then link to child index blocks. 3. The third program implements linked file allocation by linking the starting block of a file to subsequent free blocks in a linked list structure.

Uploaded by

Vasantha Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Exp no:12(a) SEQUENTIAL FILE ALLOCATION

AIM: Write a C Program to implement Sequential File Allocation method.

ALGORITHM:

Step 1: Start the program.


Step 2: Get the number of memory partition and their sizes.
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches all the entire memory block until a hole which is
big enough is encountered. It allocates that memory block for the requesting
process.
Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can
be allocated to requesting process and allocates if.
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and
allocates it to the process.
Step 7: Analyses all the three memory management techniques and display the best
algorithm which utilizes the memory resources effectively and efficiently.
Step 8: Stop the program.
PROGRAM:

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,j,b[20],sb[20],t[20],x,c[20][20];
clrscr();
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++)
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("Enter file name:");
scanf("%d",&x);
printf("File name is:%d",x);
printf("length is:%d",b[x-1]);
printf("blocks occupied:");
for(i=0;i<b[x-1];i++)
printf("%4d",c[x-1][i]);
getch();
}

OUTPUT:

Enter no.of files: 2


Enter no. of blocks occupied by file1 4
Enter the starting block of file1 2
Enter no. of blocks occupied by file2 10
Enter the starting block of file2 5
Filename Start block length
1 2 4
2 5 10
Enter file name: rajesh
File name is:12803 length is:0blocks occupied

Exp no:12(b) INDEXED FILE ALLOCATION


AIM: To write a C program to implement File Allocation concept using the technique indexed
allocation Technique..
ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,index block.
Step 4: Print the file name index loop.
Step 5:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM CODING:
#include<stdio.h>
void main()
{
char a[10];
int i,ib,cib[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n index block:");
scanf("%d",&ib);
for(i=1;i<=5;i++)
{
printf("\n enter the child of index block %d:",i);
scanf("%d",&cib[i]);
}
printf("\n the list of files\t index block\n");
printf("%s\t\t %d",a,ib);
printf("\n the above file utiltization index block of child blocks followin\t");
printf("\n");
for(i=1;i<=5;i++)
{
printf("%d\t\t",cib[i]);
}
printf("\n");
}
RESULT: Thus the program was executed successfully.
OUTPUT: Enter the name:Testing
Index block:19
Enter the child of index block 1:9
Enter the child of index block 2:16
Enter the child of index block 3:1
Enter the child of index block 4:10
Enter the child of index block 5:25
The list of files index block
Testing 19

The above file utilization index block of child blocks following: 9 16 1 10 25


Exp no:12(c) LINKED FILE ALLOCATION

Aim:
To write a C program to implement File Allocation concept using the technique Linked
List Technique..
ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,starting block ending block.
Step 4: Print the free block using loop.
Step 5:‟for‟ loop is created to print the file utilization of linked type of entered type .
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM CODING
#include<stdio.h>
void main()
{
char a[10];
int i,sb,eb,fb1[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n Enter the starting block:");
scanf("%d",&sb);
printf("Enter the ending Block:");
scanf("%d",&eb);
for(i=0;i<5;i++)
{
printf("Enter the free block %d",i+1);
scanf("%d",&fb1[i]);
}
printf("\n File name \t Starting block \t Ending block \n");
printf("%s \t\t %d\t\t %d",a,sb,eb);
printf("\n %s File Utilization of Linked type of following blocks:",a);
printf("\n %d->",sb);
for(i=0;i<5;i++)
{
printf("%d->",fb1[i]);
}
printf("%d\n",eb);
}
RESULT: Thus the program was executed successfully.

OUTPUT:
Enter the filename:binary
Enter the starting block:19
Enter the ending block:25
Enter the free block:1:12
Enter the free block:2:34
Enter the free block:3:21
Enter the free block:4:18
Enter the free block:5:35
File name starting block ending block
Binary 19 25

Binary file utilization of linked type of the following blocks:


19123421183525

You might also like