finish off the tests restructuring.
[xfstests-dev.git] / common.quota
1 ##/bin/sh
2 #
3 # Functions useful for quota tests
4
5 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
6
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of version 2 of the GNU General Public License as
9 # published by the Free Software Foundation.
10
11 # This program is distributed in the hope that it would be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 # Further, this software is distributed without any warranty that it is
16 # free of the rightful claim of any third person regarding infringement
17 # or the like.  Any license provided herein, whether implied or
18 # otherwise, applies only to this software file.  Patent licenses, if
19 # any, provided herein do not apply to combinations of this program with
20 # other software, or any other product whatsoever.
21
22 # You should have received a copy of the GNU General Public License along
23 # with this program; if not, write the Free Software Foundation, Inc., 59
24 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
25
26 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 # Mountain View, CA  94043, or:
28
29 # http://www.sgi.com 
30
31 # For further information regarding this notice, see: 
32
33 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #
35
36
37 # checks that the XFS quota support in the kernel is enabled
38 # and that we have valid quota user tools installed.
39
40 _require_quota()
41 {
42     [ ! -x /usr/sbin/repquota ] && _notrun "Quota user tools not installed"
43
44     /usr/sbin/repquota -m -s -a >/dev/null 2>&1
45     [ $? -ne 0 ] && _notrun "Installed quota tools do not support XFS"
46
47     [ ! -f /proc/fs/xfs/xqm ] && _notrun "Kernel does not support XFS quota"
48 }
49
50 # create a file as a specific user (uid)
51 # takes filename, id, type (u/g), blocksize, blockcount
52
53 _file_as_id()
54 {
55     [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
56
57     if [ $3 = u ]
58     then
59         magik='$>'      # perlspeak for effective uid
60     elif [ $3 = g ]
61     then
62         magik='$)'      # perlspeak for effective gid
63     else
64         _notrun "broken type in call to _file_as_id in test $seq"
65     fi
66
67     perl <<EOF
68         \$| = 1;
69         $magik = $2;
70         exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
71 EOF
72 }
73
74 _choose_uid()
75 {
76     perl -ne '@a = split(/:/); END { print $a[2]; }' /etc/passwd
77 }
78
79 _choose_gid()
80 {
81     perl -ne '@a = split(/:/); END { print $a[2]; }' /etc/group
82 }
83
84 _filter_repquota()
85 {
86     perl -ne 's/^(\w+)\s+([-|+])/[NAME]    \2/g; print'
87 }
88
89
90 # make sure this script returns success
91 /bin/true