Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
ba8e7a21
Commit
ba8e7a21
authored
Sep 12, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use default preferences from lz4 cli
parent
6b41653a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
13 deletions
+22
-13
compress.c
jni/magiskboot/compress.c
+22
-13
No files found.
jni/magiskboot/compress.c
View file @
ba8e7a21
...
@@ -151,7 +151,7 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
...
@@ -151,7 +151,7 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
LZ4F_compressionContext_t
cctx
;
LZ4F_compressionContext_t
cctx
;
LZ4F_frameInfo_t
info
;
LZ4F_frameInfo_t
info
;
size_t
outCapacity
,
avail_in
,
ret
=
0
,
pos
=
0
,
total
=
0
;
size_t
blockSize
,
outCapacity
,
avail_in
,
ret
=
0
,
pos
=
0
,
total
=
0
;
size_t
have
,
read
;
size_t
have
,
read
;
void
*
out
=
NULL
;
void
*
out
=
NULL
;
...
@@ -171,10 +171,11 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
...
@@ -171,10 +171,11 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
LOGE
(
1
,
"Context creation error: %s
\n
"
,
LZ4F_getErrorName
(
ret
));
LOGE
(
1
,
"Context creation error: %s
\n
"
,
LZ4F_getErrorName
(
ret
));
// Allocate out buffer
// Allocate out buffer
blockSize
=
1
<<
22
;
switch
(
mode
)
{
switch
(
mode
)
{
case
0
:
case
0
:
// Read header
// Read header
read
=
CHUNK
;
read
=
blockSize
;
ret
=
LZ4F_getFrameInfo
(
dctx
,
&
info
,
buf
,
&
read
);
ret
=
LZ4F_getFrameInfo
(
dctx
,
&
info
,
buf
,
&
read
);
if
(
LZ4F_isError
(
ret
))
if
(
LZ4F_isError
(
ret
))
LOGE
(
1
,
"LZ4F_getFrameInfo error: %s
\n
"
,
LZ4F_getErrorName
(
ret
));
LOGE
(
1
,
"LZ4F_getFrameInfo error: %s
\n
"
,
LZ4F_getErrorName
(
ret
));
...
@@ -190,7 +191,7 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
...
@@ -190,7 +191,7 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
pos
+=
read
;
pos
+=
read
;
break
;
break
;
case
1
:
case
1
:
outCapacity
=
LZ4F_compress
Bound
(
CHUNK
,
NULL
)
+
LZ4_HEADER_SIZE
+
LZ4_FOOTER_SIZE
;
outCapacity
=
LZ4F_compress
FrameBound
(
blockSize
,
NULL
)
;
break
;
break
;
}
}
...
@@ -198,23 +199,31 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
...
@@ -198,23 +199,31 @@ size_t lz4(int mode, int fd, const void *buf, size_t size) {
// Write header
// Write header
if
(
mode
==
1
)
{
if
(
mode
==
1
)
{
have
=
ret
=
LZ4F_compressBegin
(
cctx
,
out
,
size
,
NULL
);
LZ4F_preferences_t
prefs
;
memset
(
&
prefs
,
0
,
sizeof
(
prefs
));
prefs
.
autoFlush
=
1
;
prefs
.
compressionLevel
=
9
;
prefs
.
frameInfo
.
blockMode
=
1
;
prefs
.
frameInfo
.
blockSizeID
=
7
;
prefs
.
frameInfo
.
contentChecksumFlag
=
1
;
have
=
ret
=
LZ4F_compressBegin
(
cctx
,
out
,
size
,
&
prefs
);
if
(
LZ4F_isError
(
ret
))
if
(
LZ4F_isError
(
ret
))
LOGE
(
1
,
"Failed to start compression: error %s
\n
"
,
LZ4F_getErrorName
(
ret
));
LOGE
(
1
,
"Failed to start compression: error %s
\n
"
,
LZ4F_getErrorName
(
ret
));
total
+=
xwrite
(
fd
,
out
,
have
);
total
+=
xwrite
(
fd
,
out
,
have
);
}
}
do
{
do
{
if
(
pos
+
CHUNK
>=
size
)
{
if
(
pos
+
blockSize
>=
size
)
{
avail_in
=
size
-
pos
;
avail_in
=
size
-
pos
;
}
else
{
}
else
{
avail_in
=
CHUNK
;
avail_in
=
blockSize
;
}
}
do
{
do
{
switch
(
mode
)
{
switch
(
mode
)
{
case
0
:
case
0
:
have
=
outCapacity
,
read
=
avail_in
;
have
=
outCapacity
;
read
=
avail_in
;
ret
=
LZ4F_decompress
(
dctx
,
out
,
&
have
,
buf
+
pos
,
&
read
,
NULL
);
ret
=
LZ4F_decompress
(
dctx
,
out
,
&
have
,
buf
+
pos
,
&
read
,
NULL
);
break
;
break
;
case
1
:
case
1
:
...
@@ -513,16 +522,16 @@ void comp_file(const char *method, const char *from, const char *to) {
...
@@ -513,16 +522,16 @@ void comp_file(const char *method, const char *from, const char *to) {
void
*
file
;
void
*
file
;
size_t
size
;
size_t
size
;
mmap_ro
(
from
,
&
file
,
&
size
);
mmap_ro
(
from
,
&
file
,
&
size
);
if
(
!
to
)
{
if
(
!
to
)
snprintf
(
dest
,
sizeof
(
dest
),
"%s.%s"
,
from
,
ext
);
snprintf
(
dest
,
sizeof
(
dest
),
"%s.%s"
,
from
,
ext
);
to
=
dest
;
else
}
strcpy
(
dest
,
to
);
fprintf
(
stderr
,
"Compressing to [%s]
\n\n
"
,
to
);
fprintf
(
stderr
,
"Compressing to [%s]
\n\n
"
,
dest
);
int
fd
=
open_new
(
to
);
int
fd
=
open_new
(
dest
);
comp
(
type
,
fd
,
file
,
size
);
comp
(
type
,
fd
,
file
,
size
);
close
(
fd
);
close
(
fd
);
munmap
(
file
,
size
);
munmap
(
file
,
size
);
if
(
to
==
from
)
if
(
!
to
)
unlink
(
from
);
unlink
(
from
);
}
}
Write
Preview
Markdown
is supported
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