1diff --git a/contrib/populate-extfs.sh b/contrib/populate-extfs.sh 2index b1d3d1f8cd45bd7d0a09973f7b8b83752a7c166f..173b0a568f3fdbc48b4a17d274fd3a03840f14a9 100755 3--- a/contrib/populate-extfs.sh 4+++ b/contrib/populate-extfs.sh 5@@ -3,10 +3,13 @@ 6 # This script uses debugfs command to populate the ext2/3/4 filesystem 7 # from a given directory. 8 # 9+# Added mode, uid and gid config function by OpenHarmony team. 10+export LANG=en_US.UTF-8 11+export LANGUAGE=en_US:en 12 13 do_usage () { 14 cat << _EOF 15-Usage: populate-extfs.sh <source> <device> 16+Usage: populate-extfs.sh <source> <device> <cfgfile> 17 Create an ext2/ext3/ext4 filesystem from a directory or file 18 19 source: The source directory or file 20@@ -16,17 +19,71 @@ _EOF 21 exit 1 22 } 23 24-[ $# -ne 2 ] && do_usage 25+CFGFILE_CNT=5 26+FILEMODE_IDX=2 27+FILEU_IDX=3 28+FILEG_IDX=4 29+_NEW_FILEMODE=0 30+_NEW_FILEUID=0 31+_NEW_FILEGID=0 32+ 33+declare -a CONFIG_ARRAY 34+ 35+do_parsecfgfile () { 36+ i=0 37+ while read _BINFILE_ _FILETYPE_ _FILEMODE_ _FILEUID_ _FILEGID_ 38+ do 39+ CONFIG_ARRAY[${i}]=${_BINFILE_} 40+ i=$[$i+1] 41+ CONFIG_ARRAY[${i}]=${_FILETYPE_} 42+ i=$[$i+1] 43+ CONFIG_ARRAY[${i}]=${_FILEMODE_} 44+ i=$[$i+1] 45+ CONFIG_ARRAY[${i}]=${_FILEUID_} 46+ i=$[$i+1] 47+ CONFIG_ARRAY[${i}]=${_FILEGID_} 48+ i=$[$i+1] 49+ done < ${CFGFILE} 50+} 51+ 52+do_getfilecfgmode () { 53+ i=0 54+ _NEW_FILEMODE_=$2 55+ _NEW_FILEUID_=0 56+ _NEW_FILEGID_=0 57+ while [ $i -lt ${#CONFIG_ARRAY[@]} ] 58+ do 59+ if [ "$1" == "${CONFIG_ARRAY[$i]}" ]; then 60+ # Change file mode from OCT to HEX. 61+ _NEW_FILEMODE_=$(echo "obase=16;$((0x$MODE & (~07777) | 0${CONFIG_ARRAY[$i+${FILEMODE_IDX}]}))"|bc) 62+ _NEW_FILEUID_=${CONFIG_ARRAY[$i+${FILEU_IDX}]} 63+ _NEW_FILLEGID_=${CONFIG_ARRAY[$i+${FILEG_IDX}]} 64+ return 0 65+ fi 66+ i=$[$i+${CFGFILE_CNT}] 67+ done 68+} 69+ 70+[ $# -ne 3 ] && do_usage 71 72 SRCDIR=${1%%/} 73 DEVICE=$2 74+CFGFILE=$3 75+ 76+# parse config file 77+do_parsecfgfile 78 79 # Find where is the debugfs command if not found in the env. 80 if [ -z "$DEBUGFS" ]; then 81 CONTRIB_DIR=$(dirname $(readlink -f $0)) 82 DEBUGFS="$CONTRIB_DIR/../debugfs/debugfs" 83+ DEBUGFS=debugfs 84 fi 85 86+# "debugfs" command check. 87+command -v debugfs >/dev/null 2>&1 || \ 88+{ echo >&2 "debugfs is required, please install by \"apt-get install e2fsprogs\". Aborting."; exit 1; } 89+ 90 { 91 CWD="/" 92 find $SRCDIR | while read FILE; do 93@@ -72,6 +129,10 @@ fi 94 ;; 95 esac 96 97+ do_getfilecfgmode ${FILE#$SRCDIR} $MODE $U $G 98+ MODE=${_NEW_FILEMODE_} 99+ U=${_NEW_FILEUID_} 100+ G=${_NEW_FILEGID_} 101 # Set the file mode 102 echo "sif $TGT mode 0x$MODE" 103