generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 515
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 515
6 #
7 # Ensure that reflinking into a file well beyond EOF zeroes everything between
8 # the old EOF and the start of the newly linked chunk.  This is an adaptation
9 # of a reproducer script that Eric Sandeen formulated from a stale data
10 # exposure bug uncovered by shared/010.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33 _require_scratch_reflink
34 _require_xfs_io_command "falloc"
35
36 rm -f $seqres.full
37
38 # Fill disk with a well known pattern so that stale data exposure becomes much
39 # more obvious.
40 $XFS_IO_PROG -c "pwrite -S 0x58 -b 1m 0 300m" $SCRATCH_DEV >> $seqres.full
41 _scratch_mkfs_sized $((300 * 1048576)) >>$seqres.full 2>&1
42 _scratch_mount
43
44 DONOR1=$SCRATCH_MNT/a
45 TARGET=$SCRATCH_MNT/b
46 blksz=65536
47
48 $XFS_IO_PROG -f -c "pwrite -S 0x72 0 $blksz" $DONOR1 >> $seqres.full
49
50 $XFS_IO_PROG -f \
51         -c "falloc -k $((blksz*2)) $blksz"        \
52         -c "pwrite -S 0x57 $((blksz*16)) 8192" \
53         -c "fdatasync" \
54         -c 'stat' \
55         -c "reflink $DONOR1 0 $((blksz*17)) $blksz" \
56                 $TARGET >> $seqres.full
57
58 od -tx1 -Ad -c $TARGET >> $seqres.full
59 md5sum $DONOR1 | _filter_scratch
60 md5sum $TARGET | _filter_scratch
61
62 _scratch_cycle_mount
63
64 od -tx1 -Ad -c $TARGET >> $seqres.full
65 md5sum $DONOR1 | _filter_scratch
66 md5sum $TARGET | _filter_scratch
67
68 status=0
69 exit