diff options
author | Jaegeuk Kim <jaegeuk@google.com> | 2021-06-01 21:40:10 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-01 21:40:10 +0000 |
commit | 3b9c2b6499116dae58757cdce73a27c8e7a47173 (patch) | |
tree | 6712bcdf5400f660c13a89b44876310c043db150 | |
parent | ffa138b8f985958fabafc8993eb0f8424ee6c627 (diff) | |
parent | 90f568a14e3a233233376974aa9cadc86a5d13c4 (diff) | |
download | extras-3b9c2b6499116dae58757cdce73a27c8e7a47173.tar.gz |
f2fs_utils: support -O ro am: 90f568a14e
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/extras/+/14737466
Change-Id: Iee5e52324492918a4a12a67a63a57e9a4c4a1f7c
-rwxr-xr-x | f2fs_utils/mkf2fsuserimg.sh | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/f2fs_utils/mkf2fsuserimg.sh b/f2fs_utils/mkf2fsuserimg.sh index 522f9ea4..013ff543 100755 --- a/f2fs_utils/mkf2fsuserimg.sh +++ b/f2fs_utils/mkf2fsuserimg.sh @@ -8,7 +8,7 @@ Usage: ${0##*/} OUTPUT_FILE SIZE [-S] [-C FS_CONFIG] [-f SRC_DIR] [-D PRODUCT_OUT] [-s FILE_CONTEXTS] [-t MOUNT_POINT] [-T TIMESTAMP] - [-L LABEL] [--prjquota] [--casefold] [--compression] + [-L LABEL] [--prjquota] [--casefold] [--compression] [--readonly] [--sldc <num> [sload compression sub-options]] <num>: number of the sload compression args, e.g. -a LZ4 counts as 2 when sload compression args are not given, <num> must be 0, @@ -95,6 +95,11 @@ if [[ "$1" == "--compression" ]]; then MKFS_OPTS+=" -O compression,extra_attr" shift; fi +if [[ "$1" == "--readonly" ]]; then + MKFS_OPTS+=" -O ro" + READONLY=1 + shift; +fi if [[ "$1" == "--sldc" ]]; then if [ -z "$COMPRESS_SUPPORT" ]; then @@ -122,32 +127,54 @@ if [ -z $SIZE ]; then exit 2 fi -if [ "$SPARSE_IMG" = "false" ]; then +function _truncate() +{ + if [ "$SPARSE_IMG" = "true" ]; then + return + fi + 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 +function _build() +{ + 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 $SLOAD_OPTS $OUTPUT_FILE" + echo $SLOAD_F2FS_CMD + MB_SIZE=`$SLOAD_F2FS_CMD | grep "Max image size" | awk '{print $5}'` + # allow 1: Filesystem errors corrected + ret=$? + if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then rm -f $OUTPUT_FILE + exit 4 fi - exit 4 -fi + SIZE=$(((MB_SIZE + 6) * 1024 * 1024)) +} + +_truncate +_build -SLOAD_F2FS_CMD="sload_f2fs $SLOAD_OPTS $OUTPUT_FILE" -echo $SLOAD_F2FS_CMD -$SLOAD_F2FS_CMD -# allow 1: Filesystem errors corrected -ret=$? -if [ $ret -ne 0 ] && [ $ret -ne 1 ]; then - rm -f $OUTPUT_FILE - exit 4 +# readonly + compress can reduce the image +if [ "$READONLY" ] && [ "$COMPRESS_SUPPORT" ]; then + if [ "$SPARSE_IMG" = "true" ]; then + MKFS_OPTS+=" -S $SIZE" + rm -f $OUTPUT_FILE && touch $OUTPUT_FILE + fi + _truncate + _build fi exit 0 |