From d1464aac0f8d2c04173067ac43fa5edb7cc80b05 Mon Sep 17 00:00:00 2001 From: rxuglr Date: Sat, 28 Jan 2023 23:59:07 +0300 Subject: [PATCH] surya: Optimize FBE script --- recovery/root/system/bin/patchfstab.sh | 70 ++++++++++----------- recovery/root/system/etc/recovery.fstab.bak | 2 +- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/recovery/root/system/bin/patchfstab.sh b/recovery/root/system/bin/patchfstab.sh index 635fbf1..940b6c8 100755 --- a/recovery/root/system/bin/patchfstab.sh +++ b/recovery/root/system/bin/patchfstab.sh @@ -1,11 +1,20 @@ #!/system/bin/sh +# # This script is needed to support wrappedkey and fbe v2 +# Version: 1.2 +# Date : 2023/01/19 # Author : brigudav # -n=1 +reclog=/tmp/recovery.log +tmpv=/tmp/vendor_fstab +fstabd=$tmpv/etc/fstab.default +fstabq=$tmpv/etc/fstab.qcom +fstabr=/system/etc/recovery.fstab -while [ $n -le 2 ]; do +send_log() { + echo "I:$1" >> $reclog +} finish() { sleep 1 @@ -14,40 +23,29 @@ finish() { exit 1 } -logf=/tmp/recovery.log -tmpv=/tmp/vendor_fstab -mkdir -p $tmpv -fstabd=$tmpv/etc/fstab.default -fstabq=$tmpv/etc/fstab.qcom -fstabr=/system/etc/recovery.fstab -mount -o ro -t auto /dev/block/mapper/vendor $tmpv || true -if [ -f $fstabq ]; then - fbev2=$(grep "/userdata" ${fstabq} | grep ":v2") - echo "I:Find $fstabq" >> $logf - if [ -z "$fbev2" ]; then - echo "I:This ROM not support FBE v2. Changing flags in fstab" >> $logf - cp $fstabr.bak $fstabr - wrapv=$(grep "/userdata" ${fstabq} | grep "wrappedkey") - if [ -n "$wrapv" ]; then - echo "I:And enabled supports wrappedkey..." >> $logf - sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr +patch_fstab() { + mkdir -p $tmpv + mount -o ro -t auto /dev/block/mapper/vendor $tmpv || true + + for i in $fstabq $fstabd; do + if [ -f $i ]; then + send_log "Find $i" + if [[ ! $(grep "/userdata" $i | grep ":v2") = "" ]]; then + send_log "ROM FBE v2 support..." + finish + else + send_log "Change FBE v1 support..." + cp $fstabr.bak $fstabr + if [[ ! $(grep "/userdata" $i | grep wrappedkey) = "" ]]; then + send_log "...and enabled wrappedkey." + sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr + fi + finish + fi fi - finish - else - echo "I:This ROM with FBE v2. Continuing with the default fstab." >> $logf - finish - fi -elif [ -f $fstabd ]; then - cp $fstabr.bak $fstabr - wrap=$(grep "/userdata" ${fstabd} | grep "wrappedkey") - echo "I:Find $fstabd" >> $logf - if [ -n "$wrap" ]; then - echo "I:This ROM supports wrappedkey. Changing flags in fstab" >> $logf - sed -i -e "s/formattable/formattable,wrappedkey/g" $fstabr - fi - finish -fi -sleep 1 -done + done +} + +patch_fstab exit 0 diff --git a/recovery/root/system/etc/recovery.fstab.bak b/recovery/root/system/etc/recovery.fstab.bak index b46a610..3ffff63 100644 --- a/recovery/root/system/etc/recovery.fstab.bak +++ b/recovery/root/system/etc/recovery.fstab.bak @@ -5,5 +5,5 @@ product /product ext4 ro,barrier=1,discard vendor /vendor ext4 ro,barrier=1,discard wait,logical /dev/block/bootdevice/by-name/cache /cache ext4 nosuid,noatime,nodev,barrier=1 wait /dev/block/bootdevice/by-name/metadata /metadata ext4 noatime,nosuid,nodev,discard wait,formattable -/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt wait,check,formattable,fileencryption=ice,quota +/dev/block/bootdevice/by-name/userdata /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier,inlinecrypt wait,check,formattable,fileencryption=ice,reservedsize=128M,quota /dev/block/bootdevice/by-name/misc /misc emmc defaults defaults