fstab: add support for metadata_encryption flag

Change-Id: Ic1f12f280e9e99cfe3587e35b88a1f2e9d97a1b2
diff --git a/partition.cpp b/partition.cpp
index 1d68c24..d67344a 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -133,6 +133,7 @@
 	TWFLAG_DISPLAY,
 	TWFLAG_ENCRYPTABLE,
 	TWFLAG_FILEENCRYPTION,
+	TWFLAG_METADATA_ENCRYPTION,
 	TWFLAG_FLASHIMG,
 	TWFLAG_FORCEENCRYPT,
 	TWFLAG_FSFLAGS,
@@ -180,6 +181,7 @@
 	{ "display=",               TWFLAG_DISPLAY },
 	{ "encryptable=",           TWFLAG_ENCRYPTABLE },
 	{ "fileencryption=",        TWFLAG_FILEENCRYPTION },
+	{ "metadata_encryption=",   TWFLAG_METADATA_ENCRYPTION },
 	{ "flashimg",               TWFLAG_FLASHIMG },
 	{ "forceencrypt=",          TWFLAG_FORCEENCRYPT },
 	{ "fsflags=",               TWFLAG_FSFLAGS },
@@ -936,6 +938,26 @@
 				LOGINFO("FBE contents '%s', filenames '%s'\n", FBE_contents.c_str(), FBE_filenames.c_str());
 			}
 			break;
+		case TWFLAG_METADATA_ENCRYPTION:
+			// This flag isn't used by TWRP but is needed for FBEv2 metadata decryption
+			// metadata_encryption=aes-256-xts:wrappedkey_v0
+			{
+				std::string META = str;
+				size_t colon_loc = META.find(":");
+				if (colon_loc == std::string::npos) {
+					property_set("metadata.contents", META.c_str());
+					property_set("metadata.filenames", "");
+					LOGINFO("Metadata contents '%s', filenames ''\n", META.c_str());
+					break;
+				}
+				std::string META_contents, META_filenames;
+				META_contents = META.substr(0, colon_loc);
+				META_filenames = META.substr(colon_loc + 1);
+				property_set("metadata.contents", META_contents.c_str());
+				property_set("metadata.filenames", META_filenames.c_str());
+				LOGINFO("Metadata contents '%s', filenames '%s'\n", META_contents.c_str(), META_filenames.c_str());
+			}
+			break;
 		case TWFLAG_WRAPPEDKEY:
 			// no more processing needed. leaving it here in case we want to do something in the future
 			break;