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 leaf directory's leaf
8 # extent, then see how 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"
40 dblksz="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep naming.*bsize | sed -e 's/^.*bsize=//g' -e 's/\([0-9]*\).*$/\1/g')"
42 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
43 leaf_lblk="$((32 * 1073741824 / blksz))"
44 node_lblk="$((64 * 1073741824 / blksz))"
46 echo "+ make some files"
47 __populate_create_dir "${SCRATCH_MNT}/blockdir" "${nr}"
48 inode="$(stat -c '%i' "${SCRATCH_MNT}/blockdir")"
49 umount "${SCRATCH_MNT}"
52 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
55 __populate_check_xfs_dir "${inode}" leaf
58 _scratch_xfs_db -x -c "inode ${inode}" -c "dblock ${leaf_lblk}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full
60 echo "+ mount image && modify dir"
61 if _try_scratch_mount >> $seqres.full 2>&1; then
63 rm -rf "${SCRATCH_MNT}/blockdir/00000000" 2> /dev/null && _fail "modified corrupt directory"
64 mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" 2> /dev/null && _fail "add to corrupt directory"
65 umount "${SCRATCH_MNT}"
69 _repair_scratch_fs >> $seqres.full 2>&1
70 _repair_scratch_fs >> $seqres.full 2>&1
72 echo "+ mount image (2)"
76 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
78 echo "+ modify dir (2)"
79 mkdir -p "${SCRATCH_MNT}/blockdir"
80 rm -rf "${SCRATCH_MNT}/blockdir/00000000" || _fail "couldn't modify repaired directory"
81 mkdir "${SCRATCH_MNT}/blockdir/xxxxxxxx" || _fail "add to repaired directory"
82 umount "${SCRATCH_MNT}"
85 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"