2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt the refcount btree,
8 # then see how the kernel and xfs_repair deal with it.
11 _begin_fstest fuzzers clone
13 # Override the default cleanup function.
20 # Import common functions.
25 # real QA test starts here
27 _require_scratch_reflink
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
33 echo "+ create scratch fs"
34 _scratch_mkfs_xfs > /dev/null
36 echo "+ mount fs image"
38 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
39 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
40 _xfs_force_bdev data $SCRATCH_MNT
42 echo "+ make some files"
43 _pwrite_byte 0x62 0 $((blksz * 64)) "${SCRATCH_MNT}/file0" >> "$seqres.full"
44 _pwrite_byte 0x61 0 $((blksz * 64)) "${SCRATCH_MNT}/file1" >> "$seqres.full"
45 _cp_reflink "${SCRATCH_MNT}/file0" "${SCRATCH_MNT}/file2"
46 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file3"
47 umount "${SCRATCH_MNT}"
50 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
51 _fail "xfs_repair should not fail"
53 echo "+ corrupt image"
54 seq 0 $((agcount - 1)) | while read ag; do
55 _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr refcntroot" \
56 -c "stack" -c "blocktrash -x 4096 -y 4096 -z -n 8 -3" \
57 >> "$seqres.full" 2>&1
61 _try_scratch_mount >> $seqres.full 2>&1 && \
62 echo "Should not be able to mount with broken refcountbt."
63 _scratch_unmount >> $seqres.full 2>&1
67 _repair_scratch_fs >> "$seqres.full" 2>&1
68 _repair_scratch_fs >> "$seqres.full" 2>&1
70 echo "+ mount image (2)"
74 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
76 echo "+ reflink more (2)"
77 _cp_reflink "${SCRATCH_MNT}/file1" "${SCRATCH_MNT}/file5" || \
78 _fail "modified refcount tree"
79 umount "${SCRATCH_MNT}"
82 _scratch_xfs_repair -n >> "$seqres.full" 2>&1 || \
83 _fail "xfs_repair should not fail"