Very minor tidyups in the report headers for bonnie runs.
[xfstests-dev.git] / common.attr
1 ##/bin/sh
2
3 #
4 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of version 2 of the GNU General Public License as
8 # published by the Free Software Foundation.
9
10 # This program is distributed in the hope that it would be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 # Further, this software is distributed without any warranty that it is
15 # free of the rightful claim of any third person regarding infringement
16 # or the like.  Any license provided herein, whether implied or
17 # otherwise, applies only to this software file.  Patent licenses, if
18 # any, provided herein do not apply to combinations of this program with
19 # other software, or any other product whatsoever.
20
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, write the Free Software Foundation, Inc., 59
23 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
24
25 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 # Mountain View, CA  94043, or:
27
28 # http://www.sgi.com 
29
30 # For further information regarding this notice, see: 
31
32 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #
34
35 # common extended attribute and ACL support
36
37 # pick three unused user/group ids, store them as $acl[1-3]
38 #
39 _acl_setup_ids()
40 {
41     eval `cat /etc/passwd /etc/group | awk -F: '
42       { ids[$3]=1 }
43       END {
44         j=1
45         for(i=1; i<1000000 && j<=3;i++){
46           if (! (i in ids)) {
47              printf "acl%d=%d;", j, i;           
48              j++
49           }
50         }       
51       }'`
52 }
53
54 # filter for the acl ids selected above
55 #
56 _acl_filter_id()
57 {
58     sed \
59        -e "s/u:$acl1/u:id1/" \
60        -e "s/u:$acl2/u:id2/" \
61        -e "s/u:$acl3/u:id3/" \
62        -e "s/g:$acl1/g:id1/" \
63        -e "s/g:$acl2/g:id2/" \
64        -e "s/g:$acl3/g:id3/" \
65        -e "s/ $acl1 / id1 /" \
66        -e "s/ $acl2 / id2 /" \
67        -e "s/ $acl3 / id3 /"
68 }
69
70 # filtered ls
71 #
72 _acl_ls()
73 {
74     ls -ln $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
75
76
77 # create an ACL with n ACEs in it
78 #
79 _create_n_aces()
80 {
81     n=`expr $1 - 4`
82     acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
83     while [ $n -ne 0 ]; do
84        acl="$acl,u:$n:rwx"
85        n=`expr $n - 1` 
86     done
87     echo $acl
88 }
89
90 # filter user ace names to user ids
91 #
92 _filter_aces()
93 {
94     $AWK_PROG '
95         BEGIN {
96             FS=":"
97             while ( getline <"/etc/passwd" > 0 ) {
98                 idlist[$1] = $3 
99             }
100         }
101         /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
102         /^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
103         {print}
104     '
105 }
106
107 # test if acl code will work
108 #
109 _acl_requirements()
110 {
111     xfsdir=$TEST_DIR
112
113     if [ ! -x /bin/chacl -a ! -x /usr/bin/chacl ]; then
114         _notrun "chacl command not found"
115     fi
116
117     # test if acl_get syscall is operational
118     # and hence the ACL config has been turned on  
119     touch $xfsdir/syscalltest
120     if chacl -l $xfsdir/syscalltest 2>&1 | tee -a $here/$seq.full | grep 'Function not implemented' >/dev/null
121     then
122       cd $here
123       _notrun "requires kernel ACL support"
124     fi
125 }
126
127 # make sure this script returns success
128 /bin/true