summaryrefslogtreecommitdiffstats
path: root/partition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'partition.cpp')
-rw-r--r--partition.cpp96
1 files changed, 95 insertions, 1 deletions
diff --git a/partition.cpp b/partition.cpp
index e554ac7eb..e92fccfd2 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -1105,7 +1105,7 @@ bool TWPartition::Wipe(string New_File_System) {
else
unlink("/.layout_version");
- if (Has_Data_Media) {
+ if (Has_Data_Media && Current_File_System == New_File_System) {
wiped = Wipe_Data_Without_Wiping_Media();
} else {
@@ -1185,6 +1185,100 @@ bool TWPartition::Wipe_AndSec(void) {
return true;
}
+bool TWPartition::Can_Repair() {
+ if (Current_File_System == "vfat" && TWFunc::Path_Exists("/sbin/dosfsck"))
+ return true;
+ else if ((Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") && TWFunc::Path_Exists("/sbin/e2fsck"))
+ return true;
+ else if (Current_File_System == "exfat" && TWFunc::Path_Exists("/sbin/fsck.exfat"))
+ return true;
+ else if (Current_File_System == "f2fs" && TWFunc::Path_Exists("/sbin/fsck.f2fs"))
+ return true;
+ return false;
+}
+
+bool TWPartition::Repair() {
+ string command;
+
+ if (Current_File_System == "vfat") {
+ if (!TWFunc::Path_Exists("/sbin/dosfsck")) {
+ gui_print("dosfsck does not exist! Cannot repair!\n");
+ return false;
+ }
+ if (!UnMount(true))
+ return false;
+ gui_print("Repairing %s using dosfsck...\n", Display_Name.c_str());
+ Find_Actual_Block_Device();
+ command = "/sbin/dosfsck -y " + Actual_Block_Device;
+ LOGINFO("Repair command: %s\n", command.c_str());
+ if (TWFunc::Exec_Cmd(command) == 0) {
+ gui_print("Done.\n");
+ return true;
+ } else {
+ LOGERR("Unable to repair '%s'.\n", Mount_Point.c_str());
+ return false;
+ }
+ }
+ if (Current_File_System == "ext2" || Current_File_System == "ext3" || Current_File_System == "ext4") {
+ if (!TWFunc::Path_Exists("/sbin/e2fsck")) {
+ gui_print("e2fsck does not exist! Cannot repair!\n");
+ return false;
+ }
+ if (!UnMount(true))
+ return false;
+ gui_print("Repairing %s using e2fsck...\n", Display_Name.c_str());
+ Find_Actual_Block_Device();
+ command = "/sbin/e2fsck -p " + Actual_Block_Device;
+ LOGINFO("Repair command: %s\n", command.c_str());
+ if (TWFunc::Exec_Cmd(command) == 0) {
+ gui_print("Done.\n");
+ return true;
+ } else {
+ LOGERR("Unable to repair '%s'.\n", Mount_Point.c_str());
+ return false;
+ }
+ }
+ if (Current_File_System == "exfat") {
+ if (!TWFunc::Path_Exists("/sbin/fsck.exfat")) {
+ gui_print("fsck.exfat does not exist! Cannot repair!\n");
+ return false;
+ }
+ if (!UnMount(true))
+ return false;
+ gui_print("Repairing %s using fsck.exfat...\n", Display_Name.c_str());
+ Find_Actual_Block_Device();
+ command = "/sbin/fsck.exfat " + Actual_Block_Device;
+ LOGINFO("Repair command: %s\n", command.c_str());
+ if (TWFunc::Exec_Cmd(command) == 0) {
+ gui_print("Done.\n");
+ return true;
+ } else {
+ LOGERR("Unable to repair '%s'.\n", Mount_Point.c_str());
+ return false;
+ }
+ }
+ if (Current_File_System == "f2fs") {
+ if (!TWFunc::Path_Exists("/sbin/fsck.f2fs")) {
+ gui_print("fsck.f2fs does not exist! Cannot repair!\n");
+ return false;
+ }
+ if (!UnMount(true))
+ return false;
+ gui_print("Repairing %s using fsck.f2fs...\n", Display_Name.c_str());
+ Find_Actual_Block_Device();
+ command = "/sbin/fsck.f2fs " + Actual_Block_Device;
+ LOGINFO("Repair command: %s\n", command.c_str());
+ if (TWFunc::Exec_Cmd(command) == 0) {
+ gui_print("Done.\n");
+ return true;
+ } else {
+ LOGERR("Unable to repair '%s'.\n", Mount_Point.c_str());
+ return false;
+ }
+ }
+ return false;
+}
+
bool TWPartition::Backup(string backup_folder) {
if (Backup_Method == FILES)
return Backup_Tar(backup_folder);