OSDN Git Service

ext4_utils: make file system image reproducible
authorJin Qian <jinqian@google.com>
Tue, 29 Aug 2017 00:28:49 +0000 (17:28 -0700)
committerTao Bao <tbao@google.com>
Wed, 27 Sep 2017 21:48:26 +0000 (14:48 -0700)
Add flags to set filesystem uuid, hash_seed and mke2fs time.

Bug: 64994964
Change-Id: I38369a3a9dfffefead11c4b8fdd1e6984e61b938
(cherry picked from commit 407a7de4c499ede24dbbeb22d2efe6490a974b0d)

ext4_utils/mkuserimg_mke2fs.sh

index 64b1fe3..ea73ff7 100755 (executable)
@@ -8,7 +8,8 @@ Usage:
 mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
              [-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE]
              [-d BASE_ALLOC_FILE_IN ] [-A BASE_ALLOC_FILE_OUT ] [-L LABEL]
-             [-i INODES ] [-e ERASE_BLOCK_SIZE] [-o FLASH_BLOCK_SIZE] [FILE_CONTEXTS]
+             [-i INODES ] [-e ERASE_BLOCK_SIZE] [-o FLASH_BLOCK_SIZE]
+             [-U MKE2FS_UUID] [-S MKE2FS_HASH_SEED] [FILE_CONTEXTS]
 EOT
 }
 
@@ -17,6 +18,7 @@ BLOCKSIZE=4096
 MKE2FS_OPTS=""
 MKE2FS_EXTENDED_OPTS=""
 E2FSDROID_OPTS=""
+E2FSPROGS_FAKE_TIME=""
 
 if [ "$1" = "-s" ]; then
   MKE2FS_EXTENDED_OPTS+="android_sparse"
@@ -53,6 +55,7 @@ fi
 
 if [[ "$1" == "-T" ]]; then
   E2FSDROID_OPTS+=" -T $2"
+  E2FSPROGS_FAKE_TIME=$2
   shift; shift
 fi
 
@@ -108,6 +111,19 @@ if [[ "$1" == "-o" ]]; then
   shift; shift
 fi
 
+if [[ "$1" == "-U" ]]; then
+  MKE2FS_OPTS+=" -U $2"
+  shift; shift
+fi
+
+if [[ "$1" == "-S" ]]; then
+  if [[ $MKE2FS_EXTENDED_OPTS ]]; then
+    MKE2FS_EXTENDED_OPTS+=","
+  fi
+  MKE2FS_EXTENDED_OPTS+="hash_seed=$2"
+  shift; shift
+fi
+
 if [[ $MKE2FS_EXTENDED_OPTS ]]; then
   MKE2FS_OPTS+=" -E $MKE2FS_EXTENDED_OPTS"
 fi
@@ -141,16 +157,25 @@ SIZE=$((SIZE / BLOCKSIZE))
 # truncate output file since mke2fs will keep verity section in existing file
 cat /dev/null >$OUTPUT_FILE
 
+MAKE_EXT4FS_ENV="MKE2FS_CONFIG=./system/extras/ext4_utils/mke2fs.conf"
+if [[ $E2FSPROGS_FAKE_TIME ]]; then
+  MAKE_EXT4FS_ENV+=" E2FSPROGS_FAKE_TIME=$E2FSPROGS_FAKE_TIME"
+fi
+
 MAKE_EXT4FS_CMD="mke2fs $MKE2FS_OPTS -t $EXT_VARIANT -b $BLOCKSIZE $OUTPUT_FILE $SIZE"
-echo $MAKE_EXT4FS_CMD
-MKE2FS_CONFIG=./system/extras/ext4_utils/mke2fs.conf $MAKE_EXT4FS_CMD
+echo $MAKE_EXT4FS_ENV $MAKE_EXT4FS_CMD
+env $MAKE_EXT4FS_ENV $MAKE_EXT4FS_CMD
 if [ $? -ne 0 ]; then
   exit 4
 fi
 
+if [[ $E2FSPROGS_FAKE_TIME ]]; then
+  E2FSDROID_ENV="E2FSPROGS_FAKE_TIME=$E2FSPROGS_FAKE_TIME"
+fi
+
 E2FSDROID_CMD="e2fsdroid $E2FSDROID_OPTS -f $SRC_DIR -a $MOUNT_POINT $OUTPUT_FILE"
-echo $E2FSDROID_CMD
-$E2FSDROID_CMD
+echo $E2FSDROID_ENV $E2FSDROID_CMD
+env $E2FSDROID_ENV $E2FSDROID_CMD
 if [ $? -ne 0 ]; then
   rm -f $OUTPUT_FILE
   exit 4