Commit adcb4d8c authored by bigbiff bigbiff's avatar bigbiff bigbiff Committed by Dees Troy

ADB Backup: Fix gzip backup and restore

Change-Id: I92821c7053089d130a5ab73fa36aec486da77bf1
parent 19fb79c7
......@@ -31,7 +31,8 @@
int main(int argc, char **argv) {
int index;
int ret = 0, pos = 0;
int pos = 0;
bool ret = false;
int maxpos = sizeof(TWRPARG + 2);
std::string command;
twrpback tw;
......@@ -73,8 +74,9 @@ int main(int argc, char **argv) {
else if (command.substr(0, sizeof(TWRP_STREAM_ARG) - 1) == TWRP_STREAM_ARG) {
tw.setStreamFileName(argv[3]);
tw.threadStream();
ret = true;
}
if (ret == 0)
if (ret)
tw.adblogwrite("Adb backup/restore completed\n");
else
tw.adblogwrite("Adb backup/restore failed\n");
......@@ -85,5 +87,8 @@ int main(int argc, char **argv) {
tw.adblogwrite("Unable to remove TW_ADB_BU_CONTROL: " + str.str());
}
unlink(TW_ADB_TWRP_CONTROL);
return ret;
if (ret)
return 0;
else
return -1;
}
......@@ -33,6 +33,7 @@
#include "twadbstream.h"
#include "libtwadbbu.hpp"
#include "twrpback.hpp"
bool twadbbu::Check_ADB_Backup_File(std::string fname) {
struct AdbBackupStreamHeader adbbuhdr;
......@@ -290,3 +291,16 @@ bool twadbbu::Write_TWENDADB() {
close(adb_control_bu_fd);
return true;
}
bool twadbbu::Write_TWDATA(FILE* adbd_fp) {
struct AdbBackupControlType data_block;
memset(&data_block, 0, sizeof(data_block));
strncpy(data_block.start_of_header, TWRP, sizeof(data_block.start_of_header));
strncpy(data_block.type, TWDATA, sizeof(data_block.type));
data_block.crc = crc32(0L, Z_NULL, 0);
data_block.crc = crc32(data_block.crc, (const unsigned char*) &data_block, sizeof(data_block));
if (fwrite(&data_block, 1, sizeof(data_block), adbd_fp) != sizeof(data_block)) {
return false;
}
return true;
}
......@@ -33,7 +33,6 @@
#include <sstream>
#include "twadbstream.h"
#include "twrpback.hpp"
class twadbbu {
public:
......@@ -46,6 +45,7 @@ public:
static bool Write_TWEOF(); //Write ADB End-Of-File marker to stream
static bool Write_TWERROR(); //Write error message occurred to stream
static bool Write_TWENDADB(); //Write ADB End-Of-Stream command to stream
static bool Write_TWDATA(FILE* adbd_fp); //Write TWDATA separator
};
#endif //__LIBTWADBBU_HPP
......@@ -39,7 +39,7 @@
#define TWMD5 "twverifymd5" //This command is compared to the md5trailer by ORS to verify transfer
#define TWENDADB "twendadb" //End Protocol
#define TWERROR "twerror" //Send error
#define ADB_BACKUP_VERSION 1 //Backup Version
#define ADB_BACKUP_VERSION 2 //Backup Version
#define DATA_MAX_CHUNK_SIZE 1048576 //Maximum size between each data header
#define MAX_ADB_READ 512 //align with default tar size for amount to read fom adb stream
......
This diff is collapsed.
......@@ -18,14 +18,15 @@
#define _TWRPBACK_HPP
#include <fstream>
#include "../twrpDigest/twrpMD5.hpp"
class twrpback {
public:
int adbd_fd; // adbd data stream
twrpback(void);
virtual ~twrpback(void);
int backup(std::string command); // adb backup stream
int restore(void); // adb restore stream
bool backup(std::string command); // adb backup stream
bool restore(void); // adb restore stream
void adblogwrite(std::string writemsg); // adb debugging log function
void createFifos(void); // create fifos needed for adb backup
void closeFifos(void); // close created fifos
......@@ -52,6 +53,7 @@ private:
void adbloginit(void); // setup adb log stream file
void close_backup_fds(); // close backup resources
void close_restore_fds(); // close restore resources
bool checkMD5Trailer(char adbReadStream[], uint64_t md5fnsize, twrpMD5* digest); // Check MD5 Trailer
};
#endif // _TWRPBACK_HPP
......@@ -39,8 +39,9 @@ twrpAdbBuFifo::twrpAdbBuFifo(void) {
unlink(TW_ADB_FIFO);
}
bool twrpAdbBuFifo::Check_Adb_Fifo_For_Events(void) {
void twrpAdbBuFifo::Check_Adb_Fifo_For_Events(void) {
char cmd[512];
int ret;
memset(&cmd, 0, sizeof(cmd));
......@@ -51,13 +52,11 @@ bool twrpAdbBuFifo::Check_Adb_Fifo_For_Events(void) {
std::string Options(cmd);
Options = Options.substr(strlen(ADB_BACKUP_OP) + 1, strlen(cmd));
if (cmdcheck == ADB_BACKUP_OP)
return Backup_ADB_Command(Options);
Backup_ADB_Command(Options);
else {
return Restore_ADB_Backup();
Restore_ADB_Backup();
}
}
return true;
}
bool twrpAdbBuFifo::start(void) {
......@@ -195,8 +194,7 @@ bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
memset(&cmdstruct, 0, sizeof(cmdstruct));
memcpy(&cmdstruct, cmd, sizeof(cmdstruct));
std::string cmdstr(cmdstruct.type);
std::string cmdtype = cmdstr.substr(0, sizeof(cmdstruct.type) - 1);
std::string cmdtype = cmdstruct.get_type();
if (cmdtype == TWSTREAMHDR) {
struct AdbBackupStreamHeader twhdr;
memcpy(&twhdr, cmd, sizeof(cmd));
......@@ -229,6 +227,8 @@ bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
LOGINFO("adbrestore md5 matches\n");
LOGINFO("adbmd5.md5: %s\n", adbmd5.md5);
LOGINFO("md5check.md5: %s\n", md5check.md5);
ret = true;
break;
}
}
else if (cmdtype == TWENDADB) {
......@@ -269,7 +269,7 @@ bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
part_settings.progress = &progress;
if (!PartitionManager.Restore_Partition(&part_settings)) {
LOGERR("ADB Restore failed.\n");
return false;
ret = false;
}
}
else if (cmdtype == TWFN) {
......@@ -319,18 +319,24 @@ bool twrpAdbBuFifo::Restore_ADB_Backup(void) {
part_settings.progress = &progress;
if (!PartitionManager.Restore_Partition(&part_settings)) {
LOGERR("ADB Restore failed.\n");
return false;
ret = false;
}
}
}
}
}
gui_msg("restore_complete=Restore Complete");
if (ret != false)
gui_msg("restore_complete=Restore Complete");
else
gui_err("restore_error=Error during restore process.");
if (!twadbbu::Write_TWENDADB())
ret = false;
sleep(2); //give time for user to see messages on console
DataManager::SetValue("ui_progress", 100);
gui_changePage("main");
close(adb_control_bu_fd);
close(adb_control_twrp_fd);
return ret;
}
......@@ -31,7 +31,7 @@ class twrpAdbBuFifo {
private:
bool start(void);
bool Backup_ADB_Command(std::string Options);
bool Check_Adb_Fifo_For_Events(void);
void Check_Adb_Fifo_For_Events(void);
bool Restore_ADB_Backup(void);
typedef bool (twrpAdbBuFifo::*ThreadPtr)(void);
typedef void* (*PThreadPtr)(void *);
......
......@@ -1276,7 +1276,7 @@ int twrpTar::openTar() {
} else if (current_archive_type == COMPRESSED) {
int pigzfd[2];
LOGINFO("Opening as a gzip...\n");
LOGINFO("Opening gzip compressed tar...\n");
if (part_settings->adbbackup) {
LOGINFO("opening TW_ADB_RESTORE compressed stream\n");
input_fd = open(TW_ADB_RESTORE, O_RDONLY | O_LARGEFILE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment