summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2019-03-22 14:18:21 +0100
committerEthan Yonker <dees_troy@teamw.in>2019-03-22 14:18:24 +0100
commit7e941586844e514d296dd755972902dd64a4c8ba (patch)
tree0e512dab2b10d0ab3bf897b5815a59f607ffe9dc
parentFix the long broken format function (diff)
downloadandroid_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar.gz
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar.bz2
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar.lz
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar.xz
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.tar.zst
android_bootable_recovery-7e941586844e514d296dd755972902dd64a4c8ba.zip
-rw-r--r--partition.cpp44
-rwxr-xr-xtwrp-functions.cpp12
-rwxr-xr-xtwrp-functions.hpp4
3 files changed, 45 insertions, 15 deletions
diff --git a/partition.cpp b/partition.cpp
index b421598b8..c278fa9fe 100644
--- a/partition.cpp
+++ b/partition.cpp
@@ -2275,17 +2275,45 @@ bool TWPartition::Wipe_F2FS() {
NeedPreserveFooter = false;
}
- unsigned long long dev_sz = TWFunc::IOCTL_Get_Block_Size(Actual_Block_Device.c_str());
- if (!dev_sz)
+ gui_msg(Msg("formatting_using=Formatting {1} using {2}...")(Display_Name)("mkfs.f2fs"));
+ // First determine if we have the old mkfs.f2fs that uses "-r reserved_bytes"
+ // or the new mkfs.f2fs that expects the number of sectors as the optional last argument
+ // Note: some 7.1 trees have the old and some have the new.
+ command = "mkfs.f2fs | grep \"reserved\" > /tmp/f2fsversiontest";
+ TWFunc::Exec_Cmd(command, false); // no help argument so printing usage exits with an error code
+ if (!TWFunc::Path_Exists("/tmp/f2fsversiontest")) {
+ LOGINFO("Error determining mkfs.f2fs version\n");
return false;
+ }
+ if (TWFunc::Get_File_Size("/tmp/f2fsversiontest") <= 0) {
+ LOGINFO("Using newer mkfs.f2fs\n");
+ unsigned long long dev_sz = TWFunc::IOCTL_Get_Block_Size(Actual_Block_Device.c_str());
+ if (!dev_sz)
+ return false;
- if (NeedPreserveFooter)
- Length < 0 ? dev_sz += Length : dev_sz -= CRYPT_FOOTER_OFFSET;
+ if (NeedPreserveFooter)
+ Length < 0 ? dev_sz += Length : dev_sz -= CRYPT_FOOTER_OFFSET;
- gui_msg(Msg("formatting_using=Formatting {1} using {2}...")(Display_Name)("mkfs.f2fs"));
- command = "mkfs.f2fs -d1 -f -O encrypt -O quota -O verity -w 4096 " + Actual_Block_Device + " " + to_string(dev_sz / 4096);
- if (TWFunc::Path_Exists("/sbin/sload.f2fs")) {
- command += " && sload.f2fs -t /data " + Actual_Block_Device;
+ char dev_sz_str[48];
+ sprintf(dev_sz_str, "%llu", (dev_sz / 4096));
+ command = "mkfs.f2fs -d1 -f -O encrypt -O quota -O verity -w 4096 " + Actual_Block_Device + " " + dev_sz_str;
+ if (TWFunc::Path_Exists("/sbin/sload.f2fs")) {
+ command += " && sload.f2fs -t /data " + Actual_Block_Device;
+ }
+ } else {
+ LOGINFO("Using older mkfs.f2fs\n");
+ command = "mkfs.f2fs -t 0";
+ if (NeedPreserveFooter) {
+ // Only use length if we're not decrypted
+ char len[32];
+ int mod_length = Length;
+ if (Length < 0)
+ mod_length *= -1;
+ sprintf(len, "%i", mod_length);
+ command += " -r ";
+ command += len;
+ }
+ command += " " + Actual_Block_Device;
}
LOGINFO("mkfs.f2fs command: %s\n", command.c_str());
if (TWFunc::Exec_Cmd(command) == 0) {
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index ff34828e2..84451b3b6 100755
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -77,7 +77,7 @@ int TWFunc::Exec_Cmd(const string& cmd, string &result) {
return ret;
}
-int TWFunc::Exec_Cmd(const string& cmd) {
+int TWFunc::Exec_Cmd(const string& cmd, bool Show_Errors) {
pid_t pid;
int status;
switch(pid = fork())
@@ -91,7 +91,7 @@ int TWFunc::Exec_Cmd(const string& cmd) {
break;
default:
{
- if (TWFunc::Wait_For_Child(pid, &status, cmd) != 0)
+ if (TWFunc::Wait_For_Child(pid, &status, cmd, Show_Errors) != 0)
return -1;
else
return 0;
@@ -121,18 +121,20 @@ string TWFunc::Get_Path(const string& Path) {
return Path;
}
-int TWFunc::Wait_For_Child(pid_t pid, int *status, string Child_Name) {
+int TWFunc::Wait_For_Child(pid_t pid, int *status, string Child_Name, bool Show_Errors) {
pid_t rc_pid;
rc_pid = waitpid(pid, status, 0);
if (rc_pid > 0) {
if (WIFSIGNALED(*status)) {
- gui_msg(Msg(msg::kError, "pid_signal={1} process ended with signal: {2}")(Child_Name)(WTERMSIG(*status))); // Seg fault or some other non-graceful termination
+ if (Show_Errors)
+ gui_msg(Msg(msg::kError, "pid_signal={1} process ended with signal: {2}")(Child_Name)(WTERMSIG(*status))); // Seg fault or some other non-graceful termination
return -1;
} else if (WEXITSTATUS(*status) == 0) {
LOGINFO("%s process ended with RC=%d\n", Child_Name.c_str(), WEXITSTATUS(*status)); // Success
} else {
- gui_msg(Msg(msg::kError, "pid_error={1} process ended with ERROR: {2}")(Child_Name)(WEXITSTATUS(*status))); // Graceful exit, but there was an error
+ if (Show_Errors)
+ gui_msg(Msg(msg::kError, "pid_error={1} process ended with ERROR: {2}")(Child_Name)(WEXITSTATUS(*status))); // Graceful exit, but there was an error
return -1;
}
} else { // no PID returned
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index efaa460d9..669a9e970 100755
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -56,8 +56,8 @@ public:
static string Get_Filename(const string& Path); // Trims the path off of a filename
static int Exec_Cmd(const string& cmd, string &result); //execute a command and return the result as a string by reference
- static int Exec_Cmd(const string& cmd); //execute a command
- static int Wait_For_Child(pid_t pid, int *status, string Child_Name); // Waits for pid to exit and checks exit status
+ static int Exec_Cmd(const string& cmd, bool Show_Errors = true); //execute a command, displays an error to the GUI if Show_Errors is true, Show_Errors is true by default
+ static int Wait_For_Child(pid_t pid, int *status, string Child_Name, bool Show_Errors = true); // Waits for pid to exit and checks exit status, displays an error to the GUI if Show_Errors is true which is the default
static int Wait_For_Child_Timeout(pid_t pid, int *status, const string& Child_Name, int timeout); // Waits for a pid to exit until the timeout is hit. If timeout is hit, kill the chilld.
static bool Path_Exists(string Path); // Returns true if the path exists
static Archive_Type Get_File_Type(string fn); // Determines file type, 0 for unknown, 1 for gzip, 2 for OAES encrypted