2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt a big symlink, then
8 # see how the kernel and e2fsck deal with it. (They won't)
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
30 # real QA test starts here
34 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
38 TESTDIR="${SCRATCH_MNT}/scratchdir"
39 TESTFILE="${TESTDIR}/testfile"
41 echo "+ create scratch fs"
42 _scratch_mkfs_ext4 -O journal > /dev/null 2>&1
44 echo "+ mount fs image"
46 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
47 test "${blksz}" -gt 4096 && blksz=4096
49 echo "+ make some files"
50 echo "file contents: moo" > "${SCRATCH_MNT}/x"
51 str="$(perl -e "print './' x $(( (blksz / 2) - 16));")x"
52 (cd $SCRATCH_MNT; ln -s "${str}" "long_symlink")
53 cat "${SCRATCH_MNT}/long_symlink"
54 umount "${SCRATCH_MNT}"
57 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
59 echo "+ corrupt image"
60 debugfs -w -R 'zap -f /long_symlink -p 0x62 0' "${SCRATCH_DEV}" 2> /dev/null
63 _scratch_mount 2> /dev/null
64 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
65 umount "${SCRATCH_MNT}"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
70 echo "+ mount image (2)"
72 cat "${SCRATCH_MNT}/long_symlink" 2>/dev/null && _fail "symlink should be broken"
73 umount "${SCRATCH_MNT}"
76 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"