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.
13 # Override the default cleanup function.
20 # Import common functions.
25 # real QA test starts here
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
35 echo "+ create scratch fs"
36 _scratch_mkfs_xfs > /dev/null
38 echo "+ mount fs image"
42 echo "+ make some files"
43 echo "file contents: moo" > "${SCRATCH_MNT}/x"
44 reps=$(( (blksz - (56 + 1)) / 2 ))
45 str="$(perl -e "print './' x $reps;")x"
46 (cd $SCRATCH_MNT; ln -s "${str}" "long_symlink")
47 cat "${SCRATCH_MNT}/long_symlink"
48 inode="$(stat -c '%i' "${SCRATCH_MNT}/long_symlink")"
49 umount "${SCRATCH_MNT}"
52 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
54 echo "+ corrupt image"
55 _scratch_xfs_db -x -c "inode ${inode}" -c "dblock 0" -c "stack" -c "blocktrash -x 32 -o 256 -y $((blksz * 4)) -z ${FUZZ_ARGS}" >> $seqres.full
58 if _try_scratch_mount >> $seqres.full 2>&1; then
59 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
60 umount "${SCRATCH_MNT}"
64 _repair_scratch_fs >> $seqres.full 2>&1
66 echo "+ mount image (2)"
68 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
69 umount "${SCRATCH_MNT}"
72 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"