Support f2fs filesystem compression (needs kernel support and relevant fstab flags)

Change-Id: Ib90ce3a6c96eea84d3d7f6a88e85b931177df5d3
(cherry picked from commit 9fb13afad8331481b4a516ee32620ca49f6c833a)
diff --git a/Android.mk b/Android.mk
index fe10883..da8cdd0 100755
--- a/Android.mk
+++ b/Android.mk
@@ -189,6 +189,10 @@
     LOCAL_CFLAGS += -DTW_PREPARE_DATA_MEDIA_EARLY
 endif
 
+ifeq ($(TW_ENABLE_FS_COMPRESSION),true)
+    LOCAL_CFLAGS += -DTW_ENABLE_FS_COMPRESSION
+endif
+
 LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/bin
 
 ifeq ($(TARGET_RECOVERY_TWRP_LIB),)
diff --git a/partition.cpp b/partition.cpp
index 59e046a..14a9fe8 100755
--- a/partition.cpp
+++ b/partition.cpp
@@ -166,6 +166,7 @@
 	TWFLAG_WRAPPEDKEY,
 	TWFLAG_ADOPTED_MOUNT_DELAY,
 	TWFLAG_DM_USE_ORIGINAL_PATH,
+	TWFLAG_FS_COMPRESS,
 	TWFLAG_LOGICAL,
 };
 
@@ -215,6 +216,7 @@
 	{ "wrappedkey",             TWFLAG_WRAPPEDKEY },
 	{ "adopted_mount_delay=",   TWFLAG_ADOPTED_MOUNT_DELAY },
 	{ "dm_use_original_path",   TWFLAG_DM_USE_ORIGINAL_PATH },
+	{ "fscompress",             TWFLAG_FS_COMPRESS },
 	{ "logical",                TWFLAG_LOGICAL },
 	{ 0,                        0 },
 };
@@ -283,6 +285,7 @@
 	Adopted_Mount_Delay = 0;
 	Original_Path = "";
 	Use_Original_Path = false;
+	Needs_Fs_Compress = false;
 }
 
 TWPartition::~TWPartition(void) {
@@ -1053,6 +1056,14 @@
 		case TWFLAG_LOGICAL:
 			Is_Super = true;
 			break;
+		case TWFLAG_FS_COMPRESS:
+			#ifdef TW_ENABLE_FS_COMPRESSION
+				Needs_Fs_Compress = true;
+				LOGINFO("Enabling 'fs compression'\n");
+			#else
+				LOGINFO("Ignoring the 'fscompress' fstab flag\n");
+			#endif
+			break;
 		default:
 			// Should not get here
 			LOGINFO("Flag identified for processing, but later unmatched: %i\n", flag);
@@ -2489,6 +2500,9 @@
 	if(needs_casefold)
 		f2fs_command += " -O casefold -C utf8";
 
+	if (Needs_Fs_Compress)
+		f2fs_command += " -O compression,extra_attr";
+
 	f2fs_command += " " + Actual_Block_Device + " " + dev_sz_str;
 
 	if (TWFunc::Path_Exists("/system/bin/sload_f2fs")) {
diff --git a/partitions.hpp b/partitions.hpp
index 1b2f3cb..713337b 100755
--- a/partitions.hpp
+++ b/partitions.hpp
@@ -285,6 +285,7 @@
 	string Key_Directory;                                                     // Metadata key directory needed for mounting FBE encrypted data partitions using metadata encryption
 	string Original_Path;
 	bool Use_Original_Path;
+	bool Needs_Fs_Compress;
 
 	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;