generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 545
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Alibaba Group.  All Rights Reserved.
4 #
5 # FS QA Test No. 545
6 #
7 # Check that we can't set the FS_APPEND_FL and FS_IMMUTABLE_FL inode
8 # flags without capbility CAP_LINUX_IMMUTABLE
9 #
10 . ./common/preamble
11 _begin_fstest auto quick cap
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         # Cleanup of flags on both file in case test is aborted
17         # (i.e. CTRL-C), so we have no immutable/append-only files
18         $CHATTR_PROG -ia $workdir/file1 >/dev/null 2>&1
19         $CHATTR_PROG -ia $workdir/file2 >/dev/null 2>&1
20
21         cd /
22         rm -rf $tmp.* $workdir
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/attr
28
29 # real QA test starts here
30 _supported_fs generic
31
32 _require_test
33 _require_chattr i
34 _require_chattr a
35 _require_command "$CAPSH_PROG" "capsh"
36
37 workdir="$TEST_DIR/test-$seq"
38 rm -rf $workdir
39 mkdir $workdir
40
41 echo "Create the original files"
42 touch $workdir/file1
43 touch $workdir/file2
44
45 do_filter_output()
46 {
47         grep -o "Operation not permitted"
48 }
49
50 echo "Try to chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
51 $CHATTR_PROG +a $workdir/file1
52 $CHATTR_PROG +i $workdir/file1
53
54 echo "Try to chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
55 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +a $workdir/file2" 2>&1 | do_filter_output
56 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG +i $workdir/file2" 2>&1 | do_filter_output
57
58 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -i $workdir/file1" 2>&1 | do_filter_output
59 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$CHATTR_PROG -a $workdir/file1" 2>&1 | do_filter_output
60
61 echo "Try to chattr -ia with capability CAP_LINUX_IMMUTABLE"
62 $CHATTR_PROG -i $workdir/file1
63 $CHATTR_PROG -a $workdir/file1
64
65 # success, all done
66 status=0
67 exit