2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt a long symlink, then see how
8 # the kernel and xfs_repair deal with it.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
31 # real QA test starts here
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
44 echo "+ create scratch fs"
45 _scratch_mkfs_xfs > /dev/null
47 echo "+ mount fs image"
51 echo "+ make some files"
52 echo "file contents: moo" > "${SCRATCH_MNT}/x"
53 str="$(perl -e "print './' x $(( (blksz / 2) - 16));")x"
54 (cd $SCRATCH_MNT; ln -s "${str}" "long_symlink")
55 cat "${SCRATCH_MNT}/long_symlink"
56 inode="$(stat -c '%i' "${SCRATCH_MNT}/long_symlink")"
57 umount "${SCRATCH_MNT}"
60 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
62 echo "+ corrupt image"
63 _scratch_xfs_db -x -c "inode ${inode}" -c "dblock 0" -c "stack" -c "blocktrash -x 32 -o 256 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
66 if _try_scratch_mount >> $seqres.full 2>&1; then
67 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
68 umount "${SCRATCH_MNT}"
72 _scratch_xfs_repair >> $seqres.full 2>&1
74 echo "+ mount image (2)"
76 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
77 umount "${SCRATCH_MNT}"
80 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"