2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Check that various invalid reflink scenarios are rejected.
10 _begin_fstest auto quick clone
12 # Override the default cleanup function.
16 rm -rf $tmp.* $testdir1
19 # Import common functions.
24 # real QA test starts here
26 _require_scratch_reflink
29 echo "Format and mount"
30 _scratch_mkfs > $seqres.full 2>&1
31 _scratch_mount >> $seqres.full 2>&1
33 testdir1="$TEST_DIR/test-$seq"
37 testdir2=$SCRATCH_MNT/test-$seq
40 echo "Create the original files"
41 blksz="$(_get_file_block_size $testdir1)"
45 free_blocks0=$(stat -f $testdir1 -c '%f')
47 filesize=$((blksz * nr))
48 _pwrite_byte 0x61 0 $sz $testdir1/file1 >> $seqres.full
49 _pwrite_byte 0x61 0 $sz $testdir1/file2 >> $seqres.full
50 _pwrite_byte 0x61 0 $sz $testdir2/file1 >> $seqres.full
51 _pwrite_byte 0x61 0 $sz $testdir2/file2 >> $seqres.full
53 seq 1 $((2 * blksz / 250)) | while read f; do
54 touch $testdir1/dir1/$f
56 mknod $testdir1/dev1 c 1 3
57 mkfifo $testdir1/fifo1
61 sed -e 's/Inappropriate ioctl for device/Invalid argument/g'
65 sed -e 's/Invalid argument/Bad file descriptor/g'
68 echo "Try cross-device reflink"
69 _reflink_range $testdir1/file1 0 $testdir2/file1 0 $blksz
71 echo "Try unaligned reflink"
72 _reflink_range $testdir1/file1 37 $testdir1/file1 59 23
74 echo "Try overlapping reflink"
75 _reflink_range $testdir1/file1 0 $testdir1/file1 1 $((blksz * 2))
77 echo "Try reflink past EOF"
78 _reflink_range $testdir1/file1 $(( (blks + 10) * blksz)) $testdir1/file1 0 $blksz
80 echo "Try to reflink a dir"
81 _reflink_range $testdir1/dir1 0 $testdir1/file2 0 $blksz
83 echo "Try to reflink a device"
84 _reflink_range $testdir1/dev1 0 $testdir1/file2 0 $blksz
86 echo "Try to reflink to a dir"
87 _reflink_range $testdir1/file1 0 $testdir1/dir1 0 $blksz 2>&1 | _filter_test_dir
89 echo "Try to reflink to a device"
90 _reflink_range $testdir1/file1 0 $testdir1/dev1 0 $blksz 2>&1 | _filter_enotty
92 echo "Try to reflink to a fifo"
93 _reflink_range $testdir1/file1 0 $testdir1/fifo1 0 $blksz -n 2>&1 | _filter_enotty
95 echo "Try to reflink an append-only file"
96 _reflink_range $testdir1/file1 0 $testdir1/file3 0 $blksz -a 2>&1 | _filter_einval
98 echo "Reflink two files"
99 _reflink_range $testdir1/file1 0 $testdir1/file2 0 $blksz >> $seqres.full
100 _reflink_range $testdir2/file1 0 $testdir2/file2 0 $blksz >> $seqres.full