Skip to content

Commit

Permalink
ADB Backup: Fix gzip backup and restore
Browse files Browse the repository at this point in the history
Change-Id: I92821c7053089d130a5ab73fa36aec486da77bf1
  • Loading branch information
bigbiff authored and Dees-Troy committed Nov 27, 2017
1 parent 19fb79c commit adcb4d8
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 204 deletions.
11 changes: 8 additions & 3 deletions adbbu/adbbumain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
14 changes: 14 additions & 0 deletions adbbu/libtwadbbu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion adbbu/libtwadbbu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <sstream>

#include "twadbstream.h"
#include "twrpback.hpp"

class twadbbu {
public:
Expand All @@ -46,6 +45,7 @@ class twadbbu {
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
2 changes: 1 addition & 1 deletion adbbu/twadbstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit adcb4d8

Please sign in to comment.