611847a8179391bef0947f7297a3d5a07024adb2
[xfstests-dev.git] / tests / overlay / 004
1 #! /bin/bash
2 # FS QA Test 004
3 #
4 # Test file copy up on overlayfs by changing mode bits.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016 Red Hat Inc. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         cd /
36         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # remove previous $seqres.full before test
44 rm -f $seqres.full
45
46 # Modify as appropriate.
47 _supported_fs overlay
48 _supported_os Linux
49 _require_scratch
50 _require_user
51
52 # Remove all files from previous tests
53 _scratch_mkfs
54
55 # Create test file in lower dir
56 lowerdir=${OVL_BASE_SCRATCH_MNT}/${OVL_LOWER}
57 upperdir=${OVL_BASE_SCRATCH_MNT}/${OVL_UPPER}
58 mkdir -p $lowerdir
59 touch ${lowerdir}/attr_file1
60 chmod 000 ${lowerdir}/attr_file1
61 touch ${lowerdir}/attr_file2
62 chmod 000 ${lowerdir}/attr_file2
63
64 _scratch_mount
65
66 # copy up by change mode bits and check.
67 chmod a+x ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
68 chmod o-w ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
69 chmod g+w ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
70 chmod u-r ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
71 chmod a+X ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
72 chmod o-s ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
73 chmod g+t ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
74 chmod u-X ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
75 stat -c %a ${SCRATCH_MNT}/attr_file1
76
77 # unprivileged user can't do this.
78 _user_do "chmod a+x ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
79 _user_do "chmod o-w ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
80 _user_do "chmod g+w ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
81 _user_do "chmod u-r ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
82 _user_do "chmod a+X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
83 _user_do "chmod o-s ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
84 _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
85 _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
86 stat -c %a ${SCRATCH_MNT}/attr_file2
87
88 # unmount overlayfs but not base fs
89 $UMOUNT_PROG $SCRATCH_MNT
90
91 # check mode bits of the file that has been copied up, and
92 # the file that should not have been copied up.
93 stat -c %a ${upperdir}/attr_file1
94 ls ${upperdir}/
95
96 # success, all done
97 status=0
98 exit