overlay/029: fix test failure with nfs_export feature enabled
[xfstests-dev.git] / tests / overlay / 004
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Red Hat Inc. All Rights Reserved.
4 #
5 # FS QA Test 004
6 #
7 # Test file copy up on overlayfs by changing mode bits.
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 -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # Modify as appropriate.
32 _supported_fs overlay
33 _supported_os Linux
34 _require_scratch
35 _require_user
36
37 # Remove all files from previous tests
38 _scratch_mkfs
39
40 # Create test file in lower dir
41 lowerdir=${OVL_BASE_SCRATCH_MNT}/${OVL_LOWER}
42 upperdir=${OVL_BASE_SCRATCH_MNT}/${OVL_UPPER}
43 mkdir -p $lowerdir
44 touch ${lowerdir}/attr_file1
45 chmod 000 ${lowerdir}/attr_file1
46 touch ${lowerdir}/attr_file2
47 chmod 000 ${lowerdir}/attr_file2
48
49 _scratch_mount
50
51 # copy up by change mode bits and check.
52 chmod a+x ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
53 chmod o-w ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
54 chmod g+w ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
55 chmod u-r ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
56 chmod a+X ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
57 chmod o-s ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
58 chmod g+t ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
59 chmod u-X ${SCRATCH_MNT}/attr_file1 > /dev/null 2>&1
60 stat -c %a ${SCRATCH_MNT}/attr_file1
61
62 # unprivileged user can't do this.
63 _user_do "chmod a+x ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
64 _user_do "chmod o-w ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
65 _user_do "chmod g+w ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
66 _user_do "chmod u-r ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
67 _user_do "chmod a+X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
68 _user_do "chmod o-s ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
69 _user_do "chmod g+t ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
70 _user_do "chmod u-X ${SCRATCH_MNT}/attr_file2 > /dev/null 2>&1"
71 stat -c %a ${SCRATCH_MNT}/attr_file2
72
73 # unmount overlayfs but not base fs
74 $UMOUNT_PROG $SCRATCH_MNT
75
76 # check mode bits of the file that has been copied up, and
77 # the file that should not have been copied up.
78 stat -c %a ${upperdir}/attr_file1
79 ls ${upperdir}/
80
81 # success, all done
82 status=0
83 exit