diff options
author | Jaegeuk Kim <jaegeuk@google.com> | 2021-05-20 23:16:10 -0700 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@google.com> | 2021-05-26 23:47:41 +0000 |
commit | 90f568a14e3a233233376974aa9cadc86a5d13c4 (patch) | |
tree | 6712bcdf5400f660c13a89b44876310c043db150 | |
parent | c4d103c8757dcf7b9024855795854d9eb9c73650 (diff) | |
download | extras-90f568a14e3a233233376974aa9cadc86a5d13c4.tar.gz |
f2fs_utils: support -O ro
"-O ro" sets the filesystem as readonly.
Bug: 171942852
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Change-Id: Ia561618557e4e72bcc702b1e1d954a380a90d1b2
-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 |