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 https://opensource.org/licenses/CDDL-1.0.
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) 2017 by Fan Yong. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib
33
34#
35#
36# DESCRIPTION:
37#	Check project ID/flags can be set/inherited properly
38#
39#
40# STRATEGY:
41#	1. Create a regular file and a directory.
42#	2. Set project ID on both directory and regular file.
43#	3. New created subdir or regular file should inherit its parent's
44#	   project ID if its parent has project inherit flag.
45#	4. New created subdir should inherit its parent project's inherit flag.
46#
47
48function cleanup
49{
50	log_must rm -f $PRJFILE
51	log_must rm -rf $PRJDIR
52}
53
54if ! lsattr -pd > /dev/null 2>&1; then
55	log_unsupported "Current e2fsprogs does not support set/show project ID"
56fi
57
58#
59# e2fsprogs-1.44.4 incorrectly reports verity 'V' bit when the project 'P'
60# bit is set.  Skip this test when 1.44.4 is installed to prevent failures.
61#
62# https://github.com/tytso/e2fsprogs/commit/7e5a95e3d
63#
64if lsattr -V 2>&1 | grep "lsattr 1.44.4"; then
65	log_unsupported "Current e2fsprogs incorrectly reports 'V' verity bit"
66fi
67
68log_onexit cleanup
69
70log_assert "Check project ID/flags can be set/inherited properly"
71
72log_must touch $PRJFILE
73log_must mkdir $PRJDIR
74
75log_must chattr -p $PRJID1 $PRJFILE
76log_must eval "lsattr -p $PRJFILE | grep $PRJID1 | grep -v '\-P[- ]* '"
77log_must chattr -p $PRJID1 $PRJDIR
78log_must eval "lsattr -pd $PRJDIR | grep $PRJID1 | grep -v '\-P[- ]* '"
79
80log_must chattr +P $PRJDIR
81log_must eval "lsattr -pd $PRJDIR | grep $PRJID1 | grep '\-P[- ]* '"
82
83# "-1" is invalid project ID, should be denied
84log_mustnot chattr -p -1 $PRJFILE
85log_must eval "lsattr -p $PRJFILE | grep $PRJID1 | grep -v '\-P[- ]* '"
86
87log_must mkdir $PRJDIR/dchild
88log_must eval "lsattr -pd $PRJDIR/dchild | grep $PRJID1 | grep '\-P[- ]* '"
89log_must touch $PRJDIR/fchild
90log_must eval "lsattr -p $PRJDIR/fchild | grep $PRJID1"
91
92log_must touch $PRJDIR/dchild/foo
93log_must eval "lsattr -p $PRJDIR/dchild/foo | grep $PRJID1"
94
95# not support project ID/flag on symlink
96log_must ln -s $PRJDIR/dchild/foo $PRJDIR/dchild/s_foo
97log_mustnot lsattr -p $PRJDIR/dchild/s_foo
98log_mustnot chattr -p 123 $PRJDIR/dchild/s_foo
99log_mustnot chattr +P $PRJDIR/dchild/s_foo
100
101# not support project ID/flag on block special file
102log_must mknod $PRJDIR/dchild/b_foo b 124 124
103log_mustnot lsattr -p $PRJDIR/dchild/b_foo
104log_mustnot chattr -p 123 $PRJDIR/dchild/b_foo
105log_mustnot chattr +P $PRJDIR/dchild/b_foo
106
107# not support project ID/flag on character special file
108log_must mknod $PRJDIR/dchild/c_foo c 125 125
109log_mustnot lsattr -p $PRJDIR/dchild/c_foo
110log_mustnot chattr -p 123 $PRJDIR/dchild/c_foo
111log_mustnot chattr +P $PRJDIR/dchild/c_foo
112
113log_pass "Check project ID/flags can be set/inherited properly"
114