]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh
MFV r365636: libarchive: import fix for WARNS=6 builds in testing bits
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / chattr / chattr_001_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2013 by Delphix. All rights reserved.
30 #
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib
33
34 #
35 #
36 # DESCRIPTION:
37 #       Check whether chattr works as expected
38 #
39 #
40 # STRATEGY:
41 #       1. Create 3 files
42 #       2. Use chattr to make them writable, immutable and appendonly
43 #       3. Try to write and append to each file
44 #
45
46 set -A files writable immutable append
47
48 function cleanup
49 {
50         for i in ${files[*]}; do
51                 if is_freebsd ; then
52                         log_must chflags noschg $TESTDIR/$i
53                         log_must rm -f $TESTDIR/$i
54                 else
55                         log_must chattr -ia $TESTDIR/$i
56                         log_must rm -f $TESTDIR/$i
57                 fi
58         done
59 }
60
61 log_onexit cleanup
62
63 if is_freebsd ; then
64         log_assert "Check whether chflags works as expected"
65 else
66         log_assert "Check whether chattr works as expected"
67 fi
68
69 log_must touch $TESTDIR/writable
70 log_must touch $TESTDIR/immutable
71 log_must touch $TESTDIR/append
72
73 if is_freebsd ; then
74         log_must chflags noschg $TESTDIR/writable
75         log_must chflags schg $TESTDIR/immutable
76         log_must chflags sappnd $TESTDIR/append
77 else
78         log_must chattr -i $TESTDIR/writable
79         log_must chattr +i $TESTDIR/immutable
80         log_must chattr +a $TESTDIR/append
81 fi
82
83 log_must eval "echo test > $TESTDIR/writable"
84 log_must eval "echo test >> $TESTDIR/writable"
85 log_mustnot eval "echo test > $TESTDIR/immutable"
86 log_mustnot eval "echo test >> $TESTDIR/immutable"
87 log_mustnot eval "echo test > $TESTDIR/append"
88 log_must eval "echo test >> $TESTDIR/append"
89
90 if is_freebsd ; then
91         log_pass "chflags works as expected"
92 else
93         log_pass "chattr works as expected"
94 fi