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
a5aa1b39
Commit
a5aa1b39
authored
Jun 11, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use system and collect logs
parent
aced0632
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
28 deletions
+42
-28
bootstages.c
jni/daemon/bootstages.c
+15
-16
misc.c
jni/utils/misc.c
+27
-12
No files found.
jni/daemon/bootstages.c
View file @
a5aa1b39
...
@@ -91,6 +91,8 @@ static void umount_image(const char *target, const char *device) {
...
@@ -91,6 +91,8 @@ static void umount_image(const char *target, const char *device) {
}
}
#define round_size(a) ((((a) / 32) + 2) * 32)
#define round_size(a) ((((a) / 32) + 2) * 32)
#define SOURCE_TMP "/dev/source"
#define TARGET_TMP "/dev/target"
static
int
merge_img
(
const
char
*
source
,
const
char
*
target
)
{
static
int
merge_img
(
const
char
*
source
,
const
char
*
target
)
{
if
(
access
(
source
,
F_OK
)
==
-
1
)
if
(
access
(
source
,
F_OK
)
==
-
1
)
...
@@ -105,20 +107,20 @@ static int merge_img(const char *source, const char *target) {
...
@@ -105,20 +107,20 @@ static int merge_img(const char *source, const char *target) {
if
(
get_img_size
(
source
,
&
s_used
,
&
s_total
))
return
1
;
if
(
get_img_size
(
source
,
&
s_used
,
&
s_total
))
return
1
;
if
(
get_img_size
(
target
,
&
t_used
,
&
t_total
))
return
1
;
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
)
re
turn
1
;
re
size_img
(
target
,
n_total
)
;
mkdir
(
"/cache/source"
,
0755
);
mkdir
(
SOURCE_TMP
,
0755
);
mkdir
(
"/cache/target"
,
0755
);
mkdir
(
TARGET_TMP
,
0755
);
char
*
s_loop
,
*
t_loop
;
char
*
s_loop
,
*
t_loop
;
s_loop
=
mount_image
(
source
,
"/cache/source"
);
s_loop
=
mount_image
(
source
,
SOURCE_TMP
);
if
(
s_loop
==
NULL
)
return
1
;
if
(
s_loop
==
NULL
)
return
1
;
t_loop
=
mount_image
(
target
,
"/cache/target"
);
t_loop
=
mount_image
(
target
,
TARGET_TMP
);
if
(
t_loop
==
NULL
)
return
1
;
if
(
t_loop
==
NULL
)
return
1
;
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
if
(
!
(
dir
=
opendir
(
"/cache/source"
)))
if
(
!
(
dir
=
opendir
(
SOURCE_TMP
)))
return
1
;
return
1
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
entry
->
d_type
==
DT_DIR
)
{
...
@@ -128,7 +130,7 @@ static int merge_img(const char *source, const char *target) {
...
@@ -128,7 +130,7 @@ static int merge_img(const char *source, const char *target) {
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
continue
;
continue
;
// Cleanup old module
// Cleanup old module
snprintf
(
buf
,
PATH_MAX
,
"/
cache
/target/%s"
,
entry
->
d_name
);
snprintf
(
buf
,
PATH_MAX
,
"/
dev
/target/%s"
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
if
(
access
(
buf
,
F_OK
)
==
0
)
{
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
rm_rf
(
buf
);
rm_rf
(
buf
);
...
@@ -138,13 +140,13 @@ static int merge_img(const char *source, const char *target) {
...
@@ -138,13 +140,13 @@ static int merge_img(const char *source, const char *target) {
}
}
}
}
closedir
(
dir
);
closedir
(
dir
);
clone_dir
(
"/cache/source"
,
"/cache/target"
);
clone_dir
(
SOURCE_TMP
,
TARGET_TMP
);
// Unmount all loop devices
// Unmount all loop devices
umount_image
(
"/cache/source"
,
s_loop
);
umount_image
(
SOURCE_TMP
,
s_loop
);
umount_image
(
"/cache/target"
,
t_loop
);
umount_image
(
TARGET_TMP
,
t_loop
);
rmdir
(
"/cache/source"
);
rmdir
(
SOURCE_TMP
);
rmdir
(
"/cache/target"
);
rmdir
(
TARGET_TMP
);
free
(
s_loop
);
free
(
s_loop
);
free
(
t_loop
);
free
(
t_loop
);
unlink
(
source
);
unlink
(
source
);
...
@@ -551,9 +553,6 @@ void post_fs_data(int client) {
...
@@ -551,9 +553,6 @@ void post_fs_data(int client) {
new_img
=
1
;
new_img
=
1
;
}
}
// Initialize resetprop for the daemon
init_resetprop
();
LOGI
(
"* Mounting "
MAINIMG
"
\n
"
);
LOGI
(
"* Mounting "
MAINIMG
"
\n
"
);
// Mounting magisk image
// Mounting magisk image
char
*
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
char
*
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
...
...
jni/utils/misc.c
View file @
a5aa1b39
...
@@ -419,12 +419,17 @@ int create_img(const char *img, int size) {
...
@@ -419,12 +419,17 @@ int create_img(const char *img, int size) {
xwrite
(
fd
,
file_contexts
,
sizeof
(
file_contexts
));
xwrite
(
fd
,
file_contexts
,
sizeof
(
file_contexts
));
close
(
fd
);
close
(
fd
);
char
command
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
snprintf
(
command
,
sizeof
(
command
),
snprintf
(
buffer
,
sizeof
(
buffer
),
"make_ext4fs -l %dM -a /magisk -S /dev/file_contexts_image %s"
,
size
,
img
);
"make_ext4fs -l %dM -a /magisk -S /dev/file_contexts_image %s; e2fsck -yf %s;"
,
size
,
img
,
img
);
int
ret
=
system
(
command
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
status
;
pid
=
run_command
(
0
,
NULL
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
return
1
;
waitpid
(
pid
,
&
status
,
0
);
unlink
(
"/dev/file_contexts_image"
);
unlink
(
"/dev/file_contexts_image"
);
return
ret
;
return
WEXITSTATUS
(
status
)
;
}
}
int
get_img_size
(
const
char
*
img
,
int
*
used
,
int
*
total
)
{
int
get_img_size
(
const
char
*
img
,
int
*
used
,
int
*
total
)
{
...
@@ -433,22 +438,23 @@ int get_img_size(const char *img, int *used, int *total) {
...
@@ -433,22 +438,23 @@ int get_img_size(const char *img, int *used, int *total) {
char
buffer
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -yf %s"
,
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
,
ret
=
1
;
int
pid
,
fd
=
0
,
status
=
1
;
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
if
(
pid
==
-
1
)
return
1
;
return
1
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
{
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
{
LOGD
(
"magisk_img: %s"
,
buffer
);
if
(
strstr
(
buffer
,
img
))
{
if
(
strstr
(
buffer
,
img
))
{
char
*
tok
;
char
*
tok
;
tok
=
strtok
(
buffer
,
","
);
tok
=
strtok
(
buffer
,
","
);
while
(
tok
!=
NULL
)
{
while
(
tok
!=
NULL
)
{
if
(
strstr
(
tok
,
"blocks"
))
{
if
(
strstr
(
tok
,
"blocks"
))
{
ret
=
0
;
status
=
0
;
break
;
break
;
}
}
tok
=
strtok
(
NULL
,
","
);
tok
=
strtok
(
NULL
,
","
);
}
}
if
(
ret
)
continue
;
if
(
status
)
continue
;
sscanf
(
tok
,
"%d/%d"
,
used
,
total
);
sscanf
(
tok
,
"%d/%d"
,
used
,
total
);
*
used
=
*
used
/
256
+
1
;
*
used
=
*
used
/
256
+
1
;
*
total
/=
256
;
*
total
/=
256
;
...
@@ -456,15 +462,24 @@ int get_img_size(const char *img, int *used, int *total) {
...
@@ -456,15 +462,24 @@ int get_img_size(const char *img, int *used, int *total) {
}
}
}
}
close
(
fd
);
close
(
fd
);
waitpid
(
pid
,
NULL
,
0
);
waitpid
(
pid
,
&
status
,
0
);
return
ret
;
return
WEXITSTATUS
(
status
)
;
}
}
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
,
"resize2fs %s %dM;"
,
img
,
size
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"resize2fs %s %dM; e2fsck -yf %s;"
,
img
,
size
,
img
);
return
system
(
buffer
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
status
,
fd
=
0
;
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
return
1
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
LOGD
(
"magisk_img: %s"
,
buffer
);
close
(
fd
);
waitpid
(
pid
,
&
status
,
0
);
return
WEXITSTATUS
(
status
);
}
}
int
switch_mnt_ns
(
int
pid
)
{
int
switch_mnt_ns
(
int
pid
)
{
...
...
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