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" { |
| 20 | #include "libtar/libtar.h" |
| 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> |
| 30 | |
| 31 | using namespace std; |
| 32 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 33 | struct TarListStruct { |
| 34 | std::string fn; |
| 35 | unsigned thread_id; |
| 36 | }; |
| 37 | |
| 38 | struct thread_data_struct { |
| 39 | std::vector<TarListStruct> *TarList; |
| 40 | unsigned thread_id; |
| 41 | }; |
| 42 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 43 | class twrpTar { |
| 44 | public: |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 45 | twrpTar(); |
| 46 | virtual ~twrpTar(); |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 47 | int createTarFork(); |
| 48 | int extractTarFork(); |
| 49 | int splitArchiveFork(); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 50 | void setexcl(string exclude); |
| 51 | void setfn(string fn); |
| 52 | void setdir(string dir); |
| 53 | unsigned long long uncompressedSize(); |
| 54 | |
| 55 | public: |
| 56 | int use_encryption; |
| 57 | int userdata_encryption; |
| 58 | int use_compression; |
| 59 | int split_archives; |
| 60 | int has_data_media; |
| 61 | string backup_name; |
| 62 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 63 | private: |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 64 | int extract(); |
| 65 | int addFilesToExistingTar(vector <string> files, string tarFile); |
| 66 | int createTar(); |
| 67 | int addFile(string fn, bool include_root); |
| 68 | int entryExists(string entry); |
| 69 | int closeTar(); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 70 | int create(); |
| 71 | int Split_Archive(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 72 | int removeEOT(string tarFile); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 73 | int extractTar(); |
| 74 | int tarDirs(bool include_root); |
| 75 | int Generate_Multiple_Archives(string Path); |
| 76 | string Strip_Root_Dir(string Path); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 77 | int openTar(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 78 | int Archive_File_Count; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 79 | int Archive_Current_Type; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 80 | unsigned long long Archive_Current_Size; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 81 | TAR *t; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 82 | int fd; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 83 | pid_t pigz_pid; |
| 84 | pid_t oaes_pid; |
| 85 | |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 86 | string tardir; |
| 87 | string tarfn; |
| 88 | string basefn; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 89 | string tarexclude; |
| 90 | |
| 91 | vector<string> split; |
| 92 | |
| 93 | int Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id); |
| 94 | static void* createList(void *cookie); |
| 95 | static void* extractMulti(void *cookie); |
| 96 | int tarList(bool include_root, std::vector<TarListStruct> *TarList, unsigned thread_id); |
| 97 | std::vector<TarListStruct> *ItemList; |
| 98 | int thread_id; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 99 | }; |