100% found this document useful (1 vote)
119 views3 pages

Week-7 - Os Lab

The document discusses different file allocation strategies: 1) Sequential allocation allocates files sequentially to the first available blocks. 2) Indexed allocation uses index blocks to point to data blocks. An index is allocated and files are stored in the indexed blocks. 3) Linked allocation uses linked lists to allocate files by linking unused blocks together. Previously allocated blocks and new allocations are linked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
119 views3 pages

Week-7 - Os Lab

The document discusses different file allocation strategies: 1) Sequential allocation allocates files sequentially to the first available blocks. 2) Indexed allocation uses index blocks to point to data blocks. An index is allocated and files are stored in the indexed blocks. 3) Linked allocation uses linked lists to allocate files by linking unused blocks together. Previously allocated blocks and new allocations are linked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

WEEK-7 Do you want to enter more file(Yes - 1/No - 0) : 1

7. Simulate all file allocation strategies Enter starting block and length of files: 14 4
a) Sequential b) Indexed c) Linked The file is not allocated
Do you want to enter more file(Yes - 1/No - 0) : 0
a) Program to simulate sequential file allocation
strategy OUTPUT 2:

#include < stdio.h> Files Allocated are :


#include<conio.h> Enter starting block and length of files: 17 4
void main() 17 1
{ 18 1
int f[50], i, st, len, j, c, k, count = 0; 19 1
clrscr(); 20 1
for(i=0;i<50;i++) The file is allocated to disk
f[i]=0; Do you want to enter more file(Yes - 1/No - 0) : 1
printf("Files Allocated are : \n"); Enter starting block and length of files : 21 3
x: count=0; 21 1
printf(“Enter starting block and length of files: ”); 22 1
scanf("%d%d", &st,&len); 23 1
for(k=st;k<(st+len);k++) The file is allocated to disk
if(f[k]==0) Do you want to enter more file(Yes - 1/No - 0) : 1
count++; Enter starting block and length of files : 19 4
if(len==count) The file is not allocated
{ Do you want to enter more file(Yes - 1/No - 0) : 1
for(j=st;j<(st+len);j++) Enter starting block and length of files: 25 5
if(f[j]==0) 25 1
{ 26 1
f[j]=1; 27 1
printf("%d\t%d\n",j,f[j]); 28 1
} 29 1
if(j!=(st+len-1)) The file is allocated to disk
printf(” The file is allocated to disk\n"); Do you want to enter more file(Yes - 1/No - 0) : 0
}
else =================================
printf(” The file is not allocated \n"); b) Program to simulate indexed file allocation
printf("Do u want to enter more file(Yes - 1/No -0)"); strategy.
scanf("%d", &c);
if(c==1) #include<stdio.h>
goto x; #include<conio.h>
else #include<stdlib.h>
exit(); void main()
getch(); {
} int f[50], index[50],i, n, st, len, j, c, k, indx,
count=0;
OUTPUT 1: clrscr();
for(i=0;i<50;i++)
Files Allocated are : f[i]=0;
Enter starting block and length of files : 14 3 x:printf("Enter the index block: ");
14 1 scanf("%d",&indx);
15 1 if(f[indx]!=1)
16 1 {
The file is allocated to disk printf("Enter no. of blocks needed and no. of files
Do u want to enter more file (Yes - 1/No - 0) : 1 for the index %d on the disk : \n", indx);
Enter starting block and length of files : 14 1 scanf("%d",&n);
The file is not allocated }
else 6-------->7 : 1
{ 6-------->8 : 1
printf("%d index is already allocated \n",indx); Do you want to enter more file(Yes - 1/No - 0) : 0
goto x;
}
y: count=0; OUTPUT 2:
for(i=0;i<n;i++)
{ Enter the index block: 4
Enter no of blocks needed and no of files for the index 4 on the disk :
scanf("%d", &index[i]);
3
if(f[index[i]]==0)
123
count++;
Allocated
}
File Indexed
if(count==n)
4-------->1 : 1
{
4-------->2 : 1
for(j=0;j<n;j++)
4-------->3 : 1
f[index[j]]=1; Do you want to enter more file(Yes - 1/No - 0) : 0
printf("Allocated\n"); =================================
printf("File Indexed\n");
for(k=0;k<n;k++) c) Program to simulate linked file allocation
printf("%d--->%d : %d\n",ind,index[k],f[index[k]]); strategy
}
else #include<stdio.h>
{ #include<conio.h>
printf("File in the index is already allocated \n"); #include<stdlib.h>
printf("Enter another file indexed"); void main()
goto y; {
} int f[50], p,i, st, len, j, c, k, a;
printf("Do uwant to eter more file(Yes - 1/No - 0)"); clrscr();
scanf("%d", &c); for(i=0;i<50;i++)
if(c==1) f[i]=0;
goto x; printf("Enter how many blocks already allocated: ");
else scanf("%d",&p);
exit(0); printf("Enter blocks already allocated: ");
getch(); for(i=0;i<p;i++)
} {
OUTPUT 1: scanf("%d",&a);
Enter the index block: 5 f[a]=1;
Enter no of blocks needed and no of files for the index 5 on the
disk : }
4 x: printf("Enter index starting block and length: ");
1234 scanf("%d%d", &st,&len);
Allocated k=len;
File Indexed if(f[st]==0)
5-------->1 : 1 {
5-------->2 : 1 for(j=st;j<(st+k);j++)
5-------->3 : 1 {
5-------->4 : 1 if(f[j]==0)
Do you want to enter more file(Yes - 1/No - 0) : 1 {
Enter the index block: 4 f[j]=1;
4 index is already allocated printf("%d-------->%d\n",j,f[j]);
Enter the index block: 6 }
Enter no of blocks needed and no of files for the index 6 on the disk : else
2 {
7 8 printf("%d Block is already allocated \n",j);
Allocated k++;
File Indexed }
}
}
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();
}

OUTPUT 1:

Enter how many blocks already allocated: 3


Enter blocks already allocated: 1 3 5
Enter index starting block and length: 2 2
2-------->1
3 Block is already allocated
4-------->1
Do you want to enter mre file(Yes - 1/No - 0) : 0

OUTPUT 2:

Enter blocks already allocated: 2 4 6 8 10 12


Enter index starting block and length: 3 10
3-------->1
4 Block is already allocated
5-------->1
6 Block is already allocated
7-------->1
8 Block is already allocated
9-------->1
10 Block is already allocated
11-------->1
12 Block is already allocated
13-------->1
14-------->1
15-------->1
16-------->1
17-------->1
Do you want to enter more file(Yes - 1/No - 0) : 1
Enter index starting block and length: 5 1
5 starting block is already allocated
Do you want to enter more file(Yes - 1/No - 0) : 1
Enter index starting block and length: 18 2
18-------->1
19-------->1
Do you want to enter more file(Yes - 1/No - 0) : 0

==============================

You might also like