blob: a486c41741864c8f464075ab44227f4d11e21cba [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
2 Copyright 2012 bigbiff/Dees_Troy TeamWin
3 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"
bigbiff bigbiff9c754052013-01-09 09:09:08 -050031
32using namespace std;
33
Dees_Troy83bd4832013-05-04 12:39:56 +000034struct TarListStruct {
35 std::string fn;
36 unsigned thread_id;
37};
38
39struct thread_data_struct {
40 std::vector<TarListStruct> *TarList;
41 unsigned thread_id;
42};
43
bigbiff bigbiff9c754052013-01-09 09:09:08 -050044class twrpTar {
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020045public:
46 twrpTar();
47 virtual ~twrpTar();
bigbiff7abc5fe2015-01-17 16:53:12 -050048 int createTarFork(const unsigned long long *overall_size, const unsigned long long *other_backups_size, pid_t &fork_pid);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050049 int extractTarFork(const unsigned long long *overall_size, unsigned long long *other_backups_size);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020050 void setfn(string fn);
51 void setdir(string dir);
Dees Troye0a433a2013-12-02 04:10:37 +000052 void setsize(unsigned long long backup_size);
Ethan Yonker87af5632014-02-10 11:56:35 -060053 void setpassword(string pass);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050054 unsigned long long get_size();
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -040055
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020056public:
57 int use_encryption;
58 int userdata_encryption;
59 int use_compression;
60 int split_archives;
61 int has_data_media;
62 string backup_name;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050063 int progress_pipe_fd;
64 string partition_name;
65 string backup_folder;
Dees_Troy83bd4832013-05-04 12:39:56 +000066
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020067private:
68 int extract();
69 int addFilesToExistingTar(vector <string> files, string tarFile);
70 int createTar();
71 int addFile(string fn, bool include_root);
72 int entryExists(string entry);
73 int closeTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020074 int removeEOT(string tarFile);
75 int extractTar();
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020076 string Strip_Root_Dir(string Path);
77 int openTar();
78 int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id);
79 static void* createList(void *cookie);
80 static void* extractMulti(void *cookie);
Dees Troye0a433a2013-12-02 04:10:37 +000081 int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id);
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050082 unsigned long long uncompressedSize(string filename, int *archive_type);
bigbiff7abc5fe2015-01-17 16:53:12 -050083 static void Signal_Kill(int signum);
Dees_Troy83bd4832013-05-04 12:39:56 +000084
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020085 int Archive_Current_Type;
86 unsigned long long Archive_Current_Size;
Dees Troye0a433a2013-12-02 04:10:37 +000087 unsigned long long Total_Backup_Size;
88 bool include_root_dir;
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020089 TAR *t;
90 int fd;
91 pid_t pigz_pid;
92 pid_t oaes_pid;
Ethan Yonker1b7a31b2014-07-03 15:09:22 -050093 unsigned long long file_count;
Dees_Troy83bd4832013-05-04 12:39:56 +000094
Vojtech Bocekfafb0c52013-07-25 22:53:02 +020095 string tardir;
96 string tarfn;
97 string basefn;
Ethan Yonker87af5632014-02-10 11:56:35 -060098 string password;
Dees_Troy83bd4832013-05-04 12:39:56 +000099
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200100 std::vector<TarListStruct> *ItemList;
Ethan Yonkerc798c9c2015-10-09 11:15:26 -0500101 unsigned thread_id;
bigbiff bigbiff86e77bc2013-08-26 21:36:23 -0400102};