summaryrefslogtreecommitdiff
path: root/tests/generic/518
blob: f3cb5868c81646c745a1cb1625d53889611dd123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
#
# FS QA Test No. 518
#
# Test that we can not clone a range from a file A into the middle of a file B
# when the range includes the last block of file A and file A's size is not
# aligned with the filesystem's block size. Allowing such case would lead to
# data corruption since the data between EOF and the end of its block is
# undefined.
#
. ./common/preamble
_begin_fstest auto quick clone

# Import common functions.
. ./common/filter
. ./common/reflink

# real QA test starts here
_supported_fs generic
_require_scratch_reflink

_scratch_mkfs >>$seqres.full 2>&1
_scratch_mount

foo_size=$((256 * 1024 + 100)) # 256Kb + 100 bytes
bar_size="1M"

$XFS_IO_PROG -f -c "pwrite -S 0x3c 0 $foo_size" $SCRATCH_MNT/foo | _filter_xfs_io
$XFS_IO_PROG -f -c "pwrite -S 0xb5 0 $bar_size" $SCRATCH_MNT/bar | _filter_xfs_io

# Cloning the EOF block of a file into the middle of another file should fail
# with an invalid argument error.
$XFS_IO_PROG -c "reflink $SCRATCH_MNT/foo 0 512K $foo_size" $SCRATCH_MNT/bar

# Unmount the filesystem and mount it again. This guarantees any file data in
# the page cache is dropped.
_scratch_cycle_mount

# Verify no changes were made to the file.
echo "File content after failed reflink:"
od -A d -t x1 $SCRATCH_MNT/bar

status=0
exit