From d68e6413e52a1edef535e7d3a5f2f5338295aadd Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 2 Nov 2019 19:22:38 +0800 Subject: [PATCH] partition: add support dm_use_original_path * On some mediatek devices we must use symlinked path instead of the real block device. Needed for decryption on some MTK HW FDE devices. Change-Id: Ib48d745fd442c590aea2baf6d2dbe20aaaef9eec --- partition.cpp | 11 ++++++++++- partitions.hpp | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/partition.cpp b/partition.cpp index 7755b469..d3dfba03 100755 --- a/partition.cpp +++ b/partition.cpp @@ -161,6 +161,7 @@ enum TW_FSTAB_FLAGS { TWFLAG_KEYDIRECTORY, TWFLAG_WRAPPEDKEY, TWFLAG_ADOPTED_MOUNT_DELAY, + TWFLAG_DM_USE_ORIGINAL_PATH, }; /* Flags without a trailing '=' are considered dual format flags and can be @@ -206,6 +207,7 @@ const struct flag_list tw_flags[] = { { "keydirectory=", TWFLAG_KEYDIRECTORY }, { "wrappedkey", TWFLAG_WRAPPEDKEY }, { "adopted_mount_delay=", TWFLAG_ADOPTED_MOUNT_DELAY }, + { "dm_use_original_path", TWFLAG_DM_USE_ORIGINAL_PATH }, { 0, 0 }, }; @@ -271,6 +273,8 @@ TWPartition::TWPartition() { Key_Directory = ""; Is_Super = false; Adopted_Mount_Delay = 0; + Original_Path = ""; + Use_Original_Path = false; } TWPartition::~TWPartition(void) { @@ -670,7 +674,7 @@ void TWPartition::Setup_Data_Partition(bool Display_Error) { } else if (!Mount(false)) { if (Is_Present) { if (Key_Directory.empty()) { - set_partition_data(Actual_Block_Device.c_str(), Crypto_Key_Location.c_str(), + set_partition_data(Use_Original_Path ? Original_Path.c_str() : Actual_Block_Device.c_str(), Crypto_Key_Location.c_str(), Fstab_File_System.c_str()); if (cryptfs_check_footer() == 0) { Is_Encrypted = true; @@ -1015,6 +1019,9 @@ void TWPartition::Apply_TW_Flag(const unsigned flag, const char* str, const bool case TWFLAG_KEYDIRECTORY: Key_Directory = str; break; + case TWFLAG_DM_USE_ORIGINAL_PATH: + Use_Original_Path = true; + break; default: // Should not get here LOGINFO("Flag identified for processing, but later unmatched: %i\n", flag); @@ -1227,6 +1234,8 @@ void TWPartition::Setup_Data_Media() { void TWPartition::Find_Real_Block_Device(string& Block, bool Display_Error) { char device[PATH_MAX], realDevice[PATH_MAX]; + Original_Path = Block; + strcpy(device, Block.c_str()); memset(realDevice, 0, sizeof(realDevice)); while (readlink(device, realDevice, sizeof(realDevice)) > 0) diff --git a/partitions.hpp b/partitions.hpp index 49ebf60d..ef70f371 100755 --- a/partitions.hpp +++ b/partitions.hpp @@ -279,6 +279,9 @@ private: TWExclude backup_exclusions; // Exclusions for file based backups TWExclude wipe_exclusions; // Exclusions for file based wipes (data/media devices only) string Key_Directory; // Metadata key directory needed for mounting FBE encrypted data partitions using metadata encryption + string Original_Path; + bool Use_Original_Path; + struct partition_fs_flags_struct { // This struct is used to store mount flags and options for different file systems for the same partition string File_System; int Mount_Flags;