-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindFreeSectors.cpp
More file actions
31 lines (30 loc) · 1.01 KB
/
Copy pathfindFreeSectors.cpp
File metadata and controls
31 lines (30 loc) · 1.01 KB
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
#include "filesystem.h"
int FileSystem::findFreeSectors(int sectorsNeeded, std::vector<int> §orsFree) {
int sectorsFound = 0;
int sector = kReservedSectors + sectorsForDir;
while (sectorsFound < sectorsNeeded) {
int status = getStatus(sector);
if (status == FREE) {
// add sector to usable list
sectorsFree[sectorsFound++] = sector;
} else if (status == NOT_FOUND) {
// look in deleted sectors now
std::cout << "No more FREE sectors." << std::endl;
break;
}
++sector;
}
// look for available sectors that are marked deleted
sector = kReservedSectors + sectorsForDir;
while (sectorsFound < sectorsNeeded) {
int status = getStatus(sector);
if (status < 0) {
sectorsFree[sectorsFound++] = sector;
} else if (status == NOT_FOUND) {
std::cout << "Not enough space in disk!" << std::endl;
return 1;
}
++sector;
}
return 0;
}