ADB: Add adb backup for TWRP.

Functionality for client side to backup
tar and image streams over adbd to the client under backup.ab.

Using adb backup on the client side you can backup the partitions
TWRP knows about.

On the client side you can do the following:
adb backup -f <filename> --twrp <options> where options are
--compress: compress data
system: backup system
cache: backup cache
data: backup data
boot: backup boot
etc for each partition.

You can string multiple options,
i.e. adb backup -f <filename> --twrp --compress cache system data

adb backup in TWRP will take any option corresponding
to TWRP fstab partitions, e.g. efs boot as well.

If you do not specify the filename with the -f option,
adb will backup your data to a filename backup.ab on the client.
You can then rename the file and encrypt it with desktop tools.

If you don't want to use command line arguments:
adb backup --twrp

will bring up the gui and allow you to choose partitions
from the backup page.

To restore the backup use the following convention:
adb restore <filename>

Structures are used to store metadata in binary inside
of the file itself. If the metadata structure is modified,
update the adb version so that it will invalidate older
backups and not cause issues on restore. When restoring,
we currently do not support picking specific partitions.
It's all or nothing.

Change-Id: Idb92c37fc9801dc8d89ed2a4570e9d12e76facf8
diff --git a/twrpTar.hpp b/twrpTar.hpp
index 8ef5020..49d373c 100644
--- a/twrpTar.hpp
+++ b/twrpTar.hpp
@@ -29,6 +29,8 @@
 #include <vector>
 #include "twrpDU.hpp"
 #include "progresstracking.hpp"
+#include "partitions.hpp"
+#include "twrp-functions.hpp"
 using namespace std;
@@ -42,17 +44,19 @@
 	unsigned thread_id;
 class twrpTar {
 	virtual ~twrpTar();
-	int createTarFork(ProgressTracking *progress, pid_t &fork_pid);
-	int extractTarFork(ProgressTracking *progress);
+	int createTarFork(pid_t *tar_fork_pid);
+	int extractTarFork();
 	void setfn(string fn);
 	void setdir(string dir);
 	void setsize(unsigned long long backup_size);
 	void setpassword(string pass);
 	unsigned long long get_size();
+	void Set_Archive_Type(Archive_Type archive_type);
 	int use_encryption;
@@ -64,6 +68,7 @@
 	int progress_pipe_fd;
 	string partition_name;
 	string backup_folder;
+	PartitionSettings *part_settings;
 	int extract();
@@ -80,16 +85,17 @@
 	static void* createList(void *cookie);
 	static void* extractMulti(void *cookie);
 	int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id);
-	unsigned long long uncompressedSize(string filename, int *archive_type);
+	unsigned long long uncompressedSize(string filename);
 	static void Signal_Kill(int signum);
-	int Archive_Current_Type;
+	enum Archive_Type current_archive_type;
 	unsigned long long Archive_Current_Size;
 	unsigned long long Total_Backup_Size;
 	bool include_root_dir;
 	TAR *t;
 	tartype_t tar_type; // Only used in createTar() but variable must persist while the tar is open
 	int fd;
+	int input_fd;                                                                   // this stores the fd for libtar to write to
 	pid_t pigz_pid;
 	pid_t oaes_pid;
 	unsigned long long file_count;
@@ -100,5 +106,7 @@
 	string password;
 	std::vector<TarListStruct> *ItemList;
+	int output_fd;                                                                  // this stores the output fd that gzip will read from
+	int adb_control_twrp_fd, adb_control_bu_fd;                                     // fds for twrp to twrp bu and bu to twrp control fifos
 	unsigned thread_id;