Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
tools
etwrp
Commits
adcb4d8c
Commit
adcb4d8c
authored
Sep 25, 2017
by
bigbiff bigbiff
Committed by
Dees Troy
Nov 27, 2017
Browse files
ADB Backup: Fix gzip backup and restore
Change-Id: I92821c7053089d130a5ab73fa36aec486da77bf1
parent
19fb79c7
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
adbbu/adbbumain.cpp
View file @
adcb4d8c
...
...
@@ -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
;
}
adbbu/libtwadbbu.cpp
View file @
adcb4d8c
...
...
@@ -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
;
}
adbbu/libtwadbbu.hpp
View file @
adcb4d8c
...
...
@@ -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
adbbu/twadbstream.h
View file @
adcb4d8c
...
...
@@ -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
...
...
adbbu/twrpback.cpp
View file @
adcb4d8c
This diff is collapsed.
Click to expand it.
adbbu/twrpback.hpp
View file @
adcb4d8c
...
...
@@ -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
twrpAdbBuFifo.cpp
View file @
adcb4d8c
...
...
@@ -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
"
);
ret
urn
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
"
);
ret
urn
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
;
}
twrpAdbBuFifo.hpp
View file @
adcb4d8c
...
...
@@ -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
*
);
...
...
twrpTar.cpp
View file @
adcb4d8c
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment