fstests: _require_chattr() must get an input arg
[xfstests-dev.git] / tests / overlay / 027
1 #! /bin/bash
2 # FS QA Test 027
3 #
4 # If underlying upper file is immutable, it should stays
5 # untouchable in the overlayfs mount.
6 #
7 # Kernel commit below fixed it.
8 # f2b20f6ee842 vfs: move permission checking into ...
9 #
10 # This reproducer was originally written by
11 #     Miklos Szeredi <mszeredi@redhat.com>
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 here=`pwd`
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         cd /
43         $CHATTR_PROG -i $upperdir/foo
44         rm -f $tmp.*
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # remove previous $seqres.full before test
52 rm -f $seqres.full
53
54 # real QA test starts here
55
56 # Modify as appropriate.
57 _supported_fs overlay
58 _supported_os Linux
59 _require_scratch
60 _require_chattr i
61
62 # Remove all files from previous tests
63 _scratch_mkfs
64
65 # Preparing immutable file
66 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
67 mkdir -p $upperdir
68 touch $upperdir/foo
69 $CHATTR_PROG +i $upperdir/foo
70
71 # Mounting overlay
72 _scratch_mount
73
74 # Touching immutable file in overlay, should fail.
75 # Not filtering output here because of errno returned
76 # varies among kernel versions:
77 #   touch: setting times of 'foo': Operation not permitted
78 #   touch: cannot touch 'foo': Permission denied
79 if touch $SCRATCH_MNT/foo > /dev/null 2>&1 ; then
80         echo "Test Fail, you can't change an immutable file"
81 else
82         echo "Silence is golden"
83 fi
84
85 # success, all done
86 status=0
87 exit