OSDN Git Service

mkf2fsuserimg.sh: Make sparse mode optional
authorAlistair Delva <adelva@google.com>
Wed, 16 Oct 2019 17:40:23 +0000 (10:40 -0700)
committerAlistair Delva <adelva@google.com>
Fri, 15 Nov 2019 19:05:30 +0000 (19:05 +0000)
Bug: 142424832
Bug: 142803849
Test: Run mkf2fsuserimg.sh without the sparse option and check that the
      generated image is not sparse.
Co-authored-by: Satya Tangirala <satyat@google.com>
Change-Id: I8a079b30f63ddd13a94d73339501ed8ecb2c5049

f2fs_utils/mkf2fsuserimg.sh

index ef762dc..582f63c 100755 (executable)
@@ -8,7 +8,7 @@ Usage:
 ${0##*/} OUTPUT_FILE SIZE
          [-C FS_CONFIG] [-f SRC_DIR] [-D PRODUCT_OUT]
          [-s FILE_CONTEXTS] [-t MOUNT_POINT] [-T TIMESTAMP]
-         [-L LABEL]
+         [-L LABEL] [-S]
 EOT
 }
 
@@ -26,6 +26,14 @@ OUTPUT_FILE=$1
 SIZE=$2
 shift; shift
 
+SPARSE_IMG="false"
+if [[ "$1" == "-S" ]]; then
+  MKFS_OPTS+=" -S $SIZE"
+  SLOAD_OPTS+=" -S"
+  SPARSE_IMG="true"
+  shift
+fi
+
 if [[ "$1" == "-C" ]]; then
   SLOAD_OPTS+=" -C $2"
   shift; shift
@@ -73,14 +81,26 @@ if [ -z $SIZE ]; then
   exit 2
 fi
 
-MAKE_F2FS_CMD="make_f2fs -S $SIZE -g android $MKFS_OPTS $OUTPUT_FILE"
+if [ "$SPARSE_IMG" = "false" ]; then
+  TRUNCATE_CMD="truncate -s $SIZE $OUTPUT_FILE"
+  echo $TRUNCATE_CMD
+  $TRUNCATE_CMD
+  if [ $? -ne 0 ]; then
+    exit 3
+  fi
+fi
+
+MAKE_F2FS_CMD="make_f2fs -g android $MKFS_OPTS $OUTPUT_FILE"
 echo $MAKE_F2FS_CMD
 $MAKE_F2FS_CMD
 if [ $? -ne 0 ]; then
+  if [ "$SPARSE_IMG" = "false" ]; then
+    rm -f $OUTPUT_FILE
+  fi
   exit 4
 fi
 
-SLOAD_F2FS_CMD="sload_f2fs -S $SLOAD_OPTS $OUTPUT_FILE"
+SLOAD_F2FS_CMD="sload_f2fs $SLOAD_OPTS $OUTPUT_FILE"
 echo $SLOAD_F2FS_CMD
 $SLOAD_F2FS_CMD
 if [ $? -ne 0 ]; then