bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 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" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 31 | |
| 32 | using namespace std; |
| 33 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 34 | struct TarListStruct { |
| 35 | std::string fn; |
| 36 | unsigned thread_id; |
| 37 | }; |
| 38 | |
| 39 | struct thread_data_struct { |
| 40 | std::vector<TarListStruct> *TarList; |
| 41 | unsigned thread_id; |
| 42 | }; |
| 43 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 44 | class twrpTar { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 45 | public: |
| 46 | twrpTar(); |
| 47 | virtual ~twrpTar(); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 48 | int createTarFork(const unsigned long long *overall_size, const unsigned long long *other_backups_size); |
| 49 | int extractTarFork(const unsigned long long *overall_size, unsigned long long *other_backups_size); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 50 | void setfn(string fn); |
| 51 | void setdir(string dir); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 52 | void setsize(unsigned long long backup_size); |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 53 | void setpassword(string pass); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 54 | unsigned long long get_size(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 56 | public: |
| 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 Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 63 | int progress_pipe_fd; |
| 64 | string partition_name; |
| 65 | string backup_folder; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 66 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 67 | private: |
| 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 Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 74 | int removeEOT(string tarFile); |
| 75 | int extractTar(); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 76 | 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 Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 81 | int tarList(std::vector<TarListStruct> *TarList, unsigned thread_id); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 82 | unsigned long long uncompressedSize(string filename, int *archive_type); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | int Archive_Current_Type; |
| 85 | unsigned long long Archive_Current_Size; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 86 | unsigned long long Total_Backup_Size; |
| 87 | bool include_root_dir; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 88 | TAR *t; |
| 89 | int fd; |
| 90 | pid_t pigz_pid; |
| 91 | pid_t oaes_pid; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 92 | unsigned long long file_count; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 93 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 94 | string tardir; |
| 95 | string tarfn; |
| 96 | string basefn; |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 97 | string password; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 98 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 99 | std::vector<TarListStruct> *ItemList; |
| 100 | int thread_id; |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 101 | }; |