blob: 78c4c5978d61450b40f5734b71b40acb29f01e60 [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
Ethan Yonker472f5062016-02-25 13:47:30 -06002 Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin
bigbiff bigbiff9c754052013-01-09 09:09:08 -05003 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19extern "C" {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020020 #include "libtar/libtar.h"
bigbiff bigbiff9c754052013-01-09 09:09:08 -050021}
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <string.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <fstream>
28#include <string>
29#include <vector>
Ethan Yonker3fdcda42016-11-30 12:29:37 -060030#include "exclude.hpp"
Ethan Yonker472f5062016-02-25 13:47:30 -060031#include "progresstracking.hpp"
bigbiffce8f83c2015-12-12 18:30:21 -050032#include "partitions.hpp"
33#include "twrp-functions.hpp"
bigbiff bigbiff9c754052013-01-09 09:09:08 -050034
35using namespace std;
36
Dees_Troy83bd4832013-05-04 12:39:56 +000037struct TarListStruct {
38 std::string fn;
39 unsigned thread_id;
40};
41
42struct thread_data_struct {
43 std::vector<TarListStruct> *TarList;
44 unsigned thread_id;
45};
46
bigbiffce8f83c2015-12-12 18:30:21 -050047
bigbiff bigbiff9c754052013-01-09 09:09:08 -050048class twrpTar {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020049public:
50 twrpTar();
51 virtual ~twrpTar();
bigbiffce8f83c2015-12-12 18:30:21 -050052 int createTarFork(pid_t *tar_fork_pid);
53 int extractTarFork();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020054 void setfn(string fn);
55 void setdir(string dir);
Dees Troye0a433a2013-12-02 04:10:37 +000056 void setsize(unsigned long long backup_size);
Ethan Yonker87af5632014-02-10 11:56:35 -060057 void setpassword(string pass);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050058 unsigned long long get_size();
bigbiffce8f83c2015-12-12 18:30:21 -050059 void Set_Archive_Type(Archive_Type archive_type);
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -040060
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020061public:
62 int use_encryption;
63 int userdata_encryption;
64 int use_compression;
65 int split_archives;
66 int has_data_media;
67 string backup_name;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050068 int progress_pipe_fd;
69 string partition_name;
70 string backup_folder;
bigbiffce8f83c2015-12-12 18:30:21 -050071 PartitionSettings *part_settings;
Ethan Yonker3fdcda42016-11-30 12:29:37 -060072 TWExclude *backup_exclusions;
Dees_Troy83bd4832013-05-04 12:39:56 +000073
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074private:
75 int extract();
76 int addFilesToExistingTar(vector <string> files, string tarFile);
77 int createTar();
78 int addFile(string fn, bool include_root);
79 int entryExists(string entry);
80 int closeTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020081 int removeEOT(string tarFile);
82 int extractTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020083 string Strip_Root_Dir(string Path);
84 int openTar();
85 int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
86 static void* createList(void *cookie);
87 static void* extractMulti(void *cookie);
Dees Troye0a433a2013-12-02 04:10:37 +000088 int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id);
bigbiffce8f83c2015-12-12 18:30:21 -050089 unsigned long long uncompressedSize(string filename);
bigbiff7abc5fe2015-01-17 16:53:12 -050090 static void Signal_Kill(int signum);
Dees_Troy83bd4832013-05-04 12:39:56 +000091
bigbiffce8f83c2015-12-12 18:30:21 -050092 enum Archive_Type current_archive_type;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020093 unsigned long long Archive_Current_Size;
Dees Troye0a433a2013-12-02 04:10:37 +000094 unsigned long long Total_Backup_Size;
95 bool include_root_dir;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020096 TAR *t;
Ethan Yonker472f5062016-02-25 13:47:30 -060097 tartype_t tar_type; // Only used in createTar() but variable must persist while the tar is open
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020098 int fd;
bigbiffce8f83c2015-12-12 18:30:21 -050099 int input_fd; // this stores the fd for libtar to write to
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 pid_t pigz_pid;
101 pid_t oaes_pid;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -0500102 unsigned long long file_count;
Dees_Troy83bd4832013-05-04 12:39:56 +0000103
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200104 string tardir;
105 string tarfn;
106 string basefn;
Ethan Yonker87af5632014-02-10 11:56:35 -0600107 string password;
Dees_Troy83bd4832013-05-04 12:39:56 +0000108
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200109 std::vector<TarListStruct> *ItemList;
bigbiffce8f83c2015-12-12 18:30:21 -0500110 int output_fd; // this stores the output fd that gzip will read from
111 int adb_control_twrp_fd, adb_control_bu_fd; // fds for twrp to twrp bu and bu to twrp control fifos
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500112 unsigned thread_id;
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -0400113};