blob: 8ef50207f4a424229597c96b5514eb4267928479 [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>
bigbiff bigbiff34684ff2013-12-01 21:03:45 -050030#include "twrpDU.hpp"
Ethan Yonker472f5062016-02-25 13:47:30 -060031#include "progresstracking.hpp"
bigbiff bigbiff9c754052013-01-09 09:09:08 -050032
33using namespace std;
34
Dees_Troy83bd4832013-05-04 12:39:56 +000035struct TarListStruct {
36 std::string fn;
37 unsigned thread_id;
38};
39
40struct thread_data_struct {
41 std::vector<TarListStruct> *TarList;
42 unsigned thread_id;
43};
44
bigbiff bigbiff9c754052013-01-09 09:09:08 -050045class twrpTar {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020046public:
47 twrpTar();
48 virtual ~twrpTar();
Ethan Yonker472f5062016-02-25 13:47:30 -060049 int createTarFork(ProgressTracking *progress, pid_t &fork_pid);
50 int extractTarFork(ProgressTracking *progress);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020051 void setfn(string fn);
52 void setdir(string dir);
Dees Troye0a433a2013-12-02 04:10:37 +000053 void setsize(unsigned long long backup_size);
Ethan Yonker87af5632014-02-10 11:56:35 -060054 void setpassword(string pass);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050055 unsigned long long get_size();
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -040056
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020057public:
58 int use_encryption;
59 int userdata_encryption;
60 int use_compression;
61 int split_archives;
62 int has_data_media;
63 string backup_name;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050064 int progress_pipe_fd;
65 string partition_name;
66 string backup_folder;
Dees_Troy83bd4832013-05-04 12:39:56 +000067
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020068private:
69 int extract();
70 int addFilesToExistingTar(vector <string> files, string tarFile);
71 int createTar();
72 int addFile(string fn, bool include_root);
73 int entryExists(string entry);
74 int closeTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020075 int removeEOT(string tarFile);
76 int extractTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020077 string Strip_Root_Dir(string Path);
78 int openTar();
79 int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
80 static void* createList(void *cookie);
81 static void* extractMulti(void *cookie);
Dees Troye0a433a2013-12-02 04:10:37 +000082 int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050083 unsigned long long uncompressedSize(string filename, int *archive_type);
bigbiff7abc5fe2015-01-17 16:53:12 -050084 static void Signal_Kill(int signum);
Dees_Troy83bd4832013-05-04 12:39:56 +000085
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020086 int Archive_Current_Type;
87 unsigned long long Archive_Current_Size;
Dees Troye0a433a2013-12-02 04:10:37 +000088 unsigned long long Total_Backup_Size;
89 bool include_root_dir;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020090 TAR *t;
Ethan Yonker472f5062016-02-25 13:47:30 -060091 tartype_t tar_type; // Only used in createTar() but variable must persist while the tar is open
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020092 int fd;
93 pid_t pigz_pid;
94 pid_t oaes_pid;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050095 unsigned long long file_count;
Dees_Troy83bd4832013-05-04 12:39:56 +000096
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020097 string tardir;
98 string tarfn;
99 string basefn;
Ethan Yonker87af5632014-02-10 11:56:35 -0600100 string password;
Dees_Troy83bd4832013-05-04 12:39:56 +0000101
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200102 std::vector<TarListStruct> *ItemList;
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500103 unsigned thread_id;
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -0400104};