-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilesystem.cpp
48 lines (41 loc) · 1.26 KB
/
filesystem.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
37
38
39
40
41
42
43
44
45
46
47
48
#include "filesystem.h"
int main(int argc, char const *argv[]) {
std::string diskTitle;
int diskSizeBytes;
// get disk title
if (argc > 1 && argv[1]) {
diskTitle = argv[1];
} else {
std::cout << "Enter path to disk: ";
std::cin >> diskTitle;
}
// check if disk doesn't exists or is empty
// and if exists, get it's size in bytes
bool alreadyExists = false;
std::fstream fin;
fin.open(diskTitle, std::ios::binary | std::ios::in | std::ios::ate);
diskSizeBytes = fin.tellg();
fin.close();
alreadyExists = (diskSizeBytes > -1);
// get size if not exists
if (!alreadyExists) {
int diskSizeMB;
if (argc > 2) {
std::istringstream iss(argv[2]);
iss >> diskSizeMB;
} else {
std::cout << "Enter disk size in MiB : ";
std::cin >> diskSizeMB;
std::cin.ignore(32767, '\n');
}
diskSizeBytes = kOneMiB_g*diskSizeMB;
}
// initialize disk
FileSystem disk(diskTitle, diskSizeBytes, alreadyExists);
std::cout << "Type `help` to see available commands." << std::endl;
int response = handleInput(disk);
while (response != 1) {
response = handleInput(disk);
}
return 0;
}