From 352b75eddb22f78a1148a37d961c792a7847a557 Mon Sep 17 00:00:00 2001 From: codelover Date: Sun, 29 Mar 2015 02:44:07 +0800 Subject: Backup: fix 'out of memory' issue when backing up large partition as image Restore: improve image restoration speed * Workaround for devices that need to backup partition as image, eg: dm-verity * Increased block size used for partition restore, now using 8M instead of 4K Change-Id: Ie7e7ff3283d71a7e459d76f72caea9f57e71c628 --- partition.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'partition.cpp') diff --git a/partition.cpp b/partition.cpp index 87ba0bc66..b5aacccf6 100644 --- a/partition.cpp +++ b/partition.cpp @@ -1764,12 +1764,21 @@ bool TWPartition::Backup_Tar(string backup_folder, const unsigned long long *ove } bool TWPartition::Backup_DD(string backup_folder) { - char back_name[255], backup_size[32]; - string Full_FileName, Command, DD_BS; + char back_name[255], block_size[32], dd_count[32]; + string Full_FileName, Command, DD_BS, DD_COUNT; int use_compression; + unsigned long long DD_Block_Size, DD_Count; - sprintf(backup_size, "%llu", Backup_Size); - DD_BS = backup_size; + DD_Block_Size = 16 * 1024 * 1024; + while (Backup_Size % DD_Block_Size != 0) DD_Block_Size >>= 1; + + DD_Count = Backup_Size / DD_Block_Size; + + sprintf(dd_count, "%llu", DD_Count); + DD_COUNT = dd_count; + + sprintf(block_size, "%llu", DD_Block_Size); + DD_BS = block_size; TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up"); gui_print("Backing up %s...\n", Display_Name.c_str()); @@ -1779,7 +1788,7 @@ bool TWPartition::Backup_DD(string backup_folder) { Full_FileName = backup_folder + "/" + Backup_FileName; - Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'" + " bs=" + DD_BS + " count=1"; + Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'" + " bs=" + DD_BS + " count=" + DD_COUNT; LOGINFO("Backup command: '%s'\n", Command.c_str()); TWFunc::Exec_Cmd(Command); tw_set_default_metadata(Full_FileName.c_str()); @@ -2102,7 +2111,7 @@ bool TWPartition::Flash_Image_DD(string Filename) { string Command; gui_print("Flashing %s...\n", Display_Name.c_str()); - Command = "dd bs=4096 if='" + Filename + "' of=" + Actual_Block_Device; + Command = "dd bs=8388608 if='" + Filename + "' of=" + Actual_Block_Device; LOGINFO("Flash command: '%s'\n", Command.c_str()); TWFunc::Exec_Cmd(Command); return true; -- cgit v1.2.3