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
diff --git a/partition.cpp b/partition.cpp
index d08aa5b..b31b228 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -163,6 +163,7 @@
 	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
@@ -209,6 +210,7 @@
 	{ "keydirectory=",          TWFLAG_KEYDIRECTORY },
 	{ "wrappedkey",             TWFLAG_WRAPPEDKEY },
 	{ "adopted_mount_delay=",   TWFLAG_ADOPTED_MOUNT_DELAY },
+	{ "dm_use_original_path",   TWFLAG_DM_USE_ORIGINAL_PATH },
 	{ 0,                        0 },
 };
 
@@ -274,6 +276,8 @@
 	SlotSelect = false;
 	Key_Directory = "";
 	Adopted_Mount_Delay = 0;
+	Original_Path = "";
+	Use_Original_Path = false;
 }
 
 TWPartition::~TWPartition(void) {
@@ -671,7 +675,7 @@
 	} 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;
@@ -994,6 +998,8 @@
 			break;
 		case TWFLAG_KEYDIRECTORY:
 			Key_Directory = str;
+		case TWFLAG_DM_USE_ORIGINAL_PATH:
+			Use_Original_Path = true;
 		default:
 			// Should not get here
 			LOGINFO("Flag identified for processing, but later unmatched: %i\n", flag);
@@ -1207,6 +1213,8 @@
 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 cc4eb98..4510281 100755
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -285,6 +285,8 @@
 	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;