-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAFDU.cpp
More file actions
62 lines (48 loc) · 1.49 KB
/
AFDU.cpp
File metadata and controls
62 lines (48 loc) · 1.49 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
#include <iostream>
#include <cstdlib>
#include <string>
#include <unistd.h>
void format_disk(const std::string& device, const std::string& fs_type) {
if (getuid() != 0) {
std::cerr << "❌ Root required, restart with sudo\n";
exit(1);
}
std::cout << "⚠️ WARNING all data on " << device
<< " will be deleted!\n";
std::cout << "Continue? (yes/no): ";
std::string answer;
std::cin >> answer;
if (answer != "yes") {
std::cout << "Canceled.\n";
return;
}
std::string command = "mkfs." + fs_type + " " + device;
std::cout << "Formatting...\n";
int result = system(command.c_str());
if (result == 0) {
std::cout << "✅ Done!\n";
} else {
std::cerr << "❌ Format error\n";
}
}
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cout << "Using: " << argv[0]
<< " <disk> <fs_type>\n";
std::cout << "Example: " << argv[0]
<< " /dev/sdb1 ext4\n";
return 1;
}
std::string device = argv[1];
std::string fs_type = argv[2];
int unmount;
std::cout << "do you really want to unmout disk?\n 1.Yes 2.No\n";
std::cin >> unmount;
if((unmount = 1)){
int unmount = std::system("umount "), device;
}else{
std::cerr << "unmount error, you should unmount disk before formatting\n";
}
format_disk(device, fs_type);
return 0;
}