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
05ed2913
Commit
05ed2913
authored
May 03, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish post-fs simple mount
parent
a31c1e80
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
18 deletions
+59
-18
bootstages.c
jni/daemon/bootstages.c
+57
-11
magisk.h
jni/magisk.h
+1
-0
main.c
jni/main.c
+0
-7
misc.c
jni/utils/misc.c
+1
-0
No files found.
jni/daemon/bootstages.c
View file @
05ed2913
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <selinux/selinux.h>
#include "magisk.h"
#include "magisk.h"
#include "utils.h"
#include "utils.h"
...
@@ -140,7 +141,7 @@ static int merge_img(const char *source, const char *target) {
...
@@ -140,7 +141,7 @@ static int merge_img(const char *source, const char *target) {
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
if
(
!
(
dir
=
x
opendir
(
"/cache/source"
)))
if
(
!
(
dir
=
opendir
(
"/cache/source"
)))
return
1
;
return
1
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
entry
->
d_type
==
DT_DIR
)
{
...
@@ -286,7 +287,7 @@ static void construct_tree(const char *module, const char *path, struct node_ent
...
@@ -286,7 +287,7 @@ static void construct_tree(const char *module, const char *path, struct node_ent
snprintf
(
buf
,
PATH_MAX
,
"%s/%s/%s"
,
MOUNTPOINT
,
module
,
path
);
snprintf
(
buf
,
PATH_MAX
,
"%s/%s/%s"
,
MOUNTPOINT
,
module
,
path
);
if
(
!
(
dir
=
x
opendir
(
buf
)))
if
(
!
(
dir
=
opendir
(
buf
)))
return
;
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
...
@@ -335,7 +336,8 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
...
@@ -335,7 +336,8 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
struct
node_entry
*
dummy
,
*
child
;
struct
node_entry
*
dummy
,
*
child
;
// Clone the structure
// Clone the structure
dir
=
xopendir
(
real_path
);
if
(
!
(
dir
=
opendir
(
real_path
)))
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
continue
;
...
@@ -380,7 +382,7 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
...
@@ -380,7 +382,7 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
xreadlink
(
buf2
,
temp
,
PATH_MAX
);
xreadlink
(
buf2
,
temp
,
PATH_MAX
);
symlink
(
temp
,
buf
);
symlink
(
temp
,
buf
);
free
(
temp
);
free
(
temp
);
LOG
D
(
"cplink: %s -> %s
\n
"
,
buf2
,
buf
);
LOG
I
(
"cplink: %s -> %s
\n
"
,
buf2
,
buf
);
}
else
{
}
else
{
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
real_path
,
child
->
name
);
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
real_path
,
child
->
name
);
bind_mount
(
buf2
,
buf
);
bind_mount
(
buf2
,
buf
);
...
@@ -415,6 +417,50 @@ static void magic_mount(struct node_entry *node) {
...
@@ -415,6 +417,50 @@ static void magic_mount(struct node_entry *node) {
}
}
}
}
/****************
* Simple Mount *
****************/
static
void
simple_mount
(
const
char
*
path
)
{
DIR
*
dir
;
struct
dirent
*
entry
;
snprintf
(
buf
,
PATH_MAX
,
"%s%s"
,
CACHEMOUNT
,
path
);
if
(
!
(
dir
=
opendir
(
buf
)))
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
// Target file path
snprintf
(
buf2
,
PATH_MAX
,
"%s/%s"
,
path
,
entry
->
d_name
);
// Only mount existing file
if
(
access
(
buf2
,
F_OK
)
==
-
1
)
continue
;
if
(
entry
->
d_type
==
DT_DIR
)
{
char
*
new_path
=
strdup
(
buf2
);
simple_mount
(
new_path
);
free
(
new_path
);
}
else
if
(
entry
->
d_type
==
DT_REG
)
{
// Actual file path
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
buf
,
entry
->
d_name
);
// Clone all attributes
struct
stat
s
;
xstat
(
buf2
,
&
s
);
chmod
(
buf
,
s
.
st_mode
&
0777
);
chown
(
buf
,
s
.
st_uid
,
s
.
st_gid
);
char
*
con
;
getfilecon
(
buf2
,
&
con
);
setfilecon
(
buf
,
con
);
free
(
con
);
// Finally, mount the file
bind_mount
(
buf
,
buf2
);
}
}
closedir
(
dir
);
}
/****************
/****************
* Entry points *
* Entry points *
****************/
****************/
...
@@ -441,12 +487,13 @@ void post_fs(int client) {
...
@@ -441,12 +487,13 @@ void post_fs(int client) {
if
(
access
(
UNINSTALLER
,
F_OK
)
==
0
||
access
(
DISABLEFILE
,
F_OK
)
==
0
)
if
(
access
(
UNINSTALLER
,
F_OK
)
==
0
||
access
(
DISABLEFILE
,
F_OK
)
==
0
)
goto
unblock
;
goto
unblock
;
// TODO: Simple bind mounts
// Allocate buffer
// Allocate buffer
buf
=
xmalloc
(
PATH_MAX
);
buf
=
xmalloc
(
PATH_MAX
);
buf2
=
xmalloc
(
PATH_MAX
);
buf2
=
xmalloc
(
PATH_MAX
);
simple_mount
(
"/system"
);
simple_mount
(
"/vendor"
);
unblock:
unblock:
unblock_boot_process
();
unblock_boot_process
();
}
}
...
@@ -506,8 +553,7 @@ void post_fs_data(int client) {
...
@@ -506,8 +553,7 @@ void post_fs_data(int client) {
char
*
module
;
char
*
module
;
struct
node_entry
*
sys_root
,
*
ven_root
=
NULL
,
*
child
;
struct
node_entry
*
sys_root
,
*
ven_root
=
NULL
,
*
child
;
if
(
!
(
dir
=
xopendir
(
MOUNTPOINT
)))
dir
=
xopendir
(
MOUNTPOINT
);
goto
unblock
;
// Create the system root entry
// Create the system root entry
sys_root
=
xcalloc
(
sizeof
(
*
sys_root
),
1
);
sys_root
=
xcalloc
(
sizeof
(
*
sys_root
),
1
);
...
@@ -586,7 +632,7 @@ void post_fs_data(int client) {
...
@@ -586,7 +632,7 @@ void post_fs_data(int client) {
snprintf
(
buf2
,
PATH_MAX
,
"%s/system"
,
MIRRDIR
);
snprintf
(
buf2
,
PATH_MAX
,
"%s/system"
,
MIRRDIR
);
xmkdir_p
(
buf2
,
0755
);
xmkdir_p
(
buf2
,
0755
);
xmount
(
buf
,
buf2
,
"ext4"
,
MS_RDONLY
,
NULL
);
xmount
(
buf
,
buf2
,
"ext4"
,
MS_RDONLY
,
NULL
);
LOG
D
(
"mount: %s -> %s
\n
"
,
buf
,
buf2
);
LOG
I
(
"mount: %s -> %s
\n
"
,
buf
,
buf2
);
continue
;
continue
;
}
}
if
(
strstr
(
line
,
" /vendor "
))
{
if
(
strstr
(
line
,
" /vendor "
))
{
...
@@ -595,7 +641,7 @@ void post_fs_data(int client) {
...
@@ -595,7 +641,7 @@ void post_fs_data(int client) {
snprintf
(
buf2
,
PATH_MAX
,
"%s/vendor"
,
MIRRDIR
);
snprintf
(
buf2
,
PATH_MAX
,
"%s/vendor"
,
MIRRDIR
);
xmkdir_p
(
buf2
,
0755
);
xmkdir_p
(
buf2
,
0755
);
xmount
(
buf
,
buf2
,
"ext4"
,
MS_RDONLY
,
NULL
);
xmount
(
buf
,
buf2
,
"ext4"
,
MS_RDONLY
,
NULL
);
LOG
D
(
"mount: %s -> %s
\n
"
,
buf
,
buf2
);
LOG
I
(
"mount: %s -> %s
\n
"
,
buf
,
buf2
);
continue
;
continue
;
}
}
}
}
...
@@ -604,7 +650,7 @@ void post_fs_data(int client) {
...
@@ -604,7 +650,7 @@ void post_fs_data(int client) {
snprintf
(
buf
,
PATH_MAX
,
"%s/system/vendor"
,
MIRRDIR
);
snprintf
(
buf
,
PATH_MAX
,
"%s/system/vendor"
,
MIRRDIR
);
snprintf
(
buf2
,
PATH_MAX
,
"%s/vendor"
,
MIRRDIR
);
snprintf
(
buf2
,
PATH_MAX
,
"%s/vendor"
,
MIRRDIR
);
symlink
(
buf
,
buf2
);
symlink
(
buf
,
buf2
);
LOG
D
(
"link: %s -> %s
\n
"
,
buf
,
buf2
);
LOG
I
(
"link: %s -> %s
\n
"
,
buf
,
buf2
);
}
}
// Magic!!
// Magic!!
...
...
jni/magisk.h
View file @
05ed2913
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#define MAGISKTMP "/dev/magisk"
#define MAGISKTMP "/dev/magisk"
#define MIRRDIR MAGISKTMP "/mirror"
#define MIRRDIR MAGISKTMP "/mirror"
#define DUMMDIR MAGISKTMP "/dummy"
#define DUMMDIR MAGISKTMP "/dummy"
#define CACHEMOUNT "/cache/magisk_mount"
#define SELINUX_PATH "/sys/fs/selinux/"
#define SELINUX_PATH "/sys/fs/selinux/"
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
...
...
jni/main.c
View file @
05ed2913
...
@@ -93,13 +93,6 @@ int main(int argc, char *argv[]) {
...
@@ -93,13 +93,6 @@ int main(int argc, char *argv[]) {
int
fd
=
connect_daemon
();
int
fd
=
connect_daemon
();
write_int
(
fd
,
LATE_START
);
write_int
(
fd
,
LATE_START
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
strcmp
(
argv
[
1
],
"--test"
)
==
0
)
{
// Temporary testing entry
// int fd = connect_daemon();
// write_int(fd, TEST);
// return read_int(fd);
// test();
return
0
;
}
else
{
}
else
{
// It's calling applets
// It's calling applets
--
argc
;
--
argc
;
...
...
jni/utils/misc.c
View file @
05ed2913
...
@@ -267,6 +267,7 @@ int mkdir_p(const char *pathname, mode_t mode) {
...
@@ -267,6 +267,7 @@ 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
);
LOGD
(
"bind_mount: %s -> %s
\n
"
,
from
,
to
);
LOGD
(
"bind_mount: %s -> %s
\n
"
,
from
,
to
);
LOGI
(
"bind_mount: %s
\n
"
,
to
);
return
ret
;
return
ret
;
}
}
...
...
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