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
0f55fcaf
Commit
0f55fcaf
authored
Feb 12, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate EXT4 images instead of removing them
parent
ed027ec3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
16 deletions
+40
-16
bootstages.cpp
native/jni/core/bootstages.cpp
+30
-8
utils.h
native/jni/utils/include/utils.h
+9
-3
misc.cpp
native/jni/utils/misc.cpp
+1
-5
No files found.
native/jni/core/bootstages.cpp
View file @
0f55fcaf
...
...
@@ -324,9 +324,7 @@ static void exec_common_script(const char* stage) {
continue
;
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
exec_t
exec
{
.
pre_exec
=
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
};
int
pid
=
exec_command
(
exec
,
MIRRDIR
"/system/bin/sh"
,
entry
->
d_name
);
if
(
pid
!=
-
1
)
waitpid
(
pid
,
nullptr
,
0
);
exec_command_sync
(
exec
,
MIRRDIR
"/system/bin/sh"
,
entry
->
d_name
);
}
}
...
...
@@ -342,9 +340,7 @@ static void exec_module_script(const char* stage) {
continue
;
LOGI
(
"%s: exec [%s.sh]
\n
"
,
module
,
stage
);
exec_t
exec
{
.
pre_exec
=
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
};
int
pid
=
exec_command
(
exec
,
MIRRDIR
"/system/bin/sh"
,
buf2
);
if
(
pid
!=
-
1
)
waitpid
(
pid
,
nullptr
,
0
);
exec_command_sync
(
exec
,
MIRRDIR
"/system/bin/sh"
,
buf2
);
}
}
...
...
@@ -417,8 +413,6 @@ static bool magisk_env() {
// Remove legacy stuffs
unlink
(
"/data/magisk.img"
);
unlink
(
"/data/magisk_debug.log"
);
unlink
(
SECURE_DIR
"/magisk.img"
);
unlink
(
SECURE_DIR
"/magisk_merge.img"
);
// Legacy support
symlink
(
MAGISKTMP
,
"/sbin/.core"
);
...
...
@@ -487,7 +481,35 @@ static bool magisk_env() {
return
true
;
}
/* Too lazy to do it natively, let's write some scripts */
static
const
char
migrate_cmd
[]
=
"IMG=%s;"
"MNT=/dev/img_mnt;"
"e2fsck -yf $IMG;"
"mkdir -p $MNT;"
"for num in 0 1 2 3 4 5 6 7; do"
" losetup /dev/block/loop${num} $IMG || continue;"
" mount -t ext4 /dev/block/loop${num} $MNT;"
" rm -rf $MNT/lost+found $MNT/.core;"
" magisk --clone $MNT "
MODULEROOT
";"
" umount $MNT;"
" rm -rf $MNT;"
" losetup -d /dev/block/loop${num};"
" break;"
"done;"
"rm -rf $IMG"
;
static
void
upgrade_modules
()
{
const
char
*
legacy_imgs
[]
=
{
SECURE_DIR
"/magisk.img"
,
SECURE_DIR
"/magisk_merge.img"
};
for
(
auto
img
:
legacy_imgs
)
{
if
(
access
(
img
,
F_OK
)
==
0
)
{
LOGI
(
"* Migrating %s
\n
"
,
img
);
exec_t
exec
{
.
pre_exec
=
set_path
};
char
cmds
[
sizeof
(
migrate_cmd
)
+
32
];
sprintf
(
cmds
,
migrate_cmd
,
img
);
exec_command_sync
(
exec
,
"/system/bin/sh"
,
"-c"
,
cmds
);
}
}
DIR
*
dir
;
struct
dirent
*
entry
;
if
((
dir
=
opendir
(
MODULEUPGRADE
)))
{
...
...
native/jni/utils/include/utils.h
View file @
0f55fcaf
...
...
@@ -162,11 +162,17 @@ int exec_command(exec_t &exec, Args &&...args) {
exec
.
argv
=
argv
;
return
exec_command
(
exec
);
}
int
exec_command_sync
(
const
char
**
argv
);
int
exec_command_sync
(
exec_t
&
exec
);
template
<
class
...
Args
>
int
exec_command_sync
(
Args
&&
...
args
)
{
int
exec_command_sync
(
exec_t
&
exec
,
Args
&&
...
args
)
{
const
char
*
argv
[]
=
{
args
...,
nullptr
};
return
exec_command_sync
(
argv
);
exec
.
argv
=
argv
;
return
exec_command_sync
(
exec
);
}
template
<
class
...
Args
>
int
exec_command_sync
(
Args
&&
...
args
)
{
exec_t
exec
{};
return
exec_command_sync
(
exec
,
args
...);
}
#endif
...
...
native/jni/utils/misc.cpp
View file @
0f55fcaf
...
...
@@ -11,13 +11,10 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/sysmacros.h>
#include <vector>
#include <logging.h>
#include <utils.h>
using
namespace
std
;
unsigned
get_shell_uid
()
{
struct
passwd
*
ppwd
=
getpwnam
(
"shell"
);
if
(
nullptr
==
ppwd
)
...
...
@@ -195,8 +192,7 @@ int exec_command(exec_t &exec) {
exit
(
-
1
);
}
int
exec_command_sync
(
const
char
**
argv
)
{
exec_t
exec
{
.
argv
=
argv
};
int
exec_command_sync
(
exec_t
&
exec
)
{
int
pid
,
status
;
pid
=
exec_command
(
exec
);
if
(
pid
<
0
)
...
...
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