Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 1 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 2 | /* |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 3 | Copyright 2013 to 2020 TeamWin |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 4 | This file is part of TWRP/TeamWin Recovery Project. |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 5 | |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 6 | TWRP is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 3 of the License, or |
| 9 | (at your option) any later version. |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 10 | |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 11 | TWRP is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 15 | |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 16 | You should have received a copy of the GNU General Public License |
| 17 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | extern "C" { |
| 21 | #include "libtar/libtar.h" |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 22 | #include "twrpTar.h" |
| 23 | #include "tarWrite.h" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 24 | } |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 27 | #include <sys/wait.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 28 | #include <string.h> |
| 29 | #include <errno.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <fstream> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 32 | #include <iostream> |
| 33 | #include <string> |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 34 | #include <sstream> |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 35 | #include <vector> |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 36 | #include <csignal> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 37 | #include <dirent.h> |
bigbiff bigbiff | c49d706 | 2013-10-11 20:28:00 -0400 | [diff] [blame] | 38 | #include <libgen.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 39 | #include <sys/mman.h> |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 40 | #include <sys/ioctl.h> |
| 41 | #include <zlib.h> |
| 42 | #include <semaphore.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 43 | #include "twrpTar.hpp" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 44 | #include "twcommon.h" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 45 | #include "variables.h" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 46 | #include "adbbu/libtwadbbu.hpp" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 47 | #include "twrp-functions.hpp" |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 48 | #include "gui/gui.hpp" |
| 49 | #include "progresstracking.hpp" |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 50 | |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 51 | #ifndef BUILD_TWRPTAR_MAIN |
| 52 | #include "data.hpp" |
| 53 | #include "infomanager.hpp" |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 54 | #include "set_metadata.h" |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 55 | #endif //ndef BUILD_TWRPTAR_MAIN |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 56 | |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 57 | #ifdef TW_INCLUDE_FBE |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 58 | #ifdef USE_FSCRYPT |
| 59 | #include "fscrypt_policy.h" |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 60 | #endif |
| 61 | #endif |
| 62 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 63 | #ifdef USE_FSCRYPT |
| 64 | #define TWTAR_FLAGS TAR_GNU | TAR_STORE_SELINUX | TAR_STORE_POSIX_CAP | TAR_STORE_ANDROID_USER_XATTR | TAR_STORE_FSCRYPT_POL |
| 65 | #else |
Ethan Yonker | 8d039f7 | 2017-02-03 14:26:15 -0600 | [diff] [blame] | 66 | #define TWTAR_FLAGS TAR_GNU | TAR_STORE_SELINUX | TAR_STORE_POSIX_CAP | TAR_STORE_ANDROID_USER_XATTR |
Ethan Yonker | 79f88bd | 2016-12-09 14:52:12 -0600 | [diff] [blame] | 67 | #endif |
| 68 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 69 | using namespace std; |
| 70 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 71 | twrpTar::twrpTar(void) { |
| 72 | use_encryption = 0; |
| 73 | userdata_encryption = 0; |
| 74 | use_compression = 0; |
| 75 | split_archives = 0; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 76 | pigz_pid = 0; |
| 77 | oaes_pid = 0; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 78 | Total_Backup_Size = 0; |
Ethan Yonker | 1a147a4 | 2015-02-27 13:14:44 -0600 | [diff] [blame] | 79 | Archive_Current_Size = 0; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 80 | include_root_dir = true; |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 81 | tar_type.openfunc = open; |
| 82 | tar_type.closefunc = close; |
| 83 | tar_type.readfunc = read; |
Ethan Yonker | ea2fcf0 | 2016-09-12 16:07:19 -0500 | [diff] [blame] | 84 | input_fd = -1; |
| 85 | output_fd = -1; |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 86 | backup_exclusions = NULL; |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame^] | 87 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 88 | #ifdef USE_FSCRYPT |
| 89 | fscrypt_set_mode(); |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 90 | #endif |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | twrpTar::~twrpTar(void) { |
| 94 | // Do nothing |
| 95 | } |
| 96 | |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 97 | void twrpTar::setfn(string fn) { |
| 98 | tarfn = fn; |
| 99 | } |
| 100 | |
| 101 | void twrpTar::setdir(string dir) { |
| 102 | tardir = dir; |
| 103 | } |
| 104 | |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 105 | void twrpTar::setsize(unsigned long long backup_size) { |
| 106 | Total_Backup_Size = backup_size; |
| 107 | } |
| 108 | |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 109 | void twrpTar::setpassword(string pass) { |
| 110 | password = pass; |
| 111 | } |
| 112 | |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 113 | void twrpTar::Signal_Kill(int signum) { |
| 114 | _exit(255); |
| 115 | } |
| 116 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 117 | void twrpTar::Set_Archive_Type(Archive_Type archive_type) { |
| 118 | current_archive_type = archive_type; |
| 119 | } |
| 120 | |
| 121 | int twrpTar::createTarFork(pid_t *tar_fork_pid) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 122 | int status = 0; |
Matt Mower | 23d8aae | 2017-01-06 14:30:33 -0600 | [diff] [blame] | 123 | int progress_pipe[2]; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 124 | |
| 125 | file_count = 0; |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 126 | if (backup_exclusions == NULL) { |
| 127 | LOGINFO("backup_exclusions is NULL\n"); |
| 128 | return -1; |
| 129 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 130 | |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 131 | #ifndef BUILD_TWRPTAR_MAIN |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 132 | if (part_settings->adbbackup) { |
| 133 | std::string Backup_FileName(tarfn); |
| 134 | if (!twadbbu::Write_TWFN(Backup_FileName, Total_Backup_Size, use_compression)) |
| 135 | return -1; |
| 136 | } |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 137 | #endif |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 138 | |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 139 | if (pipe(progress_pipe) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 140 | LOGINFO("Error creating progress tracking pipe\n"); |
| 141 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 142 | return -1; |
| 143 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 144 | if ((*tar_fork_pid = fork()) == -1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 145 | LOGINFO("create tar failed to fork.\n"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 146 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 147 | close(progress_pipe[0]); |
| 148 | close(progress_pipe[1]); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 149 | return -1; |
| 150 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 151 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 152 | if (*tar_fork_pid == 0) { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 153 | // Child process |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 154 | // Child closes input side of progress pipe |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 155 | signal(SIGUSR2, twrpTar::Signal_Kill); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 156 | close(progress_pipe[0]); |
| 157 | progress_pipe_fd = progress_pipe[1]; |
| 158 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 159 | if (use_encryption || userdata_encryption) { |
| 160 | LOGINFO("Using encryption\n"); |
| 161 | DIR* d; |
| 162 | struct dirent* de; |
that | 2252d24 | 2015-04-03 22:33:04 +0200 | [diff] [blame] | 163 | unsigned long long regular_size = 0, encrypt_size = 0, target_size = 0, total_size; |
| 164 | unsigned enc_thread_id = 1, regular_thread_id = 0, i, start_thread_id = 1, core_count = 1; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 165 | int item_len, ret, thread_error = 0; |
| 166 | std::vector<TarListStruct> RegularList; |
| 167 | std::vector<TarListStruct> EncryptList; |
| 168 | string FileName; |
| 169 | struct TarListStruct TarItem; |
| 170 | twrpTar reg, enc[9]; |
| 171 | struct stat st; |
| 172 | pthread_t enc_thread[9]; |
| 173 | pthread_attr_t tattr; |
| 174 | void *thread_return; |
| 175 | |
| 176 | core_count = sysconf(_SC_NPROCESSORS_CONF); |
| 177 | if (core_count > 8) |
| 178 | core_count = 8; |
that | 2252d24 | 2015-04-03 22:33:04 +0200 | [diff] [blame] | 179 | LOGINFO(" Core Count : %u\n", core_count); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 180 | Archive_Current_Size = 0; |
| 181 | |
| 182 | d = opendir(tardir.c_str()); |
| 183 | if (d == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 184 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tardir)(strerror(errno))); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 185 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 186 | _exit(-1); |
| 187 | } |
| 188 | // Figure out the size of all data to be encrypted and create a list of unencrypted files |
| 189 | while ((de = readdir(d)) != NULL) { |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 190 | FileName = tardir + "/" + de->d_name; |
| 191 | |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 192 | if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 193 | continue; |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 194 | if (de->d_type == DT_DIR) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 195 | item_len = strlen(de->d_name); |
| 196 | if (userdata_encryption && ((item_len >= 3 && strncmp(de->d_name, "app", 3) == 0) || (item_len >= 6 && strncmp(de->d_name, "dalvik", 6) == 0))) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 197 | ret = Generate_TarList(FileName, &RegularList, &target_size, ®ular_thread_id); |
| 198 | if (ret < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 199 | LOGINFO("Error in Generate_TarList with regular list!\n"); |
| 200 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 201 | closedir(d); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 202 | close(progress_pipe_fd); |
| 203 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 204 | _exit(-1); |
| 205 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 206 | file_count = (unsigned long long)(ret); |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 207 | regular_size += backup_exclusions->Get_Folder_Size(FileName); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 208 | } else { |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 209 | encrypt_size += backup_exclusions->Get_Folder_Size(FileName); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 210 | } |
| 211 | } else if (de->d_type == DT_REG) { |
| 212 | stat(FileName.c_str(), &st); |
| 213 | encrypt_size += (unsigned long long)(st.st_size); |
| 214 | } |
| 215 | } |
| 216 | closedir(d); |
| 217 | |
| 218 | target_size = encrypt_size / core_count; |
| 219 | target_size++; |
| 220 | LOGINFO(" Unencrypted size: %llu\n", regular_size); |
| 221 | LOGINFO(" Encrypted size : %llu\n", encrypt_size); |
| 222 | LOGINFO(" Target size : %llu\n", target_size); |
| 223 | if (!userdata_encryption) { |
| 224 | enc_thread_id = 0; |
| 225 | start_thread_id = 0; |
| 226 | core_count--; |
| 227 | } |
| 228 | Archive_Current_Size = 0; |
| 229 | |
| 230 | d = opendir(tardir.c_str()); |
| 231 | if (d == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 232 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tardir)(strerror(errno))); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 233 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 234 | _exit(-1); |
| 235 | } |
| 236 | // Divide up the encrypted file list for threading |
| 237 | while ((de = readdir(d)) != NULL) { |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 238 | FileName = tardir + "/" + de->d_name; |
| 239 | |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 240 | if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 241 | continue; |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 242 | if (de->d_type == DT_DIR) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 243 | item_len = strlen(de->d_name); |
| 244 | if (userdata_encryption && ((item_len >= 3 && strncmp(de->d_name, "app", 3) == 0) || (item_len >= 6 && strncmp(de->d_name, "dalvik", 6) == 0))) { |
| 245 | // Do nothing, we added these to RegularList earlier |
| 246 | } else { |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 247 | FileName = tardir + "/" + de->d_name; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 248 | ret = Generate_TarList(FileName, &EncryptList, &target_size, &enc_thread_id); |
| 249 | if (ret < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 250 | LOGINFO("Error in Generate_TarList with encrypted list!\n"); |
| 251 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 252 | closedir(d); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 253 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 254 | _exit(-1); |
| 255 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 256 | file_count += (unsigned long long)(ret); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 257 | } |
| 258 | } else if (de->d_type == DT_REG || de->d_type == DT_LNK) { |
| 259 | stat(FileName.c_str(), &st); |
| 260 | if (de->d_type == DT_REG) |
| 261 | Archive_Current_Size += (unsigned long long)(st.st_size); |
| 262 | TarItem.fn = FileName; |
| 263 | TarItem.thread_id = enc_thread_id; |
| 264 | EncryptList.push_back(TarItem); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 265 | file_count++; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | closedir(d); |
| 269 | if (enc_thread_id != core_count) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 270 | LOGINFO("Error dividing up threads for encryption, %u threads for %u cores!\n", enc_thread_id, core_count); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 271 | if (enc_thread_id > core_count) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 272 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 273 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 274 | _exit(-1); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 275 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 276 | LOGINFO("Continuining anyway."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 277 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 280 | // Send file count to parent |
| 281 | write(progress_pipe_fd, &file_count, sizeof(file_count)); |
| 282 | // Send backup size to parent |
| 283 | total_size = regular_size + encrypt_size; |
| 284 | write(progress_pipe_fd, &total_size, sizeof(total_size)); |
| 285 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 286 | if (userdata_encryption) { |
| 287 | // Create a backup of unencrypted data |
| 288 | reg.setfn(tarfn); |
| 289 | reg.ItemList = &RegularList; |
| 290 | reg.thread_id = 0; |
| 291 | reg.use_encryption = 0; |
| 292 | reg.use_compression = use_compression; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 293 | reg.split_archives = 1; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 294 | reg.progress_pipe_fd = progress_pipe_fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 295 | reg.part_settings = part_settings; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 296 | LOGINFO("Creating unencrypted backup...\n"); |
| 297 | if (createList((void*)®) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 298 | LOGINFO("Error creating unencrypted backup.\n"); |
| 299 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 300 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 301 | _exit(-1); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | if (pthread_attr_init(&tattr)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 306 | LOGINFO("Unable to pthread_attr_init\n"); |
| 307 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 308 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 309 | _exit(-1); |
| 310 | } |
| 311 | if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 312 | LOGINFO("Error setting pthread_attr_setdetachstate\n"); |
| 313 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 314 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 315 | _exit(-1); |
| 316 | } |
| 317 | if (pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 318 | LOGINFO("Error setting pthread_attr_setscope\n"); |
| 319 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 320 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 321 | _exit(-1); |
| 322 | } |
| 323 | /*if (pthread_attr_setstacksize(&tattr, 524288)) { |
| 324 | LOGERR("Error setting pthread_attr_setstacksize\n"); |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 325 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 326 | _exit(-1); |
| 327 | }*/ |
| 328 | |
| 329 | // Create threads for the divided up encryption lists |
| 330 | for (i = start_thread_id; i <= core_count; i++) { |
| 331 | enc[i].setdir(tardir); |
| 332 | enc[i].setfn(tarfn); |
| 333 | enc[i].ItemList = &EncryptList; |
| 334 | enc[i].thread_id = i; |
| 335 | enc[i].use_encryption = use_encryption; |
Ethan Yonker | 924a80b | 2014-04-02 10:54:12 -0500 | [diff] [blame] | 336 | enc[i].setpassword(password); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 337 | enc[i].use_compression = use_compression; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 338 | enc[i].split_archives = 1; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 339 | enc[i].progress_pipe_fd = progress_pipe_fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 340 | enc[i].part_settings = part_settings; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 341 | LOGINFO("Start encryption thread %i\n", i); |
| 342 | ret = pthread_create(&enc_thread[i], &tattr, createList, (void*)&enc[i]); |
| 343 | if (ret) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 344 | LOGINFO("Unable to create %i thread for encryption! %i\nContinuing in same thread (backup will be slower).\n", i, ret); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 345 | if (createList((void*)&enc[i]) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 346 | LOGINFO("Error creating encrypted backup %i.\n", i); |
| 347 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 348 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 349 | _exit(-1); |
| 350 | } else { |
| 351 | enc[i].thread_id = i + 1; |
| 352 | } |
| 353 | } |
| 354 | usleep(100000); // Need a short delay before starting the next thread or the threads will never finish for some reason. |
| 355 | } |
| 356 | if (pthread_attr_destroy(&tattr)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 357 | LOGINFO("Failed to pthread_attr_destroy\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 358 | } |
| 359 | for (i = start_thread_id; i <= core_count; i++) { |
| 360 | if (enc[i].thread_id == i) { |
| 361 | if (pthread_join(enc_thread[i], &thread_return)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 362 | LOGINFO("Error joining thread %i\n", i); |
| 363 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 364 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 365 | _exit(-1); |
| 366 | } else { |
| 367 | LOGINFO("Joined thread %i.\n", i); |
that | 2252d24 | 2015-04-03 22:33:04 +0200 | [diff] [blame] | 368 | ret = (int)(intptr_t)thread_return; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 369 | if (ret != 0) { |
| 370 | thread_error = 1; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 371 | LOGINFO("Thread %i returned an error %i.\n", i, ret); |
| 372 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 373 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 374 | _exit(-1); |
| 375 | } |
| 376 | } |
| 377 | } else { |
| 378 | LOGINFO("Skipping joining thread %i because of pthread failure.\n", i); |
| 379 | } |
| 380 | } |
| 381 | if (thread_error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 382 | LOGINFO("Error returned by one or more threads.\n"); |
| 383 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 384 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 385 | _exit(-1); |
| 386 | } |
| 387 | LOGINFO("Finished encrypted backup.\n"); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 388 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 389 | _exit(0); |
| 390 | } else { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 391 | // Not encrypted |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 392 | std::vector<TarListStruct> FileList; |
| 393 | unsigned thread_id = 0; |
| 394 | unsigned long long target_size = 0; |
| 395 | twrpTar reg; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 396 | int ret; |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 397 | |
| 398 | // Generate list of files to back up |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 399 | ret = Generate_TarList(tardir, &FileList, &target_size, &thread_id); |
| 400 | if (ret < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 401 | LOGINFO("Error in Generate_TarList!\n"); |
| 402 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 403 | close(progress_pipe[1]); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 404 | _exit(-1); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 405 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 406 | file_count = (unsigned long long)(ret); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 407 | // Create a backup |
| 408 | reg.setfn(tarfn); |
| 409 | reg.ItemList = &FileList; |
| 410 | reg.thread_id = 0; |
| 411 | reg.use_encryption = 0; |
| 412 | reg.use_compression = use_compression; |
| 413 | reg.setsize(Total_Backup_Size); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 414 | reg.progress_pipe_fd = progress_pipe_fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 415 | reg.part_settings = part_settings; |
| 416 | if (Total_Backup_Size > MAX_ARCHIVE_SIZE && !part_settings->adbbackup) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 417 | gui_msg("split_backup=Breaking backup file into multiple archives..."); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 418 | reg.split_archives = 1; |
| 419 | } else { |
| 420 | reg.split_archives = 0; |
| 421 | } |
| 422 | LOGINFO("Creating backup...\n"); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 423 | write(progress_pipe_fd, &file_count, sizeof(file_count)); |
| 424 | write(progress_pipe_fd, &Total_Backup_Size, sizeof(Total_Backup_Size)); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 425 | if (createList((void*)®) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 426 | gui_err("backup_error=Error creating backup."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 427 | close(progress_pipe[1]); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 428 | _exit(-1); |
| 429 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 430 | close(progress_pipe[1]); |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 431 | _exit(0); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 432 | } |
| 433 | } else { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 434 | // Parent side |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 435 | unsigned long long fs, size_backup = 0, files_backup = 0, file_count = 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 436 | int first_data = 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 437 | |
| 438 | // Parent closes output side |
| 439 | close(progress_pipe[1]); |
| 440 | |
| 441 | // Read progress data from children |
| 442 | while (read(progress_pipe[0], &fs, sizeof(fs)) > 0) { |
| 443 | if (first_data == 0) { |
| 444 | // First incoming data is the file count |
| 445 | file_count = fs; |
| 446 | if (file_count == 0) file_count = 1; // prevent division by 0 below |
| 447 | first_data = 1; |
| 448 | } else if (first_data == 1) { |
| 449 | // Second incoming data is total size |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 450 | first_data = 2; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 451 | part_settings->progress->SetSizeCount(fs, file_count); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 452 | } else { |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 453 | if (fs > 0) { |
| 454 | size_backup += fs; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 455 | part_settings->progress->UpdateSize(size_backup); |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 456 | } else { // fs == 0 increments the file counter |
| 457 | files_backup++; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 458 | part_settings->progress->UpdateSizeCount(size_backup, files_backup); |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 459 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | close(progress_pipe[0]); |
| 463 | #ifndef BUILD_TWRPTAR_MAIN |
| 464 | DataManager::SetValue("tw_file_progress", ""); |
| 465 | DataManager::SetValue("tw_size_progress", ""); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 466 | part_settings->progress->DisplayFileCount(false); |
| 467 | part_settings->progress->UpdateDisplayDetails(true); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 468 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 469 | if (!part_settings->adbbackup) { |
James Christopher Adduono | 9059499 | 2016-10-25 00:51:27 -0400 | [diff] [blame] | 470 | InfoManager backup_info(backup_folder + "/" + partition_name + ".info"); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 471 | backup_info.SetValue("backup_size", size_backup); |
| 472 | if (use_compression && use_encryption) |
| 473 | backup_info.SetValue("backup_type", COMPRESSED_ENCRYPTED); |
| 474 | else if (use_encryption) |
| 475 | backup_info.SetValue("backup_type", ENCRYPTED); |
| 476 | else if (use_compression) |
| 477 | backup_info.SetValue("backup_type", COMPRESSED); |
| 478 | else |
| 479 | backup_info.SetValue("backup_type", UNCOMPRESSED); |
| 480 | backup_info.SetValue("file_count", files_backup); |
| 481 | backup_info.SaveValues(); |
| 482 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 483 | #endif //ndef BUILD_TWRPTAR_MAIN |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 484 | if (TWFunc::Wait_For_Child(*tar_fork_pid, &status, "createTarFork()") != 0) |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 485 | return -1; |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 486 | } |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 490 | int twrpTar::extractTarFork() { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 491 | int status = 0; |
Matt Mower | 23d8aae | 2017-01-06 14:30:33 -0600 | [diff] [blame] | 492 | pid_t tar_fork_pid; |
| 493 | int progress_pipe[2]; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 494 | |
| 495 | if (pipe(progress_pipe) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 496 | LOGINFO("Error creating progress tracking pipe\n"); |
| 497 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 498 | return -1; |
| 499 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 500 | |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 501 | tar_fork_pid = fork(); |
| 502 | if (tar_fork_pid >= 0) // fork was successful |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 503 | { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 504 | if (tar_fork_pid == 0) // child process |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 505 | { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 506 | close(progress_pipe[0]); |
| 507 | progress_pipe_fd = progress_pipe[1]; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 508 | if (TWFunc::Path_Exists(tarfn) || part_settings->adbbackup) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 509 | LOGINFO("Single archive\n"); |
| 510 | if (extract() != 0) |
| 511 | _exit(-1); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 512 | else { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 513 | _exit(0); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 514 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 515 | } else { |
| 516 | LOGINFO("Multiple archives\n"); |
| 517 | string temp; |
| 518 | char actual_filename[255]; |
| 519 | twrpTar tars[9]; |
| 520 | pthread_t tar_thread[9]; |
| 521 | pthread_attr_t tattr; |
Ethan Yonker | c798c9c | 2015-10-09 11:15:26 -0500 | [diff] [blame] | 522 | unsigned thread_count = 0, i, start_thread_id = 1; |
| 523 | int ret, thread_error = 0; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 524 | void *thread_return; |
| 525 | |
| 526 | basefn = tarfn; |
| 527 | temp = basefn + "%i%02i"; |
| 528 | tarfn += "000"; |
| 529 | if (!TWFunc::Path_Exists(tarfn)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 530 | LOGINFO("Unable to locate '%s' or '%s'\n", basefn.c_str(), tarfn.c_str()); |
| 531 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 532 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 533 | _exit(-1); |
| 534 | } |
| 535 | if (TWFunc::Get_File_Type(tarfn) != 2) { |
| 536 | LOGINFO("First tar file '%s' not encrypted\n", tarfn.c_str()); |
| 537 | tars[0].basefn = basefn; |
| 538 | tars[0].thread_id = 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 539 | tars[0].progress_pipe_fd = progress_pipe_fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 540 | tars[0].part_settings = part_settings; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 541 | if (extractMulti((void*)&tars[0]) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 542 | LOGINFO("Error extracting split archive.\n"); |
| 543 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 544 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 545 | _exit(-1); |
| 546 | } |
| 547 | } else { |
| 548 | start_thread_id = 0; |
| 549 | } |
| 550 | // Start threading encrypted restores |
| 551 | if (pthread_attr_init(&tattr)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 552 | LOGINFO("Unable to pthread_attr_init\n"); |
| 553 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 554 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 555 | _exit(-1); |
| 556 | } |
| 557 | if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 558 | LOGINFO("Error setting pthread_attr_setdetachstate\n"); |
| 559 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 560 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 561 | _exit(-1); |
| 562 | } |
| 563 | if (pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 564 | LOGINFO("Error setting pthread_attr_setscope\n"); |
| 565 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 566 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 567 | _exit(-1); |
| 568 | } |
| 569 | /*if (pthread_attr_setstacksize(&tattr, 524288)) { |
| 570 | LOGERR("Error setting pthread_attr_setstacksize\n"); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 571 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 572 | _exit(-1); |
| 573 | }*/ |
| 574 | for (i = start_thread_id; i < 9; i++) { |
| 575 | sprintf(actual_filename, temp.c_str(), i, 0); |
| 576 | if (TWFunc::Path_Exists(actual_filename)) { |
| 577 | thread_count++; |
| 578 | tars[i].basefn = basefn; |
Ethan Yonker | 924a80b | 2014-04-02 10:54:12 -0500 | [diff] [blame] | 579 | tars[i].setpassword(password); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 580 | tars[i].thread_id = i; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 581 | tars[i].progress_pipe_fd = progress_pipe_fd; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 582 | tars[i].part_settings = part_settings; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 583 | LOGINFO("Creating extract thread ID %i\n", i); |
| 584 | ret = pthread_create(&tar_thread[i], &tattr, extractMulti, (void*)&tars[i]); |
| 585 | if (ret) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 586 | LOGINFO("Unable to create %i thread for extraction! %i\nContinuing in same thread (restore will be slower).\n", i, ret); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 587 | if (extractMulti((void*)&tars[i]) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 588 | LOGINFO("Error extracting backup in thread %i.\n", i); |
| 589 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 590 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 591 | _exit(-1); |
| 592 | } else { |
| 593 | tars[i].thread_id = i + 1; |
| 594 | } |
| 595 | } |
| 596 | usleep(100000); // Need a short delay before starting the next thread or the threads will never finish for some reason. |
| 597 | } else { |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | for (i = start_thread_id; i < thread_count + start_thread_id; i++) { |
| 602 | if (tars[i].thread_id == i) { |
| 603 | if (pthread_join(tar_thread[i], &thread_return)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 604 | LOGINFO("Error joining thread %i\n", i); |
| 605 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 606 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 607 | _exit(-1); |
| 608 | } else { |
| 609 | LOGINFO("Joined thread %i.\n", i); |
that | 2252d24 | 2015-04-03 22:33:04 +0200 | [diff] [blame] | 610 | ret = (int)(intptr_t)thread_return; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 611 | if (ret != 0) { |
| 612 | thread_error = 1; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 613 | LOGINFO("Thread %i returned an error %i.\n", i, ret); |
| 614 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 615 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 616 | _exit(-1); |
| 617 | } |
| 618 | } |
| 619 | } else { |
| 620 | LOGINFO("Skipping joining thread %i because of pthread failure.\n", i); |
| 621 | } |
| 622 | } |
| 623 | if (thread_error) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 624 | LOGINFO("Error returned by one or more threads.\n"); |
| 625 | gui_err("restore_error=Error during restore process."); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 626 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 627 | _exit(-1); |
| 628 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 629 | LOGINFO("Finished encrypted restore.\n"); |
| 630 | close(progress_pipe_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 631 | _exit(0); |
| 632 | } |
| 633 | } |
| 634 | else // parent process |
| 635 | { |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 636 | unsigned long long fs, size_backup = 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 637 | |
| 638 | // Parent closes output side |
| 639 | close(progress_pipe[1]); |
| 640 | |
| 641 | // Read progress data from children |
| 642 | while (read(progress_pipe[0], &fs, sizeof(fs)) > 0) { |
| 643 | size_backup += fs; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 644 | part_settings->progress->UpdateSize(size_backup); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 645 | } |
| 646 | close(progress_pipe[0]); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 647 | part_settings->progress->UpdateDisplayDetails(true); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 648 | |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 649 | if (TWFunc::Wait_For_Child(tar_fork_pid, &status, "extractTarFork()") != 0) |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 650 | return -1; |
| 651 | } |
| 652 | } |
| 653 | else // fork has failed |
| 654 | { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 655 | close(progress_pipe[0]); |
| 656 | close(progress_pipe[1]); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 657 | LOGINFO("extract tar failed to fork.\n"); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 658 | return -1; |
| 659 | } |
| 660 | return 0; |
| 661 | } |
| 662 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 663 | int twrpTar::Generate_TarList(string Path, std::vector<TarListStruct> *TarList, unsigned long long *Target_Size, unsigned *thread_id) { |
| 664 | DIR* d; |
| 665 | struct dirent* de; |
| 666 | struct stat st; |
| 667 | string FileName; |
| 668 | struct TarListStruct TarItem; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 669 | int ret, file_count; |
| 670 | file_count = 0; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 671 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 672 | d = opendir(Path.c_str()); |
| 673 | if (d == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 674 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(Path)(strerror(errno))); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 675 | closedir(d); |
| 676 | return -1; |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 677 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 678 | while ((de = readdir(d)) != NULL) { |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 679 | FileName = Path + "/" + de->d_name; |
Matt Mower | bb81e5d | 2014-03-20 18:05:41 -0500 | [diff] [blame] | 680 | |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 681 | if (de->d_type == DT_BLK || de->d_type == DT_CHR || backup_exclusions->check_skip_dirs(FileName)) |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 682 | continue; |
| 683 | TarItem.fn = FileName; |
| 684 | TarItem.thread_id = *thread_id; |
Matt Mower | 50248ab | 2014-03-31 15:58:40 -0500 | [diff] [blame] | 685 | if (de->d_type == DT_DIR) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 686 | TarList->push_back(TarItem); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 687 | ret = Generate_TarList(FileName, TarList, Target_Size, thread_id); |
| 688 | if (ret < 0) |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 689 | return -1; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 690 | file_count += ret; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 691 | } else if (de->d_type == DT_REG || de->d_type == DT_LNK) { |
| 692 | stat(FileName.c_str(), &st); |
| 693 | TarList->push_back(TarItem); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 694 | if (de->d_type == DT_REG) { |
| 695 | file_count++; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 696 | Archive_Current_Size += st.st_size; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 697 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 698 | if (Archive_Current_Size != 0 && *Target_Size != 0 && Archive_Current_Size > *Target_Size) { |
| 699 | *thread_id = *thread_id + 1; |
| 700 | Archive_Current_Size = 0; |
bigbiff bigbiff | e6594ab | 2013-02-17 20:18:31 -0500 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 704 | closedir(d); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 705 | return file_count; |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 706 | } |
| 707 | |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 708 | int twrpTar::extractTar() { |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 709 | char* charRootDir = (char*) tardir.c_str(); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 710 | if (openTar() == -1) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 711 | return -1; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 712 | if (tar_extract_all(t, charRootDir, &progress_pipe_fd) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 713 | LOGINFO("Unable to extract tar archive '%s'\n", tarfn.c_str()); |
| 714 | gui_err("restore_error=Error during restore process."); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 715 | return -1; |
| 716 | } |
| 717 | if (tar_close(t) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 718 | LOGINFO("Unable to close tar file\n"); |
| 719 | gui_err("restore_error=Error during restore process."); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 720 | return -1; |
| 721 | } |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 722 | #ifndef BUILD_TWRPTAR_MAIN |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 723 | if (part_settings->adbbackup) { |
| 724 | if (!twadbbu::Write_TWEOF()) |
| 725 | return -1; |
| 726 | } |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 727 | #endif |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 731 | int twrpTar::extract() { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 732 | if (!part_settings->adbbackup) { |
| 733 | LOGINFO("Setting archive type\n"); |
| 734 | Set_Archive_Type(TWFunc::Get_File_Type(tarfn)); |
| 735 | } |
| 736 | else { |
| 737 | if (part_settings->adb_compression == 1) |
| 738 | current_archive_type = COMPRESSED; |
| 739 | else |
| 740 | current_archive_type = UNCOMPRESSED; |
| 741 | } |
n0d3 | 3b51163 | 2013-03-06 21:14:15 +0200 | [diff] [blame] | 742 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 743 | if (current_archive_type == COMPRESSED) { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 744 | //if you return the extractTGZ function directly, stack crashes happen |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 745 | LOGINFO("Extracting gzipped tar\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 746 | int ret = extractTar(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 747 | return ret; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 748 | } else if (current_archive_type == ENCRYPTED) { |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 749 | int ret = TWFunc::Try_Decrypting_File(tarfn, password); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 750 | if (ret < 1) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 751 | gui_msg(Msg(msg::kError, "fail_decrypt_tar=Failed to decrypt tar file '{1}'")(tarfn)); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 752 | return -1; |
| 753 | } |
| 754 | if (ret == 1) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 755 | LOGINFO("Decrypted file is not in tar format.\n"); |
| 756 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 757 | return -1; |
| 758 | } |
| 759 | if (ret == 3) { |
| 760 | LOGINFO("Extracting encrypted and compressed tar.\n"); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 761 | current_archive_type = COMPRESSED_ENCRYPTED; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 762 | } else |
| 763 | LOGINFO("Extracting encrypted tar.\n"); |
| 764 | return extractTar(); |
| 765 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 766 | LOGINFO("Extracting uncompressed tar\n"); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 767 | return extractTar(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 771 | int twrpTar::tarList(std::vector<TarListStruct> *TarList, unsigned thread_id) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 772 | struct stat st; |
| 773 | char buf[PATH_MAX]; |
| 774 | int list_size = TarList->size(), i = 0, archive_count = 0; |
| 775 | string temp; |
| 776 | char actual_filename[PATH_MAX]; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 777 | unsigned long long fs; |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 778 | |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 779 | if (split_archives) { |
| 780 | basefn = tarfn; |
| 781 | temp = basefn + "%i%02i"; |
| 782 | sprintf(actual_filename, temp.c_str(), thread_id, archive_count); |
| 783 | tarfn = actual_filename; |
| 784 | include_root_dir = true; |
| 785 | } else { |
| 786 | include_root_dir = false; |
| 787 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 788 | |
| 789 | if (part_settings->adbbackup) |
| 790 | LOGINFO("Writing tar file '%s' to adb backup\n", tarfn.c_str()); |
| 791 | else |
| 792 | LOGINFO("Creating tar file '%s'\n", tarfn.c_str()); |
| 793 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 794 | if (createTar() != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 795 | LOGINFO("Error creating tar '%s' for thread %i\n", tarfn.c_str(), thread_id); |
| 796 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 797 | return -2; |
| 798 | } |
| 799 | Archive_Current_Size = 0; |
| 800 | |
| 801 | while (i < list_size) { |
| 802 | if (TarList->at(i).thread_id == thread_id) { |
| 803 | strcpy(buf, TarList->at(i).fn.c_str()); |
bigbiff bigbiff | ec8fc28 | 2014-03-16 20:32:50 -0400 | [diff] [blame] | 804 | lstat(buf, &st); |
| 805 | if (S_ISREG(st.st_mode)) { // item is a regular file |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 806 | fs = (unsigned long long)(st.st_size); |
| 807 | if (split_archives && Archive_Current_Size + fs > MAX_ARCHIVE_SIZE) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 808 | if (closeTar() != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 809 | LOGINFO("Error closing '%s' on thread %i\n", tarfn.c_str(), thread_id); |
| 810 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 811 | return -3; |
| 812 | } |
| 813 | archive_count++; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 814 | gui_msg(Msg("split_thread=Splitting thread ID {1} into archive {2}")(thread_id)(archive_count + 1)); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 815 | if (archive_count > 99) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 816 | LOGINFO("Too many archives for thread %i\n", thread_id); |
| 817 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 818 | return -4; |
| 819 | } |
| 820 | sprintf(actual_filename, temp.c_str(), thread_id, archive_count); |
| 821 | tarfn = actual_filename; |
| 822 | if (createTar() != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 823 | LOGINFO("Error creating tar '%s' for thread %i\n", tarfn.c_str(), thread_id); |
| 824 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 825 | return -2; |
| 826 | } |
| 827 | Archive_Current_Size = 0; |
| 828 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 829 | Archive_Current_Size += fs; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 830 | fs = 0; // Sending a 0 size to the pipe tells it to increment the file counter |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 831 | write(progress_pipe_fd, &fs, sizeof(fs)); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 832 | } |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 833 | LOGINFO("addFile '%s' including root: %i\n", buf, include_root_dir); |
| 834 | if (addFile(buf, include_root_dir) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 835 | LOGINFO("Error adding file '%s' to '%s'\n", buf, tarfn.c_str()); |
| 836 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 837 | return -1; |
| 838 | } |
| 839 | } |
| 840 | i++; |
| 841 | } |
| 842 | if (closeTar() != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 843 | LOGINFO("Error closing '%s' on thread %i\n", tarfn.c_str(), thread_id); |
| 844 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 845 | return -3; |
| 846 | } |
Ethan Yonker | bcc502c | 2014-11-10 11:22:10 -0600 | [diff] [blame] | 847 | LOGINFO("Thread id %i tarList done, %i archives.\n", thread_id, archive_count); |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 848 | return 0; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 849 | } |
| 850 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 851 | void* twrpTar::createList(void *cookie) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 852 | twrpTar* threadTar = (twrpTar*) cookie; |
Ethan Yonker | eae4209 | 2014-03-07 15:33:13 -0600 | [diff] [blame] | 853 | if (threadTar->tarList(threadTar->ItemList, threadTar->thread_id) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 854 | LOGINFO("ERROR tarList for thread ID %i\n", threadTar->thread_id); |
| 855 | return (void*)-2; |
| 856 | } |
| 857 | LOGINFO("Thread ID %i finished successfully.\n", threadTar->thread_id); |
| 858 | return (void*)0; |
| 859 | } |
| 860 | |
| 861 | void* twrpTar::extractMulti(void *cookie) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 862 | twrpTar* threadTar = (twrpTar*) cookie; |
| 863 | int archive_count = 0; |
| 864 | string temp = threadTar->basefn + "%i%02i"; |
| 865 | char actual_filename[255]; |
| 866 | sprintf(actual_filename, temp.c_str(), threadTar->thread_id, archive_count); |
| 867 | while (TWFunc::Path_Exists(actual_filename)) { |
| 868 | threadTar->tarfn = actual_filename; |
| 869 | if (threadTar->extract() != 0) { |
| 870 | LOGINFO("Error extracting '%s' in thread ID %i\n", actual_filename, threadTar->thread_id); |
| 871 | return (void*)-2; |
| 872 | } |
| 873 | archive_count++; |
| 874 | if (archive_count > 99) |
| 875 | break; |
| 876 | sprintf(actual_filename, temp.c_str(), threadTar->thread_id, archive_count); |
| 877 | } |
| 878 | LOGINFO("Thread ID %i finished successfully.\n", threadTar->thread_id); |
| 879 | return (void*)0; |
| 880 | } |
| 881 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 882 | int twrpTar::addFilesToExistingTar(vector <string> files, string fn) { |
| 883 | char* charTarFile = (char*) fn.c_str(); |
| 884 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 885 | if (tar_open(&t, charTarFile, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) == -1) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 886 | return -1; |
| 887 | removeEOT(charTarFile); |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 888 | if (tar_open(&t, charTarFile, NULL, O_CLOEXEC | O_WRONLY | O_APPEND | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) == -1) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 889 | return -1; |
| 890 | for (unsigned int i = 0; i < files.size(); ++i) { |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 891 | char* file = (char*) files.at(i).c_str(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 892 | if (tar_append_file(t, file, file) == -1) |
| 893 | return -1; |
| 894 | } |
| 895 | if (tar_append_eof(t) == -1) |
| 896 | return -1; |
| 897 | if (tar_close(t) == -1) |
| 898 | return -1; |
| 899 | return 0; |
| 900 | } |
| 901 | |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 902 | int twrpTar::createTar() { |
| 903 | char* charTarFile = (char*) tarfn.c_str(); |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 904 | char* charRootDir = (char*) tardir.c_str(); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 905 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 906 | if (use_encryption && use_compression) { |
| 907 | // Compressed and encrypted |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 908 | current_archive_type = COMPRESSED_ENCRYPTED; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 909 | LOGINFO("Using encryption and compression...\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 910 | int i, pipes[4]; |
| 911 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 912 | if (pipe2(pipes, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 913 | LOGINFO("Error creating first pipe\n"); |
| 914 | gui_err("backup_error=Error creating backup."); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 915 | return -1; |
| 916 | } |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 917 | if (pipe2(pipes + 2, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 918 | LOGINFO("Error creating second pipe\n"); |
| 919 | gui_err("backup_error=Error creating backup."); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 920 | return -1; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 921 | } |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 922 | output_fd = open(tarfn.c_str(), O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 923 | if (output_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 924 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 925 | for (i = 0; i < 4; i++) |
| 926 | close(pipes[i]); // close all |
| 927 | return -1; |
| 928 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 929 | pigz_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 930 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 931 | if (pigz_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 932 | LOGINFO("pigz fork() failed\n"); |
| 933 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 934 | close(output_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 935 | for (i = 0; i < 4; i++) |
| 936 | close(pipes[i]); // close all |
| 937 | return -1; |
| 938 | } else if (pigz_pid == 0) { |
| 939 | // pigz Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 940 | dup2(pipes[0], STDIN_FILENO); |
| 941 | dup2(pipes[3], STDOUT_FILENO); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 942 | if (execlp("pigz", "pigz", "-", NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 943 | LOGINFO("execlp pigz ERROR!\n"); |
| 944 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 945 | _exit(-1); |
| 946 | } |
| 947 | } else { |
| 948 | // Parent |
| 949 | oaes_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 950 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 951 | if (oaes_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 952 | LOGINFO("openaes fork() failed\n"); |
| 953 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 954 | close(output_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 955 | for (i = 0; i < 4; i++) |
| 956 | close(pipes[i]); // close all |
| 957 | return -1; |
| 958 | } else if (oaes_pid == 0) { |
| 959 | // openaes Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 960 | dup2(pipes[2], STDIN_FILENO); |
| 961 | dup2(output_fd, STDOUT_FILENO); |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 962 | if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 963 | LOGINFO("execlp openaes ERROR!\n"); |
| 964 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 965 | _exit(-1); |
| 966 | } |
| 967 | } else { |
| 968 | // Parent |
| 969 | close(pipes[0]); |
| 970 | close(pipes[2]); |
| 971 | close(pipes[3]); |
| 972 | fd = pipes[1]; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 973 | init_libtar_no_buffer(progress_pipe_fd); |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 974 | tar_type.writefunc = write_tar_no_buffer; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 975 | if (tar_fdopen(&t, fd, charRootDir, &tar_type, O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 976 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 977 | LOGINFO("tar_fdopen failed\n"); |
| 978 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 979 | return -1; |
| 980 | } |
| 981 | return 0; |
| 982 | } |
| 983 | } |
| 984 | } else if (use_compression) { |
| 985 | // Compressed |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 986 | current_archive_type = COMPRESSED; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 987 | LOGINFO("Using compression...\n"); |
| 988 | int pigzfd[2]; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 989 | if (part_settings->adbbackup) { |
| 990 | LOGINFO("opening TW_ADB_BACKUP compressed stream\n"); |
| 991 | output_fd = open(TW_ADB_BACKUP, O_WRONLY); |
| 992 | } |
| 993 | else { |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 994 | output_fd = open(tarfn.c_str(), O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 995 | } |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 996 | if (output_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 997 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 998 | return -1; |
| 999 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1000 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1001 | if (pipe2(pigzfd, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1002 | LOGINFO("Error creating pipe\n"); |
| 1003 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1004 | close(output_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1005 | return -1; |
| 1006 | } |
| 1007 | pigz_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 1008 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1009 | if (pigz_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1010 | LOGINFO("fork() failed\n"); |
| 1011 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1012 | close(output_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1013 | close(pigzfd[0]); |
| 1014 | close(pigzfd[1]); |
| 1015 | return -1; |
| 1016 | } else if (pigz_pid == 0) { |
| 1017 | // Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1018 | dup2(pigzfd[0], STDIN_FILENO); // remap stdin |
| 1019 | dup2(output_fd, STDOUT_FILENO); // remap stdout to output file |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1020 | if (execlp("pigz", "pigz", "-", NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1021 | LOGINFO("execlp pigz ERROR!\n"); |
| 1022 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1023 | _exit(-1); |
| 1024 | } |
| 1025 | } else { |
| 1026 | // Parent |
| 1027 | close(pigzfd[0]); // close parent input |
| 1028 | fd = pigzfd[1]; // copy parent output |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 1029 | init_libtar_no_buffer(progress_pipe_fd); |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 1030 | tar_type.writefunc = write_tar_no_buffer; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1031 | if (tar_fdopen(&t, fd, charRootDir, &tar_type, O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1032 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1033 | LOGINFO("tar_fdopen failed\n"); |
| 1034 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1035 | return -1; |
| 1036 | } |
| 1037 | } |
| 1038 | } else if (use_encryption) { |
| 1039 | // Encrypted |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1040 | current_archive_type = ENCRYPTED; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1041 | LOGINFO("Using encryption...\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1042 | int oaesfd[2]; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1043 | output_fd = open(tarfn.c_str(), O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1044 | if (output_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1045 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1046 | return -1; |
| 1047 | } |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1048 | if (pipe2(oaesfd, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1049 | LOGINFO("Error creating pipe\n"); |
| 1050 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1051 | close(output_fd); |
| 1052 | return -1; |
| 1053 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1054 | oaes_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 1055 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1056 | if (oaes_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1057 | LOGINFO("fork() failed\n"); |
| 1058 | gui_err("backup_error=Error creating backup."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1059 | close(output_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1060 | close(oaesfd[0]); |
| 1061 | close(oaesfd[1]); |
| 1062 | return -1; |
| 1063 | } else if (oaes_pid == 0) { |
| 1064 | // Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1065 | dup2(oaesfd[0], STDIN_FILENO); // remap stdin |
| 1066 | dup2(output_fd, STDOUT_FILENO); // remap stdout to output file |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 1067 | if (execlp("openaes", "openaes", "enc", "--key", password.c_str(), NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1068 | LOGINFO("execlp openaes ERROR!\n"); |
| 1069 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1070 | _exit(-1); |
| 1071 | } |
| 1072 | } else { |
| 1073 | // Parent |
| 1074 | close(oaesfd[0]); // close parent input |
| 1075 | fd = oaesfd[1]; // copy parent output |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 1076 | init_libtar_no_buffer(progress_pipe_fd); |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 1077 | tar_type.writefunc = write_tar_no_buffer; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1078 | if (tar_fdopen(&t, fd, charRootDir, &tar_type, O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1079 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1080 | LOGINFO("tar_fdopen failed\n"); |
| 1081 | gui_err("backup_error=Error creating backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1082 | return -1; |
| 1083 | } |
| 1084 | return 0; |
| 1085 | } |
| 1086 | } else { |
| 1087 | // Not compressed or encrypted |
nkk71 | d59d02e | 2017-06-29 15:16:23 +0300 | [diff] [blame] | 1088 | current_archive_type = UNCOMPRESSED; |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 1089 | init_libtar_buffer(0, progress_pipe_fd); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1090 | if (part_settings->adbbackup) { |
| 1091 | LOGINFO("Opening TW_ADB_BACKUP uncompressed stream\n"); |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 1092 | tar_type.writefunc = write_tar_no_buffer; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1093 | output_fd = open(TW_ADB_BACKUP, O_WRONLY); |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1094 | if(tar_fdopen(&t, output_fd, charRootDir, &tar_type, O_CLOEXEC | O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1095 | close(output_fd); |
| 1096 | LOGERR("tar_fdopen failed\n"); |
| 1097 | return -1; |
| 1098 | } |
| 1099 | } |
| 1100 | else { |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 1101 | tar_type.writefunc = write_tar; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1102 | if (tar_open(&t, charTarFile, &tar_type, O_CLOEXEC | O_WRONLY | O_CREAT | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) == -1) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1103 | LOGERR("tar_open error opening '%s'\n", tarfn.c_str()); |
| 1104 | gui_err("backup_error=Error creating backup."); |
| 1105 | return -1; |
| 1106 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1107 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1108 | } |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1112 | int twrpTar::openTar() { |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 1113 | char* charRootDir = (char*) tardir.c_str(); |
| 1114 | char* charTarFile = (char*) tarfn.c_str(); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1115 | string Password; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1116 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1117 | if (current_archive_type == COMPRESSED_ENCRYPTED) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1118 | LOGINFO("Opening encrypted and compressed backup...\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1119 | int i, pipes[4]; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1120 | input_fd = open(tarfn.c_str(), O_CLOEXEC | O_RDONLY | O_LARGEFILE); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1121 | if (input_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1122 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1123 | return -1; |
| 1124 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1125 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1126 | if (pipe2(pipes, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1127 | LOGINFO("Error creating first pipe\n"); |
| 1128 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1129 | close(input_fd); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1130 | return -1; |
| 1131 | } |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1132 | if (pipe2(pipes + 2, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1133 | LOGINFO("Error creating second pipe\n"); |
| 1134 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1135 | close(pipes[0]); |
| 1136 | close(pipes[1]); |
| 1137 | close(input_fd); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1138 | return -1; |
| 1139 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1140 | oaes_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 1141 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1142 | if (oaes_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1143 | LOGINFO("pigz fork() failed\n"); |
| 1144 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1145 | close(input_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1146 | for (i = 0; i < 4; i++) |
| 1147 | close(pipes[i]); // close all |
| 1148 | return -1; |
| 1149 | } else if (oaes_pid == 0) { |
| 1150 | // openaes Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1151 | dup2(input_fd, STDIN_FILENO); |
| 1152 | dup2(pipes[1], STDOUT_FILENO); |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 1153 | if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1154 | LOGINFO("execlp openaes ERROR!\n"); |
| 1155 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1156 | _exit(-1); |
| 1157 | } |
| 1158 | } else { |
| 1159 | // Parent |
| 1160 | pigz_pid = fork(); |
bigbiff bigbiff | 86e77bc | 2013-08-26 21:36:23 -0400 | [diff] [blame] | 1161 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1162 | if (pigz_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1163 | LOGINFO("openaes fork() failed\n"); |
| 1164 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1165 | close(input_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1166 | for (i = 0; i < 4; i++) |
| 1167 | close(pipes[i]); // close all |
| 1168 | return -1; |
| 1169 | } else if (pigz_pid == 0) { |
| 1170 | // pigz Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1171 | dup2(pipes[0], STDIN_FILENO); |
| 1172 | dup2(pipes[3], STDOUT_FILENO); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1173 | if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1174 | LOGINFO("execlp pigz ERROR!\n"); |
| 1175 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1176 | _exit(-1); |
| 1177 | } |
| 1178 | } else { |
| 1179 | // Parent |
| 1180 | close(pipes[0]); // Close pipes not used by parent |
| 1181 | close(pipes[1]); |
| 1182 | close(pipes[3]); |
| 1183 | fd = pipes[2]; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1184 | if (tar_fdopen(&t, fd, charRootDir, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1185 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1186 | LOGINFO("tar_fdopen failed\n"); |
| 1187 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1188 | return -1; |
| 1189 | } |
| 1190 | } |
| 1191 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1192 | } else if (current_archive_type == ENCRYPTED) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1193 | LOGINFO("Opening encrypted backup...\n"); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1194 | int oaesfd[2]; |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1195 | input_fd = open(tarfn.c_str(), O_CLOEXEC | O_RDONLY | O_LARGEFILE); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1196 | if (input_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1197 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1198 | return -1; |
| 1199 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1200 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1201 | if (pipe2(oaesfd, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1202 | LOGINFO("Error creating pipe\n"); |
| 1203 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1204 | close(input_fd); |
| 1205 | return -1; |
| 1206 | } |
| 1207 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1208 | oaes_pid = fork(); |
| 1209 | if (oaes_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1210 | LOGINFO("fork() failed\n"); |
| 1211 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1212 | close(input_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1213 | close(oaesfd[0]); |
| 1214 | close(oaesfd[1]); |
| 1215 | return -1; |
| 1216 | } else if (oaes_pid == 0) { |
| 1217 | // Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1218 | dup2(oaesfd[1], STDOUT_FILENO); // remap stdout |
| 1219 | dup2(input_fd, STDIN_FILENO); // remap input fd to stdin |
Ethan Yonker | 87af563 | 2014-02-10 11:56:35 -0600 | [diff] [blame] | 1220 | if (execlp("openaes", "openaes", "dec", "--key", password.c_str(), NULL) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1221 | LOGINFO("execlp openaes ERROR!\n"); |
| 1222 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1223 | _exit(-1); |
| 1224 | } |
| 1225 | } else { |
| 1226 | // Parent |
| 1227 | close(oaesfd[1]); // close parent output |
| 1228 | fd = oaesfd[0]; // copy parent input |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1229 | if (tar_fdopen(&t, fd, charRootDir, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1230 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1231 | LOGINFO("tar_fdopen failed\n"); |
| 1232 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1233 | return -1; |
| 1234 | } |
| 1235 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1236 | } else if (current_archive_type == COMPRESSED) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1237 | int pigzfd[2]; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1238 | |
bigbiff bigbiff | adcb4d8 | 2017-09-25 10:51:56 -0400 | [diff] [blame] | 1239 | LOGINFO("Opening gzip compressed tar...\n"); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1240 | if (part_settings->adbbackup) { |
| 1241 | LOGINFO("opening TW_ADB_RESTORE compressed stream\n"); |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1242 | input_fd = open(TW_ADB_RESTORE, O_CLOEXEC | O_RDONLY | O_LARGEFILE); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1243 | } |
| 1244 | else |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1245 | input_fd = open(tarfn.c_str(), O_CLOEXEC | O_RDONLY | O_LARGEFILE); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1246 | |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1247 | if (input_fd < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1248 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(tarfn)(strerror(errno))); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1249 | return -1; |
| 1250 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1251 | |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1252 | if (pipe2(pigzfd, O_CLOEXEC) < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1253 | LOGINFO("Error creating pipe\n"); |
| 1254 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1255 | close(input_fd); |
| 1256 | return -1; |
| 1257 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1258 | |
| 1259 | pigz_pid = fork(); |
| 1260 | if (pigz_pid < 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1261 | LOGINFO("fork() failed\n"); |
| 1262 | gui_err("restore_error=Error during restore process."); |
Dees Troy | 9d72327 | 2014-04-07 17:13:10 +0000 | [diff] [blame] | 1263 | close(input_fd); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1264 | close(pigzfd[0]); |
| 1265 | close(pigzfd[1]); |
| 1266 | return -1; |
| 1267 | } else if (pigz_pid == 0) { |
| 1268 | // Child |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1269 | dup2(pigzfd[1], STDOUT_FILENO); // remap stdout |
| 1270 | dup2(input_fd, STDIN_FILENO); // remap input fd to stdin |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1271 | if (execlp("pigz", "pigz", "-d", "-c", NULL) < 0) { |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1272 | LOGINFO("execlp pigz ERROR!\n"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1273 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1274 | _exit(-1); |
| 1275 | } |
| 1276 | } else { |
| 1277 | // Parent |
| 1278 | close(pigzfd[1]); // close parent output |
| 1279 | fd = pigzfd[0]; // copy parent input |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1280 | if (tar_fdopen(&t, fd, charRootDir, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1281 | close(fd); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1282 | LOGINFO("tar_fdopen failed\n"); |
| 1283 | gui_err("restore_error=Error during restore process."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1284 | return -1; |
| 1285 | } |
| 1286 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1287 | } else { |
| 1288 | if (part_settings->adbbackup) { |
| 1289 | LOGINFO("Opening TW_ADB_RESTORE uncompressed stream\n"); |
| 1290 | input_fd = open(TW_ADB_RESTORE, O_RDONLY); |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1291 | if (tar_fdopen(&t, input_fd, charRootDir, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1292 | LOGERR("Unable to open tar archive '%s'\n", charTarFile); |
| 1293 | gui_err("restore_error=Error during restore process."); |
| 1294 | return -1; |
| 1295 | } |
| 1296 | } |
| 1297 | else { |
Fabrice Bellet | 72bcc20 | 2019-12-15 17:49:18 +0100 | [diff] [blame] | 1298 | if (tar_open(&t, charTarFile, NULL, O_CLOEXEC | O_RDONLY | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, TWTAR_FLAGS) != 0) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1299 | LOGERR("Unable to open tar archive '%s'\n", charTarFile); |
| 1300 | gui_err("restore_error=Error during restore process."); |
| 1301 | return -1; |
| 1302 | } |
| 1303 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1304 | } |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | string twrpTar::Strip_Root_Dir(string Path) { |
| 1309 | string temp; |
| 1310 | size_t slash; |
| 1311 | |
| 1312 | if (Path.substr(0, 1) == "/") |
| 1313 | temp = Path.substr(1, Path.size() - 1); |
| 1314 | else |
| 1315 | temp = Path; |
| 1316 | slash = temp.find("/"); |
| 1317 | if (slash == string::npos) |
| 1318 | return temp; |
| 1319 | else { |
| 1320 | string stripped; |
| 1321 | |
| 1322 | stripped = temp.substr(slash, temp.size() - slash); |
| 1323 | return stripped; |
| 1324 | } |
| 1325 | return temp; |
| 1326 | } |
| 1327 | |
| 1328 | int twrpTar::addFile(string fn, bool include_root) { |
| 1329 | char* charTarFile = (char*) fn.c_str(); |
| 1330 | if (include_root) { |
| 1331 | if (tar_append_file(t, charTarFile, NULL) == -1) |
| 1332 | return -1; |
| 1333 | } else { |
| 1334 | string temp = Strip_Root_Dir(fn); |
| 1335 | char* charTarPath = (char*) temp.c_str(); |
| 1336 | if (tar_append_file(t, charTarFile, charTarPath) == -1) |
| 1337 | return -1; |
| 1338 | } |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1342 | int twrpTar::closeTar() { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1343 | LOGINFO("Closing tar\n"); |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 1344 | flush_libtar_buffer(t->fd); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1345 | if (tar_append_eof(t) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1346 | LOGINFO("tar_append_eof(): %s\n", strerror(errno)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1347 | tar_close(t); |
| 1348 | return -1; |
| 1349 | } |
| 1350 | if (tar_close(t) != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1351 | LOGINFO("Unable to close tar archive: '%s'\n", tarfn.c_str()); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1352 | return -1; |
| 1353 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1354 | if (current_archive_type > 0) { |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1355 | int status; |
| 1356 | if (pigz_pid > 0 && TWFunc::Wait_For_Child(pigz_pid, &status, "pigz") != 0) |
| 1357 | return -1; |
| 1358 | if (oaes_pid > 0 && TWFunc::Wait_For_Child(oaes_pid, &status, "openaes") != 0) |
| 1359 | return -1; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1360 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1361 | free_libtar_buffer(); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1362 | if (!part_settings->adbbackup) { |
| 1363 | if (use_compression && !use_encryption) { |
| 1364 | string gzname = tarfn + ".gz"; |
| 1365 | if (TWFunc::Path_Exists(gzname)) { |
| 1366 | rename(gzname.c_str(), tarfn.c_str()); |
| 1367 | } |
Dees Troy | e0a433a | 2013-12-02 04:10:37 +0000 | [diff] [blame] | 1368 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1369 | if (TWFunc::Get_File_Size(tarfn) == 0) { |
| 1370 | gui_msg(Msg(msg::kError, "backup_size=Backup file size for '{1}' is 0 bytes.")(tarfn)); |
| 1371 | return -1; |
| 1372 | } |
Ethan Yonker | 960f030 | 2014-12-21 21:54:00 -0600 | [diff] [blame] | 1373 | #ifndef BUILD_TWRPTAR_MAIN |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1374 | tw_set_default_metadata(tarfn.c_str()); |
Ethan Yonker | 960f030 | 2014-12-21 21:54:00 -0600 | [diff] [blame] | 1375 | #endif |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1376 | } |
| 1377 | else { |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 1378 | #ifndef BUILD_TWRPTAR_MAIN |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1379 | if (!twadbbu::Write_TWEOF()) |
| 1380 | return -1; |
Ethan Yonker | 3fdcda4 | 2016-11-30 12:29:37 -0600 | [diff] [blame] | 1381 | #endif |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1382 | } |
Ethan Yonker | ea2fcf0 | 2016-09-12 16:07:19 -0500 | [diff] [blame] | 1383 | if (input_fd >= 0) |
| 1384 | close(input_fd); |
| 1385 | if (output_fd >= 0) |
| 1386 | close(output_fd); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1387 | return 0; |
| 1388 | } |
| 1389 | |
| 1390 | int twrpTar::removeEOT(string tarFile) { |
| 1391 | char* charTarFile = (char*) tarFile.c_str(); |
Matt Mower | 2b18a53 | 2015-02-20 16:58:05 -0600 | [diff] [blame] | 1392 | off_t tarFileEnd = 0; |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1393 | while (th_read(t) == 0) { |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1394 | if (TH_ISREG(t)) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1395 | tar_skip_regfile(t); |
| 1396 | tarFileEnd = lseek(t->fd, 0, SEEK_CUR); |
bigbiff bigbiff | 3bf2b0e | 2013-01-21 21:26:43 -0500 | [diff] [blame] | 1397 | } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1398 | if (tar_close(t) == -1) |
| 1399 | return -1; |
Matt Mower | 2b18a53 | 2015-02-20 16:58:05 -0600 | [diff] [blame] | 1400 | if (tarFileEnd > 0 && truncate(charTarFile, tarFileEnd) == -1) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1401 | return -1; |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
n0d3 | 3b51163 | 2013-03-06 21:14:15 +0200 | [diff] [blame] | 1405 | int twrpTar::entryExists(string entry) { |
| 1406 | char* searchstr = (char*)entry.c_str(); |
| 1407 | int ret; |
| 1408 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1409 | Set_Archive_Type(TWFunc::Get_File_Type(tarfn)); |
n0d3 | 3b51163 | 2013-03-06 21:14:15 +0200 | [diff] [blame] | 1410 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1411 | if (openTar() == -1) |
n0d3 | 3b51163 | 2013-03-06 21:14:15 +0200 | [diff] [blame] | 1412 | ret = 0; |
| 1413 | else |
| 1414 | ret = tar_find(t, searchstr); |
| 1415 | |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1416 | if (closeTar() != 0) |
| 1417 | LOGINFO("Unable to close tar after searching for entry.\n"); |
n0d3 | 3b51163 | 2013-03-06 21:14:15 +0200 | [diff] [blame] | 1418 | |
| 1419 | return ret; |
| 1420 | } |
| 1421 | |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1422 | unsigned long long twrpTar::get_size() { |
bigbiff bigbiff | b5ecaad | 2017-03-20 18:53:53 -0400 | [diff] [blame] | 1423 | if (part_settings->adbbackup || TWFunc::Path_Exists(tarfn)) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1424 | LOGINFO("Single archive\n"); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1425 | return uncompressedSize(tarfn); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1426 | } else { |
| 1427 | LOGINFO("Multiple archives\n"); |
| 1428 | string temp; |
| 1429 | char actual_filename[255]; |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1430 | int archive_count = 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1431 | unsigned long long total_restore_size = 0; |
| 1432 | |
| 1433 | basefn = tarfn; |
| 1434 | temp = basefn + "%i%02i"; |
| 1435 | tarfn += "000"; |
| 1436 | thread_id = 0; |
| 1437 | sprintf(actual_filename, temp.c_str(), thread_id, archive_count); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1438 | if (!part_settings->adbbackup) { |
| 1439 | if (!TWFunc::Path_Exists(actual_filename)) { |
| 1440 | LOGERR("Unable to locate '%s' or '%s'\n", basefn.c_str(), tarfn.c_str()); |
| 1441 | return 0; |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1442 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1443 | for (int i = 0; i < 9; i++) { |
| 1444 | archive_count = 0; |
| 1445 | sprintf(actual_filename, temp.c_str(), i, archive_count); |
| 1446 | while (TWFunc::Path_Exists(actual_filename)) { |
| 1447 | total_restore_size += uncompressedSize(actual_filename); |
| 1448 | archive_count++; |
| 1449 | if (archive_count > 99) |
| 1450 | break; |
| 1451 | sprintf(actual_filename, temp.c_str(), i, archive_count); |
| 1452 | } |
| 1453 | } |
| 1454 | #ifndef BUILD_TWRPTAR_MAIN |
| 1455 | if (!part_settings->adbbackup) { |
| 1456 | InfoManager backup_info(tarfn + ".info"); |
| 1457 | backup_info.SetValue("backup_size", total_restore_size); |
| 1458 | backup_info.SetValue("backup_type", current_archive_type); |
| 1459 | backup_info.SaveValues(); |
| 1460 | } |
| 1461 | #endif //ndef BUILD_TWRPTAR_MAIN |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1462 | } |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1463 | return total_restore_size; |
| 1464 | } |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1468 | unsigned long long twrpTar::uncompressedSize(string filename) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1469 | unsigned long long total_size = 0; |
| 1470 | string Tar, Command, result; |
| 1471 | vector<string> split; |
| 1472 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1473 | Set_Archive_Type(TWFunc::Get_File_Type(tarfn)); |
| 1474 | if (current_archive_type == UNCOMPRESSED) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1475 | total_size = TWFunc::Get_File_Size(filename); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1476 | } else if (current_archive_type == COMPRESSED) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1477 | // Compressed |
| 1478 | Command = "pigz -l '" + filename + "'"; |
| 1479 | /* if we set Command = "pigz -l " + tarfn + " | sed '1d' | cut -f5 -d' '"; |
| 1480 | we get the uncompressed size at once. */ |
bigbiff | ad58e1b | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 1481 | TWFunc::Exec_Cmd(Command, result, false); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1482 | if (!result.empty()) { |
| 1483 | /* Expected output: |
| 1484 | compressed original reduced name |
| 1485 | 95855838 179403776 -1.3% data.yaffs2.win |
| 1486 | ^ |
| 1487 | split[5] |
| 1488 | */ |
| 1489 | split = TWFunc::split_string(result, ' ', true); |
| 1490 | if (split.size() > 4) |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1491 | total_size = atoi(split[5].c_str()); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1492 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1493 | } else if (current_archive_type == COMPRESSED_ENCRYPTED) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1494 | // File is encrypted and may be compressed |
| 1495 | int ret = TWFunc::Try_Decrypting_File(filename, password); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1496 | if (ret < 1) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1497 | gui_msg(Msg(msg::kError, "fail_decrypt_tar=Failed to decrypt tar file '{1}'")(tarfn)); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1498 | total_size = TWFunc::Get_File_Size(filename); |
| 1499 | } else if (ret == 1) { |
| 1500 | LOGERR("Decrypted file is not in tar format.\n"); |
| 1501 | total_size = TWFunc::Get_File_Size(filename); |
| 1502 | } else if (ret == 3) { |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1503 | Command = "openaes dec --key \"" + password + "\" --in '" + filename + "' | pigz -l"; |
| 1504 | /* if we set Command = "pigz -l " + tarfn + " | sed '1d' | cut -f5 -d' '"; |
| 1505 | we get the uncompressed size at once. */ |
bigbiff | ad58e1b | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 1506 | TWFunc::Exec_Cmd(Command, result, false); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1507 | if (!result.empty()) { |
| 1508 | LOGINFO("result was: '%s'\n", result.c_str()); |
| 1509 | /* Expected output: |
| 1510 | compressed original reduced name |
| 1511 | 95855838 179403776 -1.3% data.yaffs2.win |
| 1512 | ^ |
| 1513 | split[5] |
| 1514 | */ |
| 1515 | split = TWFunc::split_string(result, ' ', true); |
| 1516 | if (split.size() > 4) |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1517 | total_size = atoi(split[5].c_str()); |
Ethan Yonker | 1b7a31b | 2014-07-03 15:09:22 -0500 | [diff] [blame] | 1518 | } |
| 1519 | } else { |
| 1520 | total_size = TWFunc::Get_File_Size(filename); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | return total_size; |
| 1525 | } |
| 1526 | |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 1527 | extern "C" ssize_t write_tar(int fd, const void *buffer, size_t size) { |
| 1528 | return (ssize_t) write_libtar_buffer(fd, buffer, size); |
Dees_Troy | 40bbcf8 | 2013-02-12 15:01:53 +0000 | [diff] [blame] | 1529 | } |
Ethan Yonker | 472f506 | 2016-02-25 13:47:30 -0600 | [diff] [blame] | 1530 | |
| 1531 | extern "C" ssize_t write_tar_no_buffer(int fd, const void *buffer, size_t size) { |
| 1532 | return (ssize_t) write_libtar_no_buffer(fd, buffer, size); |
| 1533 | } |