generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / overlay / 027
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 027
6 #
7 # If underlying upper file is immutable, it should stays
8 # untouchable in the overlayfs mount.
9 #
10 # Kernel commit below fixed it.
11 # f2b20f6ee842 vfs: move permission checking into ...
12 #
13 # This reproducer was originally written by
14 #     Miklos Szeredi <mszeredi@redhat.com>
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         $CHATTR_PROG -i $upperdir/foo
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs overlay
43 _require_scratch
44 _require_chattr i
45
46 # Remove all files from previous tests
47 _scratch_mkfs
48
49 # Preparing immutable file
50 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
51 mkdir -p $upperdir
52 touch $upperdir/foo
53 $CHATTR_PROG +i $upperdir/foo
54
55 # Mounting overlay
56 _scratch_mount
57
58 # Touching immutable file in overlay, should fail.
59 # Not filtering output here because of errno returned
60 # varies among kernel versions:
61 #   touch: setting times of 'foo': Operation not permitted
62 #   touch: cannot touch 'foo': Permission denied
63 if touch $SCRATCH_MNT/foo > /dev/null 2>&1 ; then
64         echo "Test Fail, you can't change an immutable file"
65 else
66         echo "Silence is golden"
67 fi
68
69 # success, all done
70 status=0
71 exit