2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 CTERA Networks. All Rights Reserved.
7 # Check that we can't set FS_XFLAG_APPEND and FS_XFLAG_IMMUTABLE inode
8 # flags without capbility CAP_LINUX_IMMUTABLE.
10 # This test uses xfs_io chattr, rather than the (e2fsprogs) chattr
11 # program to exercise the FS_IOC_FSSETXATTR ioctl.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # Cleanup of flags on both file in case test is aborted
25 # (i.e. CTRL-C), so we have no immutable/append-only files
26 $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1 >/dev/null 2>&1
27 $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file2 >/dev/null 2>&1
30 rm -rf $tmp.* $workdir
33 # get standard environment, filters and checks
38 # real QA test starts here
43 _require_xfs_io_command "chattr" "ia"
44 _require_command "$CAPSH_PROG" "capsh"
46 workdir="$TEST_DIR/test-$seq"
50 echo "Create the original files"
56 grep -o "Operation not permitted"
59 echo "Try to xfs_io chattr +ia with capabilities CAP_LINUX_IMMUTABLE"
60 $XFS_IO_PROG -f -c "chattr +ia" $workdir/file1
62 echo "Try to xfs_io chattr +ia/-ia without capability CAP_LINUX_IMMUTABLE"
63 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +a' $workdir/file2" 2>&1 | do_filter_output
64 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -c 'chattr +i' $workdir/file2" 2>&1 | do_filter_output
66 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -i' $workdir/file1" 2>&1 | do_filter_output
67 $CAPSH_PROG --drop=cap_linux_immutable -- -c "$XFS_IO_PROG -f -r -c 'chattr -a' $workdir/file1" 2>&1 | do_filter_output
69 echo "Try to xfs_io chattr -ia with capability CAP_LINUX_IMMUTABLE"
70 $XFS_IO_PROG -f -r -c "chattr -ia" $workdir/file1