#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2026 Yangyang Zang.  All Rights Reserved.
#
# FS QA Test No. f2fs/024
#
# This test case tries to check whether resize.f2fs can correctly
# zero out ssa blocks without corrupting the main area blocks.
#
. ./common/preamble
_begin_fstest auto quick

_fixed_by_git_commit f2fs-tools xxxxxxxxxxxx \
	"resize.f2fs: fix to avoid zeroing main area blocks in migrate_ssa()"

# magic size
target_fs_size=$((2*1024*1024*1024+4*1024*1204))

_require_scratch_size_nocheck $(($target_fs_size/1024))
_require_command "$F2FS_RESIZE_PROG" resize.f2fs
_require_command "$DUMP_F2FS_PROG" dump.f2fs

# remove all mkfs options to avoid layout change of on-disk inode
export MKFS_OPTIONS=""

_scratch_mkfs_sized $((512*1024*1024)) "" "-g android" >> $seqres.full

sector_size=$(blockdev --getss $SCRATCH_DEV)
target_sectors=$(($target_fs_size/$sector_size))

$F2FS_RESIZE_PROG -F $SCRATCH_DEV -t $target_sectors >> $seqres.full 2>&1 || \
        $F2FS_RESIZE_PROG $SCRATCH_DEV -t $target_sectors >> $seqres.full 2>&1 || \
        _fail "resize fs failed"

echo n | $DUMP_F2FS_PROG -d 1 -i 3 $SCRATCH_DEV | grep "dump_node:" | sed 's/^\[[^]]*\] //'
_scratch_mount

status=0
exit
