2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 CTERA Networks. All Rights Reserved.
7 # Run the t_immutable test program for immutable/append-only files
8 # and directories that exist in overlayfs lower layer.
10 # This test is similar and was derived from generic/079, but instead
11 # of creating new files which are created in upper layer, prepare
12 # the test area in lower layer before running the t_immutable test on
13 # the overlayfs mount.
16 _begin_fstest auto quick perms
18 timmutable=$here/src/t_immutable
19 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
20 upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
22 # Override the default cleanup function.
25 # -r will fail to remove test dirs, because we added subdirs
26 # we just need to remove the flags so use -R
27 $timmutable -R $upperdir/testdir &> /dev/null
28 $timmutable -R $lowerdir/testdir &> /dev/null
29 $timmutable -R $lowerdir/testdir.before &> /dev/null
33 # Import common functions.
39 _require_test_program "t_immutable"
44 # Check chattr support of base fs
47 $timmutable -C $lowerdir/testdir.before >$tmp.out 2>&1
48 if grep -q -e 'Operation not supported' -e "Inappropriate ioctl" $tmp.out; then
49 _notrun "Setting immutable/append flag not supported"
52 # Prepare test area files in lower dir
53 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
54 # Remove the immutable/append-only flags and create subdirs
55 $timmutable -R $lowerdir/testdir >$tmp.out 2>&1
56 for dir in $lowerdir/testdir/*.d; do
59 # Restore the immutable/append-only flags
60 $timmutable -C $lowerdir/testdir >$tmp.out 2>&1
64 # Test immutability of files in overlay before copy up
65 echo "Before directories copy up"
66 $timmutable $SCRATCH_MNT/testdir.before 2>&1
67 # Remove the immutable/append-only flags before mount cycle
68 $timmutable -R $SCRATCH_MNT/testdir.before &> /dev/null
70 # Trigger copy-up of immutable/append-only dirs by touching their subdirs
71 # inode flags are not copied-up, so immutable/append-only flags are lost
72 for dir in $SCRATCH_MNT/testdir/*.d; do
76 # Trigger copy-up of append-only files by touching them
77 # inode flags are not copied-up, so append-only flags are lost
78 # touch on the immutable files is expected to fail, so immutable
79 # flags will not be lost
80 for file in $SCRATCH_MNT/testdir/*.f; do
81 touch $file > /dev/null 2>&1
84 # immutable/append-only flags still exist on the overlay in-core inode
85 # After mount cycle, flags are forever lost
88 # Verify that files can be deleted from overlay fs after clearing
89 # immutable/append-only flags and mount cycle
90 rm -rf $SCRATCH_MNT/testdir.before
92 # Test immutability of files in overlay after directories copy-up
93 echo "After directories copy up"
94 $timmutable $SCRATCH_MNT/testdir 2>&1
96 # Verify that files can be deleted from overlay fs after clearing
97 # immutable/append-only flags
98 $timmutable -R $SCRATCH_MNT/testdir &> /dev/null
99 rm -rf $SCRATCH_MNT/testdir