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
aced0632
Commit
aced0632
authored
Jun 11, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve image merging
parent
4e801788
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
30 deletions
+49
-30
bootstages.c
jni/daemon/bootstages.c
+23
-11
misc.c
jni/utils/misc.c
+26
-19
No files found.
jni/daemon/bootstages.c
View file @
aced0632
...
@@ -102,14 +102,14 @@ static int merge_img(const char *source, const char *target) {
...
@@ -102,14 +102,14 @@ static int merge_img(const char *source, const char *target) {
// resize target to worst case
// resize target to worst case
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
get_img_size
(
source
,
&
s_used
,
&
s_total
)
;
if
(
get_img_size
(
source
,
&
s_used
,
&
s_total
))
return
1
;
get_img_size
(
target
,
&
t_used
,
&
t_total
)
;
if
(
get_img_size
(
target
,
&
t_used
,
&
t_total
))
return
1
;
n_total
=
round_size
(
s_used
+
t_used
);
n_total
=
round_size
(
s_used
+
t_used
);
if
(
n_total
!=
t_total
&&
resize_img
(
target
,
n_total
))
if
(
n_total
!=
t_total
&&
resize_img
(
target
,
n_total
))
return
1
;
return
1
;
x
mkdir
(
"/cache/source"
,
0755
);
mkdir
(
"/cache/source"
,
0755
);
x
mkdir
(
"/cache/target"
,
0755
);
mkdir
(
"/cache/target"
,
0755
);
char
*
s_loop
,
*
t_loop
;
char
*
s_loop
,
*
t_loop
;
s_loop
=
mount_image
(
source
,
"/cache/source"
);
s_loop
=
mount_image
(
source
,
"/cache/source"
);
if
(
s_loop
==
NULL
)
return
1
;
if
(
s_loop
==
NULL
)
return
1
;
...
@@ -130,8 +130,10 @@ static int merge_img(const char *source, const char *target) {
...
@@ -130,8 +130,10 @@ static int merge_img(const char *source, const char *target) {
// Cleanup old module
// Cleanup old module
snprintf
(
buf
,
PATH_MAX
,
"/cache/target/%s"
,
entry
->
d_name
);
snprintf
(
buf
,
PATH_MAX
,
"/cache/target/%s"
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
if
(
access
(
buf
,
F_OK
)
==
0
)
{
LOGI
(
"
merge module
%s
\n
"
,
entry
->
d_name
);
LOGI
(
"
Upgrade module:
%s
\n
"
,
entry
->
d_name
);
rm_rf
(
buf
);
rm_rf
(
buf
);
}
else
{
LOGI
(
"New module: %s
\n
"
,
entry
->
d_name
);
}
}
}
}
}
}
...
@@ -523,19 +525,23 @@ void post_fs_data(int client) {
...
@@ -523,19 +525,23 @@ void post_fs_data(int client) {
}
}
// Magisk Manual Injector support
// Magisk Manual Injector support
if
(
access
(
"/data/local/tmp/magisk"
,
F_OK
)
==
0
)
{
if
(
access
(
"/data/local/tmp/magisk
_inject
"
,
F_OK
)
==
0
)
{
rm_rf
(
DATABIN
);
rm_rf
(
DATABIN
);
rename
(
"/data/local/tmp/magisk"
,
DATABIN
);
rename
(
"/data/local/tmp/magisk
_inject
"
,
DATABIN
);
}
}
// Lazy.... use shell blob
// Lazy.... use shell blob
system
(
"mv /data/magisk/stock_boot* /data;"
);
system
(
"mv /data/magisk/stock_boot* /data;"
);
// Merge images
// Merge images
if
(
merge_img
(
"/cache/magisk.img"
,
MAINIMG
))
if
(
merge_img
(
"/cache/magisk.img"
,
MAINIMG
))
{
LOGE
(
"Image merge %s -> %s failed!
\n
"
,
"/cache/magisk.img"
,
MAINIMG
);
goto
unblock
;
goto
unblock
;
if
(
merge_img
(
"/data/magisk_merge.img"
,
MAINIMG
))
}
if
(
merge_img
(
"/data/magisk_merge.img"
,
MAINIMG
))
{
LOGE
(
"Image merge %s -> %s failed!
\n
"
,
"/data/magisk_merge.img"
,
MAINIMG
);
goto
unblock
;
goto
unblock
;
}
int
new_img
=
0
;
int
new_img
=
0
;
...
@@ -735,12 +741,19 @@ void late_start(int client) {
...
@@ -735,12 +741,19 @@ void late_start(int client) {
// Run scripts after full patch, most reliable way to run scripts
// Run scripts after full patch, most reliable way to run scripts
LOGI
(
"* Running service.d scripts
\n
"
);
LOGI
(
"* Running service.d scripts
\n
"
);
exec_common_script
(
"service"
);
exec_common_script
(
"service"
);
// Core only mode
if
(
access
(
DISABLEFILE
,
F_OK
)
==
0
)
{
setprop
(
"ro.magisk.disable"
,
"1"
);
return
;
}
LOGI
(
"* Running module service scripts
\n
"
);
LOGI
(
"* Running module service scripts
\n
"
);
exec_module_script
(
"service"
);
exec_module_script
(
"service"
);
// Install Magisk Manager if exists
// Install Magisk Manager if exists
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
while
(
1
)
{
while
(
1
)
{
sleep
(
5
);
sleep
(
5
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
"CLASSPATH=/system/framework/pm.jar "
"CLASSPATH=/system/framework/pm.jar "
...
@@ -765,7 +778,6 @@ void late_start(int client) {
...
@@ -765,7 +778,6 @@ void late_start(int client) {
#ifdef DEBUG
#ifdef DEBUG
// Stop recording the boot logcat after every boot task is done
// Stop recording the boot logcat after every boot task is done
extern
int
debug_log_pid
,
debug_log_fd
;
kill
(
debug_log_pid
,
SIGTERM
);
kill
(
debug_log_pid
,
SIGTERM
);
waitpid
(
debug_log_pid
,
NULL
,
0
);
waitpid
(
debug_log_pid
,
NULL
,
0
);
close
(
debug_log_fd
);
close
(
debug_log_fd
);
...
...
jni/utils/misc.c
View file @
aced0632
...
@@ -277,11 +277,11 @@ int mkdir_p(const char *pathname, mode_t mode) {
...
@@ -277,11 +277,11 @@ int mkdir_p(const char *pathname, mode_t mode) {
int
bind_mount
(
const
char
*
from
,
const
char
*
to
)
{
int
bind_mount
(
const
char
*
from
,
const
char
*
to
)
{
int
ret
=
xmount
(
from
,
to
,
NULL
,
MS_BIND
,
NULL
);
int
ret
=
xmount
(
from
,
to
,
NULL
,
MS_BIND
,
NULL
);
#ifdef DEBUG
#ifdef DEBUG
LOGD
(
"bind_mount: %s -> %s
\n
"
,
from
,
to
);
LOGD
(
"bind_mount: %s -> %s
\n
"
,
from
,
to
);
#else
#else
LOGI
(
"bind_mount: %s
\n
"
,
to
);
LOGI
(
"bind_mount: %s
\n
"
,
to
);
#endif
#endif
return
ret
;
return
ret
;
}
}
...
@@ -431,32 +431,39 @@ int get_img_size(const char *img, int *used, int *total) {
...
@@ -431,32 +431,39 @@ int get_img_size(const char *img, int *used, int *total) {
if
(
access
(
img
,
R_OK
)
==
-
1
)
if
(
access
(
img
,
R_OK
)
==
-
1
)
return
1
;
return
1
;
char
buffer
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -
n %s 2>/dev/null | tail -n 1
"
,
img
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -
yf %s
"
,
img
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
fd
=
0
;
int
pid
,
fd
=
0
,
ret
=
1
;
pid
=
run_command
(
0
,
&
fd
,
"/system/bin/sh"
,
command
);
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
);
close
(
fd
);
if
(
pid
==
-
1
)
if
(
pid
==
-
1
)
return
1
;
return
1
;
waitpid
(
pid
,
NULL
,
0
);
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
{
char
*
tok
;
if
(
strstr
(
buffer
,
img
))
{
tok
=
strtok
(
buffer
,
","
);
char
*
tok
;
while
(
tok
!=
NULL
)
{
tok
=
strtok
(
buffer
,
","
);
if
(
strstr
(
tok
,
"blocks"
))
while
(
tok
!=
NULL
)
{
if
(
strstr
(
tok
,
"blocks"
))
{
ret
=
0
;
break
;
}
tok
=
strtok
(
NULL
,
","
);
}
if
(
ret
)
continue
;
sscanf
(
tok
,
"%d/%d"
,
used
,
total
);
*
used
=
*
used
/
256
+
1
;
*
total
/=
256
;
break
;
break
;
tok
=
strtok
(
NULL
,
","
);
}
}
}
sscanf
(
tok
,
"%d/%d"
,
used
,
total
);
close
(
fd
);
*
used
=
*
used
/
256
+
1
;
waitpid
(
pid
,
NULL
,
0
);
*
total
/=
256
;
return
ret
;
return
0
;
}
}
int
resize_img
(
const
char
*
img
,
int
size
)
{
int
resize_img
(
const
char
*
img
,
int
size
)
{
LOGI
(
"Resize %s to %dM
\n
"
,
img
,
size
);
LOGI
(
"Resize %s to %dM
\n
"
,
img
,
size
);
char
buffer
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
PATH_MAX
,
"
e2fsck -yf %s; resize2fs %s %dM;"
,
img
,
img
,
size
);
snprintf
(
buffer
,
PATH_MAX
,
"
resize2fs %s %dM;"
,
img
,
size
);
return
system
(
buffer
);
return
system
(
buffer
);
}
}
...
...
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