forked from csc-mec/SS_LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequential.c
52 lines (40 loc) · 1.04 KB
/
sequential.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<stdlib.h>
#define disk_size 100
int disk[disk_size];
void sequential(int start, int size)
{
for (int i = start; i < start + size; i++) {
if (i >= disk_size) {
printf("Block %d is out of disk bounds. Allocation Failed\n", i);
return;
}
if (disk[i] != 0) {
printf("Block %d is not free to allocate.\nAllocation Failed\n", i);
return;
}
}
for (int i = start; i < start + size; i++) {
disk[i] = 1;
printf("Block %d has been successfully allocated to file\n", i);
}
}
void main()
{
printf("Sequential File allocation\n");
for(int i=0;i<disk_size;i++)
{
if(i%3 == 0)
{
disk[i] = 1;
}
else
disk[i] = 0;
}
int start,size;
printf("Enter the starting block: ");
scanf("%d",&start);
printf("Enter the size of the file: ");
scanf("%d",&size);
sequential(start,size);
}