From 198b14e5fc2a37b5e1a9fe8382ecbe1125807418 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 1 Jan 2017 19:45:06 +0800 Subject: [PATCH] Fixed various Magic Mount bugs --- scripts/magic_mask.sh | 60 ++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/scripts/magic_mask.sh b/scripts/magic_mask.sh index ca93f9f66..701d2e68b 100644 --- a/scripts/magic_mask.sh +++ b/scripts/magic_mask.sh @@ -2,6 +2,7 @@ LOGFILE=/cache/magisk.log IMG=/data/magisk.img +BLACKLIST="/system/lib /system/lib64 /system/etc /vendor/lib /vendor/lib64" MOUNTPOINT=/magisk @@ -17,13 +18,9 @@ MOUNTINFO=$TMPDIR/mnt TOOLPATH=/data/busybox BINPATH=/data/magisk -export OLDPATH=$PATH -export PATH=$TOOLPATH:$OLDPATH - # Default permissions umask 022 - log_print() { echo "$1" echo "$1" >> $LOGFILE @@ -39,6 +36,13 @@ mktouch() { fi } +in_list() { + for i in $2; do + [ "$1" = "$i" ] && return 0 + done + return 1 +} + unblock() { touch /dev/.magisk.unblock exit @@ -117,6 +121,9 @@ travel() { } clone_dummy() { + LINK=true + in_list $1 "$BLACKLIST" && LINK=false + for ITEM in $MIRRDIR$1/* ; do REAL=${ITEM#$MIRRDIR} if [ -d $MOUNTINFO$REAL ]; then @@ -128,13 +135,16 @@ clone_dummy() { # Copy original symlink cp -afc $ITEM $DUMMDIR$REAL else - if [ -d $ITEM ]; then - mkdir -p $DUMMDIR$REAL + if $LINK && [ ! -e $MOUNTINFO$REAL ]; then + ln -s $MIRRDIR$REAL $DUMMDIR$REAL else - mktouch $DUMMDIR$REAL + if [ -d $ITEM ]; then + mkdir -p $DUMMDIR$REAL + else + mktouch $DUMMDIR$REAL + fi + [ ! -e $MOUNTINFO$REAL ] && mktouch $MOUNTINFO/mirror$REAL fi - # Mount the mirror if not module item - [ ! -e $MOUNTINFO$REAL ] && mktouch $MOUNTINFO/mirror$REAL fi fi done @@ -247,12 +257,15 @@ case $1 in post-fs-data ) # /data not mounted yet - ! mount | grep " /data " && unblock - mount | grep " /data " | grep "tmpfs" && unblock + ! mount | grep " /data " >/dev/null && unblock + mount | grep " /data " | grep "tmpfs" >/dev/null && unblock # Don't run twice if [ "`getprop magisk.restart_pfsd`" != "1" ]; then + export OLDPATH=$PATH + export PATH=$TOOLPATH:$OLDPATH + log_print "** Magisk post-fs-data mode running..." # Cache support @@ -297,10 +310,11 @@ case $1 in # Remove empty directories, legacy paths, symlinks, old temporary images find $MOUNTPOINT -type d -depth ! -path "*core*" -exec rmdir {} \; 2>/dev/null - rm -rf $COREDIR/bin $COREDIR/dummy $COREDIR/mirror /data/magisk/*.img + rm -rf $COREDIR/bin $COREDIR/dummy $COREDIR/mirror /data/magisk/*.img 2>/dev/null # Remove modules that is labeled to be removed for MOD in $MOUNTPOINT/* ; do + rm -f $MOD/system/placeholder 2>/dev/null if [ -f $MOD/remove ] || [ $MOD = zzsupersu ]; then log_print "Remove module: $MOD" rm -rf $MOD @@ -329,6 +343,9 @@ case $1 in mkdir -p $DUMMDIR mkdir -p $MIRRDIR/system + # Remove crap folder + rm -rf $MOUNTPOINT/lost+found + # Travel through all mods for MOD in $MOUNTPOINT/* ; do if [ -f $MOD/auto_mount -a -d $MOD/system -a ! -f $MOD/disable ]; then @@ -345,18 +362,6 @@ case $1 in cp -afc /system/bin/linker* /system/bin/t*box $DUMMDIR/system/bin/ fi - DISABLEHIDE=false - - for i in /system /system/lib /system/lib64 /system/vendor /system/vendor/lib /system/vendor/lib64; do - [ -f $MOUNTINFO/dummy$1 ] && DISABLEHIDE=true && break - done - - # Crash prevention!! - $DISABLEHIDE && rm -f $COREDIR/magiskhide/enable 2>/dev/null - - # Remove crap folder - rm -rf $MOUNTPOINT/lost+found - # Start doing tasks # Stage 1 @@ -371,9 +376,10 @@ case $1 in else ln -s $MIRRDIR/system/vendor $MIRRDIR/vendor fi + # Since mirrors always exist, we load libraries from mirrors - LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib - [ -d /system/lib64 ] LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64 + export LD_LIBRARY_PATH=$MIRRDIR/system/lib:$MIRRDIR/vendor/lib + [ -d /system/lib64 ] && export LD_LIBRARY_PATH=$MIRRDIR/system/lib64:$MIRRDIR/vendor/lib64 # Stage 2 log_print "* Stage 2: Mount dummy skeletons" @@ -457,7 +463,7 @@ case $1 in # Add Safety Net preset $COREDIR/magiskhide/add com.google.android.gms.unstable log_print "* Starting Magisk Hide" - /data/magisk/magiskhide + /data/magisk/magiskhide --daemon fi ;;