-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (72 loc) · 2.26 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (72 loc) · 2.26 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <string>
#include "snapshot.hpp"
#include "recover.hpp"
#include "delete.hpp"
void list_deleted_files(ext2_filsys fs);
int main(int argc, char** argv) {
if (argc < 4) {
cerr << "Sufficient parameters not found. \nUsage:\n"
<< " ./bitrieve create -dev <device> -p <path> -d <depth>\n"
<< " ./bitrieve recover -dev <device> -p <path> -o <output_path>\n"
<< " ./bitrieve delete -dev <device> -p <path> \n";
return 1;
}
string command = argv[1];
string device, path, output;
unsigned int depth = 0;
for (int i = 2; i < argc; ++i) {
string arg = argv[i];
if (arg == "-dev" && i + 1 < argc) {
device = argv[++i];
}
else if (arg == "-p" && i + 1 < argc) {
path = argv[++i];
if (path.empty()) {
cerr << "Error: -p <path> is required for recovery.\n";
return 1;
}
}
else if (arg == "-d" && i + 1 < argc) {
depth = stoi(argv[++i]);
if (depth < 1 || depth > 10) {
cout << "Depth is invalid. Please enter a value between 1 - 10." << endl;
return 1;
}
}
else if (arg == "-o" && i + 1 < argc) {
output = argv[++i];
}
else {
cerr << "Unknown argument: " << arg << "\n";
return 1;
}
}
if (device.empty()) {
cerr << "Error: device not specified. Use -dev <device> after calling ./bitrieve.\n";
return 1;
}
ext2_filsys fs;
errcode_t errcode = ext2fs_open(device.c_str(), 0, 0, 0, unix_io_manager, &fs);
if (errcode) {
cerr << errcode <<" : Failed to open device: " << device << endl;
return 1;
}
if (command == "create") {
create_snapshot(fs, path, depth, device);
}
else if (command == "recover") {
if (output.empty()) {
cerr << "Error: -o <output_path> is required for recovery.\n";
return 1;
}
recover(path, fs, output, device);
}
else if (command == "delete") {
delete_file(path, fs, device);
}
else {
cerr << "Unknown command: " << command << "\n";
return 1;
}
return 0;
}