-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprintWorkingDir.cpp
36 lines (34 loc) · 1.08 KB
/
printWorkingDir.cpp
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
#include "filesystem.h"
int FileSystem::printWorkingDir() {
/*
objective: to print the current working directory
input: none
effect: the current working directory with respect to root directory
*/
if (currentDir == kReservedSectors) {
std::cout << "/" << std::endl;
} else {
int par = parentDir;
int cur = currentDir;
std::string dirPath = "";
do {
char buf[kSectorSize];
readSector(par, buf);
for (int j = 0; j < kSectorSize; j += 32) {
TypeCastEntry entry;
for (int k = 0; k < 32; ++k) {
entry.str[k] = buf[j+k];
}
if (entry.entry.startsAt == cur) {
cur = par;
par = entry.entry.parent;
std::string temp = entry.entry.name;
dirPath = temp + "/" + dirPath;
break;
}
}
} while (cur != kReservedSectors);
std::cout << "/" + dirPath << std::endl;
}
return 0;
}