common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / tests / generic / 159
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 159
6 #
7 # Check that we can't reflink immutable files
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.* $testdir1
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _require_chattr i
32 _require_test_reflink
33
34 rm -f $seqres.full
35
36 echo "Format and mount"
37 testdir1="$TEST_DIR/test-$seq"
38 rm -rf $testdir1
39 mkdir $testdir1
40
41 echo "Create the original files"
42 blksz="$(_get_block_size $testdir1)"
43 blks=1000
44 margin='7%'
45 sz=$((blksz * blks))
46 free_blocks0=$(stat -f $testdir1 -c '%f')
47 nr=4
48 filesize=$((blksz * nr))
49 _pwrite_byte 0x61 0 $sz $testdir1/file1 >> $seqres.full
50 _pwrite_byte 0x61 0 $sz $testdir1/file2 >> $seqres.full
51 sync
52
53 do_filter_output()
54 {
55         _filter_test_dir | sed -e 's/Operation not permitted/Permission denied/g'
56 }
57
58 echo "Try reflink on immutable files"
59 $CHATTR_PROG +i $testdir1/file1 $testdir1/file2
60 _reflink_range $testdir1/file1 0 $testdir1/file2 0 $blksz 2>&1 | do_filter_output
61 $CHATTR_PROG -i $testdir1/file1 $testdir1/file2
62
63 # success, all done
64 status=0
65 exit