bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1 | /* |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 2 | Copyright 2013 to 2017 TeamWin |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 3 | TWRP is free software: you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation, either version 3 of the License, or |
| 6 | (at your option) any later version. |
| 7 | |
| 8 | TWRP is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 17 | #ifndef _TWRPBACK_HPP |
| 18 | #define _TWRPBACK_HPP |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 19 | |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 20 | #include <fstream> |
bigbiff bigbiff | adcb4d8 | 2017-09-25 10:51:56 -0400 | [diff] [blame] | 21 | #include "../twrpDigest/twrpMD5.hpp" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 22 | |
| 23 | class twrpback { |
| 24 | public: |
| 25 | int adbd_fd; // adbd data stream |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 26 | twrpback(void); |
| 27 | virtual ~twrpback(void); |
bigbiff bigbiff | adcb4d8 | 2017-09-25 10:51:56 -0400 | [diff] [blame] | 28 | bool backup(std::string command); // adb backup stream |
| 29 | bool restore(void); // adb restore stream |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 30 | void adblogwrite(std::string writemsg); // adb debugging log function |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 31 | void createFifos(void); // create fifos needed for adb backup |
| 32 | void closeFifos(void); // close created fifos |
| 33 | void streamFileForTWRP(void); // stream file to twrp via bu |
| 34 | void setStreamFileName(std::string fn); // tell adb backup what file to load on storage |
| 35 | void threadStream(void); // thread bu for streaming |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 36 | |
| 37 | private: |
| 38 | int read_fd; // ors input fd |
| 39 | int write_fd; // ors operation fd |
| 40 | int ors_fd; // ors output fd |
| 41 | int adb_control_twrp_fd; // fd for bu to twrp communication |
| 42 | int adb_control_bu_fd; // fd for twrp to bu communication |
| 43 | int adb_read_fd; // adb read data stream |
| 44 | int adb_write_fd; // adb write data stream |
bigbiff bigbiff | 38b83c1 | 2017-12-28 19:58:52 -0500 | [diff] [blame] | 45 | int debug_adb_fd; // fd to write debug tars |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 46 | bool firstPart; // first partition in the stream |
| 47 | FILE *adbd_fp; // file pointer for adb stream |
| 48 | char cmd[512]; // store result of commands |
| 49 | char operation[512]; // operation to send to ors |
| 50 | std::ofstream adblogfile; // adb stream log file |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 51 | std::string streamFn; |
| 52 | typedef void (twrpback::*ThreadPtr)(void); |
| 53 | typedef void* (*PThreadPtr)(void *); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 54 | void adbloginit(void); // setup adb log stream file |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 55 | void close_backup_fds(); // close backup resources |
| 56 | void close_restore_fds(); // close restore resources |
bigbiff bigbiff | adcb4d8 | 2017-09-25 10:51:56 -0400 | [diff] [blame] | 57 | bool checkMD5Trailer(char adbReadStream[], uint64_t md5fnsize, twrpMD5* digest); // Check MD5 Trailer |
bigbiff bigbiff | 38b83c1 | 2017-12-28 19:58:52 -0500 | [diff] [blame] | 58 | void printErrMsg(std::string msg, int errNum); // print error msg to adb log |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 59 | }; |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 60 | |
| 61 | #endif // _TWRPBACK_HPP |