summaryrefslogtreecommitdiff
path: root/f2fs_utils
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2021-05-20 23:16:10 -0700
committerJaegeuk Kim <jaegeuk@google.com>2021-05-26 16:45:34 -0700
commitf3b90a9e08122404afb067727b830eff69c9efdc (patch)
treee234dc00bfc708ae0bf9042cf22ee985cd5ee5cd /f2fs_utils
parenta7b5bc2f6749d332c629e0d1ed1d2b383595fb86 (diff)
downloadextras-f3b90a9e08122404afb067727b830eff69c9efdc.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
Diffstat (limited to 'f2fs_utils')
-rwxr-xr-xf2fs_utils/mkf2fsuserimg.sh63
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