0% found this document useful (0 votes)
11 views9 pages

Lab 5

The document outlines a C program that simulates linked file allocation strategies for disk space management. It describes three allocation methods: contiguous, linked, and indexed allocation, with a focus on linked allocation where files are represented as linked lists of disk blocks. The program allows users to input allocated blocks and manage file allocations dynamically, checking for available space and handling user input for further allocations.

Uploaded by

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

Lab 5

The document outlines a C program that simulates linked file allocation strategies for disk space management. It describes three allocation methods: contiguous, linked, and indexed allocation, with a focus on linked allocation where files are represented as linked lists of disk blocks. The program allows users to input allocated blocks and manage file allocations dynamically, checking for available space and handling user input for further allocations.

Uploaded by

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

Develop a C program to simulate the Linked file

allocation strategies.
Allocation methods
Allocation methods address the problem of allocating space to files so that disk
space is utilized effectively, and files can be accessed quickly.

There are 3 types of allocation:


1. Contiguous allocation
2. Linked allocation
3. Indexed allocation
Contiguous
allocation
• Requires that each file occupy a set of
contiguous blocks on the disk
• Contiguous allocation of a file is
defined by the disk address and length
(in block units) of the first block. If the
file is n blocks long and starts at
location b, then it occupies blocks b, b
+ 1, b + 2, ... ,b + n - 1. The directory
entry for each file indicates the address
of the starting block and the length of
the area allocated for this file.
Linked Allocation
• Each file is a linked list of disk blocks: blocks
may be scattered anywhere on the disk.
• The directory contains a pointer to the first and
last blocks of a file.
Indexed Allocation
• Brings all the pointers together into one
location called index block.
• Each file has its own index block, which is an
array of disk-block addresses.
a)Linked file allocation
void main()
{
int f[50], p,i, st, len, j, c, k, a;
for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks already allocated: ");
scanf("%d",&p);
printf("Enter blocks already allocated: ");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
x: printf("Enter index starting block and length: ");
scanf("%d%d", &st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(st+k);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("%d-------->%d\n",j,f[j]);
}
else
{
printf("%d Block is already allocated \n",j);
k++;
}
}
}
else
printf("%d starting block is already allocated \n",st);
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
getch();
}

You might also like