fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / ext4 / 020
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test 020
6 #
7 # Test partial blocksize defrag integrity issue.
8 #
9 # Calling EXT4_IOC_MOVE_EXTENT on file not aligned with block size and block
10 # size is smaller than page size would cause integrity issue on the
11 # partial-blocksize part when copying data between orign file and donor file.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/defrag
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37 _supported_fs ext4
38 _supported_os Linux
39 _require_scratch
40 _require_defrag
41
42 e4compact=$here/src/e4compact
43 _require_test_program "e4compact"
44
45 testfile=$SCRATCH_MNT/$seq.orig
46 donorfile=$SCRATCH_MNT/$seq.donor
47 _scratch_mkfs >>$seqres.full 2>&1
48 _scratch_mount
49
50 # reserve space for donor file, written by 0xaa and sync to disk to avoid
51 # EBUSY on EXT4_IOC_MOVE_EXT
52 $XFS_IO_PROG -fc "pwrite -S 0xaa 0 1m" -c "fsync" $donorfile | _filter_xfs_io
53
54 # create test file with 1023 in size, written by 0xbb
55 # 1023 is smaller than 1k and works for any block size filesystems
56 $XFS_IO_PROG -fc "pwrite -S 0xbb 0 1023" -c "fsync" $testfile | _filter_xfs_io
57
58 # compute initial md5sum
59 md5sum $testfile > $tmp.md5sum
60
61 # drop cache, force e4compact to read data from disk
62 echo 3 > /proc/sys/vm/drop_caches
63
64 # test defrag
65 echo "$testfile" | $e4compact -i -v -f $donorfile >>$seqres.full
66
67 # check md5sum
68 md5sum -c $tmp.md5sum | _filter_scratch
69
70 # success, all done
71 status=0
72 exit