From 16c2b318279e2ee22cfa85b3caf07a8a899e98f1 Mon Sep 17 00:00:00 2001 From: Dees_Troy Date: Tue, 15 Jan 2013 16:51:18 +0000 Subject: Add flag for retaining layout version Needed on Sony mint (Xperia T) as the /data/media folder is a separate partition and normal data media wiping is not appropriate for this device but the layout version file needs to be retained for Android 4.2 multi-user. --- partition.cpp | 88 +++++++++++++++++++++++++++++----------------------- partitionmanager.cpp | 2 ++ partitions.hpp | 1 + 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/partition.cpp b/partition.cpp index 076c1cfb1..9122596f3 100644 --- a/partition.cpp +++ b/partition.cpp @@ -90,6 +90,7 @@ TWPartition::TWPartition(void) { Fstab_File_System = ""; Format_Block_Size = 0; Ignore_Blkid = false; + Retain_Layout_Version = false; #ifdef TW_INCLUDE_CRYPTO_SAMSUNG EcryptFS_Password = ""; #endif @@ -353,6 +354,8 @@ bool TWPartition::Process_Flags(string Flags, bool Display_Error) { SubPartition_Of = ptr; } else if (strcmp(ptr, "ignoreblkid") == 0) { Ignore_Blkid = true; + } else if (strcmp(ptr, "retainlayoutversion") == 0) { + Retain_Layout_Version = true; } else if (strlen(ptr) > 8 && strncmp(ptr, "symlink=", 8) == 0) { ptr += 8; Symlink_Path = ptr; @@ -767,6 +770,10 @@ bool TWPartition::UnMount(bool Display_Error) { } bool TWPartition::Wipe(string New_File_System) { + bool wiped = false, update_crypt = false; + int check; + string Layout_Filename = Mount_Point + "/.layout_version"; + if (!Can_Be_Wiped) { LOGE("Partition '%s' cannot be wiped.\n", Mount_Point.c_str()); return false; @@ -782,28 +789,35 @@ bool TWPartition::Wipe(string New_File_System) { } #endif - if (Has_Data_Media) - return Wipe_Data_Without_Wiping_Media(); + if (Retain_Layout_Version && Mount(false) && TWFunc::Path_Exists(Layout_Filename)) + TWFunc::copy_file(Layout_Filename, "/.layout_version", 0600); + else + unlink("/.layout_version"); - int check; - bool wiped = false; - DataManager::GetValue(TW_RM_RF_VAR, check); - - if (check) - wiped = Wipe_RMRF(); - else if (New_File_System == "ext4") - wiped = Wipe_EXT4(); - else if (New_File_System == "ext2" || New_File_System == "ext3") - wiped = Wipe_EXT23(New_File_System); - else if (New_File_System == "vfat") - wiped = Wipe_FAT(); - else if (New_File_System == "exfat") - wiped = Wipe_EXFAT(); - else if (New_File_System == "yaffs2") - wiped = Wipe_MTD(); - else { - LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str()); - return false; + if (Has_Data_Media) { + wiped = Wipe_Data_Without_Wiping_Media(); + } else { + + DataManager::GetValue(TW_RM_RF_VAR, check); + + if (check) + wiped = Wipe_RMRF(); + else if (New_File_System == "ext4") + wiped = Wipe_EXT4(); + else if (New_File_System == "ext2" || New_File_System == "ext3") + wiped = Wipe_EXT23(New_File_System); + else if (New_File_System == "vfat") + wiped = Wipe_FAT(); + else if (New_File_System == "exfat") + wiped = Wipe_EXFAT(); + else if (New_File_System == "yaffs2") + wiped = Wipe_MTD(); + else { + LOGE("Unable to wipe '%s' -- unknown file system '%s'\n", Mount_Point.c_str(), New_File_System.c_str()); + unlink("/.layout_version"); + return false; + } + update_crypt = wiped; } if (wiped) { @@ -815,15 +829,21 @@ bool TWPartition::Wipe(string New_File_System) { } } #endif - Setup_File_System(false); - if (Is_Encrypted && !Is_Decrypted) { - // just wiped an encrypted partition back to its unencrypted state - Is_Encrypted = false; - Is_Decrypted = false; - Decrypted_Block_Device = ""; - if (Mount_Point == "/data") { - DataManager::SetValue(TW_IS_ENCRYPTED, 0); - DataManager::SetValue(TW_IS_DECRYPTED, 0); + + if (TWFunc::Path_Exists("/.layout_version") && Mount(false)) + TWFunc::copy_file("/.layout_version", Layout_Filename, 0600); + + if (update_crypt) { + Setup_File_System(false); + if (Is_Encrypted && !Is_Decrypted) { + // just wiped an encrypted partition back to its unencrypted state + Is_Encrypted = false; + Is_Decrypted = false; + Decrypted_Block_Device = ""; + if (Mount_Point == "/data") { + DataManager::SetValue(TW_IS_ENCRYPTED, 0); + DataManager::SetValue(TW_IS_DECRYPTED, 0); + } } } } @@ -1217,14 +1237,6 @@ bool TWPartition::Wipe_Data_Without_Wiping_Media() { } closedir(d); ui_print("Done.\n"); -#ifdef TW_INCLUDE_CRYPTO_SAMSUNG - if (Mount_Point == "/data" && Mount(false)) { - if (TWFunc::Path_Exists("/tmp/edk_p_sd")) { - Make_Dir("/data/system", true); - TWFunc::copy_file("/tmp/edk_p_sd", "/data/system/edk_p_sd", 0600); - } - } -#endif return true; } ui_print("Dirent failed to open /data, error!\n"); diff --git a/partitionmanager.cpp b/partitionmanager.cpp index 7ebd64f0b..76824a79a 100644 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -163,6 +163,8 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) { printf("Is_Storage "); if (Part->Ignore_Blkid) printf("Ignore_Blkid "); + if (Part->Retain_Layout_Version) + printf("Retain_Layout_Version "); printf("\n"); if (!Part->SubPartition_Of.empty()) printf(" SubPartition_Of: %s\n", Part->SubPartition_Of.c_str()); diff --git a/partitions.hpp b/partitions.hpp index 7660b8b4e..47436b0ea 100644 --- a/partitions.hpp +++ b/partitions.hpp @@ -107,6 +107,7 @@ protected: string Fstab_File_System; // File system from the recovery.fstab int Format_Block_Size; // Block size for formatting bool Ignore_Blkid; // Ignore blkid results due to superblocks lying to us on certain devices / partitions + bool Retain_Layout_Version; // Retains the .layout_version file during a wipe (needed on devices like Sony Xperia T where /data and /data/media are separate partitions) #ifdef TW_INCLUDE_CRYPTO_SAMSUNG string EcryptFS_Password; // Have to store the encryption password to remount #endif -- cgit v1.2.3