mirror of
https://github.com/openharmony/third_party_e2fsprogs.git
synced 2026-07-01 04:17:47 -04:00
ecb832ba90
Signed-off-by: 张文迪 <zhangwendi3@huawei.com>
103 lines
2.4 KiB
Diff
103 lines
2.4 KiB
Diff
diff --git a/contrib/populate-extfs.sh b/contrib/populate-extfs.sh
|
|
index b1d3d1f8cd45bd7d0a09973f7b8b83752a7c166f..173b0a568f3fdbc48b4a17d274fd3a03840f14a9 100755
|
|
--- a/contrib/populate-extfs.sh
|
|
+++ b/contrib/populate-extfs.sh
|
|
@@ -3,10 +3,13 @@
|
|
# This script uses debugfs command to populate the ext2/3/4 filesystem
|
|
# from a given directory.
|
|
#
|
|
+# Added mode, uid and gid config function by OpenHarmony team.
|
|
+export LANG=en_US.UTF-8
|
|
+export LANGUAGE=en_US:en
|
|
|
|
do_usage () {
|
|
cat << _EOF
|
|
-Usage: populate-extfs.sh <source> <device>
|
|
+Usage: populate-extfs.sh <source> <device> <cfgfile>
|
|
Create an ext2/ext3/ext4 filesystem from a directory or file
|
|
|
|
source: The source directory or file
|
|
@@ -16,17 +19,71 @@ _EOF
|
|
exit 1
|
|
}
|
|
|
|
-[ $# -ne 2 ] && do_usage
|
|
+CFGFILE_CNT=5
|
|
+FILEMODE_IDX=2
|
|
+FILEU_IDX=3
|
|
+FILEG_IDX=4
|
|
+_NEW_FILEMODE=0
|
|
+_NEW_FILEUID=0
|
|
+_NEW_FILEGID=0
|
|
+
|
|
+declare -a CONFIG_ARRAY
|
|
+
|
|
+do_parsecfgfile () {
|
|
+ i=0
|
|
+ while read _BINFILE_ _FILETYPE_ _FILEMODE_ _FILEUID_ _FILEGID_
|
|
+ do
|
|
+ CONFIG_ARRAY[${i}]=${_BINFILE_}
|
|
+ i=$[$i+1]
|
|
+ CONFIG_ARRAY[${i}]=${_FILETYPE_}
|
|
+ i=$[$i+1]
|
|
+ CONFIG_ARRAY[${i}]=${_FILEMODE_}
|
|
+ i=$[$i+1]
|
|
+ CONFIG_ARRAY[${i}]=${_FILEUID_}
|
|
+ i=$[$i+1]
|
|
+ CONFIG_ARRAY[${i}]=${_FILEGID_}
|
|
+ i=$[$i+1]
|
|
+ done < ${CFGFILE}
|
|
+}
|
|
+
|
|
+do_getfilecfgmode () {
|
|
+ i=0
|
|
+ _NEW_FILEMODE_=$2
|
|
+ _NEW_FILEUID_=0
|
|
+ _NEW_FILEGID_=0
|
|
+ while [ $i -lt ${#CONFIG_ARRAY[@]} ]
|
|
+ do
|
|
+ if [ "$1" == "${CONFIG_ARRAY[$i]}" ]; then
|
|
+ # Change file mode from OCT to HEX.
|
|
+ _NEW_FILEMODE_=$(echo "obase=16;$((0x$MODE & (~07777) | 0${CONFIG_ARRAY[$i+${FILEMODE_IDX}]}))"|bc)
|
|
+ _NEW_FILEUID_=${CONFIG_ARRAY[$i+${FILEU_IDX}]}
|
|
+ _NEW_FILLEGID_=${CONFIG_ARRAY[$i+${FILEG_IDX}]}
|
|
+ return 0
|
|
+ fi
|
|
+ i=$[$i+${CFGFILE_CNT}]
|
|
+ done
|
|
+}
|
|
+
|
|
+[ $# -ne 3 ] && do_usage
|
|
|
|
SRCDIR=${1%%/}
|
|
DEVICE=$2
|
|
+CFGFILE=$3
|
|
+
|
|
+# parse config file
|
|
+do_parsecfgfile
|
|
|
|
# Find where is the debugfs command if not found in the env.
|
|
if [ -z "$DEBUGFS" ]; then
|
|
CONTRIB_DIR=$(dirname $(readlink -f $0))
|
|
DEBUGFS="$CONTRIB_DIR/../debugfs/debugfs"
|
|
+ DEBUGFS=debugfs
|
|
fi
|
|
|
|
+# "debugfs" command check.
|
|
+command -v debugfs >/dev/null 2>&1 || \
|
|
+{ echo >&2 "debugfs is required, please install by \"apt-get install e2fsprogs\". Aborting."; exit 1; }
|
|
+
|
|
{
|
|
CWD="/"
|
|
find $SRCDIR | while read FILE; do
|
|
@@ -72,6 +129,10 @@ fi
|
|
;;
|
|
esac
|
|
|
|
+ do_getfilecfgmode ${FILE#$SRCDIR} $MODE $U $G
|
|
+ MODE=${_NEW_FILEMODE_}
|
|
+ U=${_NEW_FILEUID_}
|
|
+ G=${_NEW_FILEGID_}
|
|
# Set the file mode
|
|
echo "sif $TGT mode 0x$MODE"
|