bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 2 | Copyright 2012 to 2016 bigbiff/Dees_Troy TeamWin |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 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 | |
| 19 | extern "C" { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 20 | #include "libtar/libtar.h" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 21 | } |
| 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 bigbiff | 34684ff | 2013-12-01 21:03:45 -0500 | [diff] [blame] | 30 | #include "twrpDU.hpp" |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 31 | #include "progresstracking.hpp" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 32 | #include "partitions.hpp" |
| 33 | #include "twrp-functions.hpp" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 34 | |
| 35 | using namespace std; |
| 36 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 37 | struct TarListStruct { |
| 38 | std::string fn; |
| 39 | unsigned thread_id; |
| 40 | }; |
| 41 | |
| 42 | struct thread_data_struct { |
| 43 | std::vector<TarListStruct> *TarList; |
| 44 | unsigned thread_id; |
| 45 | }; |
| 46 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 47 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 48 | class twrpTar { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 49 | public: |
| 50 | twrpTar(); |
| 51 | virtual ~twrpTar(); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 52 | int createTarFork(pid_t *tar_fork_pid); |
| 53 | int extractTarFork(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 54 | void setfn(string fn); |
| 55 | void setdir(string dir); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 56 | void setsize(unsigned long long backup_size); |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 57 | void setpassword(string pass); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 58 | unsigned long long get_size(); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 59 | void Set_Archive_Type(Archive_Type archive_type); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 60 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 61 | public: |
| 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 Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 68 | int progress_pipe_fd; |
| 69 | string partition_name; |
| 70 | string backup_folder; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 71 | PartitionSettings *part_settings; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 72 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 73 | private: |
| 74 | int extract(); |
| 75 | int addFilesToExistingTar(vector <string> files, string tarFile); |
| 76 | int createTar(); |
| 77 | int addFile(string fn, bool include_root); |
| 78 | int entryExists(string entry); |
| 79 | int closeTar(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 80 | int removeEOT(string tarFile); |
| 81 | int extractTar(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 82 | string Strip_Root_Dir(string Path); |
| 83 | int openTar(); |
| 84 | int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id); |
| 85 | static void* createList(void *cookie); |
| 86 | static void* extractMulti(void *cookie); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 87 | int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 88 | unsigned long long uncompressedSize(string filename); |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 89 | static void Signal_Kill(int signum); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 90 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 91 | enum Archive_Type current_archive_type; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 92 | unsigned long long Archive_Current_Size; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 93 | unsigned long long Total_Backup_Size; |
| 94 | bool include_root_dir; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 95 | TAR *t; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 96 | tartype_t tar_type; // Only used in createTar() but variable must persist while the tar is open |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 97 | int fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 98 | int input_fd; // this stores the fd for libtar to write to |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 99 | pid_t pigz_pid; |
| 100 | pid_t oaes_pid; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 101 | unsigned long long file_count; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 102 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 103 | string tardir; |
| 104 | string tarfn; |
| 105 | string basefn; |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 106 | string password; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 107 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 108 | std::vector<TarListStruct> *ItemList; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 109 | int output_fd; // this stores the output fd that gzip will read from |
| 110 | int adb_control_twrp_fd, adb_control_bu_fd; // fds for twrp to twrp bu and bu to twrp control fifos |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 111 | unsigned thread_id; |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 112 | }; |