partition: Perform BLKDISCARD on the block device before flashing image
Change-Id: Ifb13d47693edfc96369053199ac0b5d81910f104
diff --git a/partition.cpp b/partition.cpp
index e330aa0..18528f1 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -1769,6 +1769,13 @@
return ret;
}
+bool TWPartition::BlkDiscard() {
+ string cmd;
+ LOGINFO("Perform BLKDISCARD on block device %s\n", Actual_Block_Device.c_str());
+ cmd = "/system/bin/toybox blkdiscard " + Actual_Block_Device;
+ return (TWFunc::Exec_Cmd(cmd) == 0);
+}
+
bool TWPartition::Wipe(string New_File_System) {
bool wiped = false, update_crypt = false, recreate_media = true;
int check;
@@ -2785,6 +2792,9 @@
}
}
else {
+#ifdef TW_ENABLE_BLKDISCARD
+ BlkDiscard();
+#endif
destfn = Actual_Block_Device;
if (part_settings->adbbackup) {
srcfn = TW_ADB_RESTORE;
@@ -3326,6 +3336,10 @@
bool TWPartition::Flash_Sparse_Image(const string& Filename) {
string Command;
+#ifdef TW_ENABLE_BLKDISCARD
+ BlkDiscard();
+#endif
+
gui_msg(Msg("flashing=Flashing {1}...")(Display_Name));
Command = "simg2img '" + Filename + "' '" + Actual_Block_Device + "'";