2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that we can not clone a range from a file A into the middle of a file B
8 # when the range includes the last block of file A and file A's size is not
9 # aligned with the filesystem's block size. Allowing such case would lead to
10 # data corruption since the data between EOF and the end of its block is
14 _begin_fstest auto quick clone
16 # Import common functions.
20 # real QA test starts here
22 _require_scratch_reflink
24 _scratch_mkfs >>$seqres.full 2>&1
27 foo_size=$((256 * 1024 + 100)) # 256Kb + 100 bytes
30 $XFS_IO_PROG -f -c "pwrite -S 0x3c 0 $foo_size" $SCRATCH_MNT/foo | _filter_xfs_io
31 $XFS_IO_PROG -f -c "pwrite -S 0xb5 0 $bar_size" $SCRATCH_MNT/bar | _filter_xfs_io
33 # Cloning the EOF block of a file into the middle of another file should fail
34 # with an invalid argument error.
35 $XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo 0 512K $foo_size" $SCRATCH_MNT/bar
37 # Unmount the filesystem and mount it again. This guarantees any file data in
38 # the page cache is dropped.
41 # Verify no changes were made to the file.
42 echo "File content after failed reflink:"
43 od -A d -t x1 $SCRATCH_MNT/bar