3 # Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # Functions useful for quota tests
24 # checks that the generic quota support in the kernel is enabled
25 # and that we have valid quota user tools installed.
29 [ -x /usr/bin/quota ] || _notrun "Quota user tools not installed"
30 _scratch_mount "-o usrquota,grpquota"
33 [ $ret -ne 0 ] && _notrun "Installed kernel does not support quota"
37 # checks that the XFS quota support in the kernel is enabled
38 # and that we have valid quota user tools installed.
42 src/feature -q $TEST_DEV
43 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
44 [ -x /usr/sbin/xfs_quota ] || _notrun "XFS quota user tools not installed"
48 # checks that the XFS project quota support in the kernel is enabled.
52 src/feature -p $TEST_DEV
53 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
57 # checks for user nobody in /etc/passwd and /etc/group.
61 grep -q '^nobody' /etc/passwd
62 [ $? -ne 0 ] && _notrun "/etc/passwd does not contain user nobody."
64 egrep -q '^no(body|group)' /etc/group
65 [ $? -ne 0 ] && _notrun "/etc/group does not contain nobody/nogroup."
68 # create a file as a specific user (uid)
69 # takes filename, id, type (u/g/p), blocksize, blockcount
73 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
77 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
78 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
79 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
81 magik='$>' # perlspeak for effective uid
83 magik='$)' # perlspeak for effective gid
85 _notrun "broken type in call to _file_as_id in test $seq"
88 perl <<EOF >>$seq.full 2>&1
95 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
96 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
99 # for debugging the above euid change, try... [need write in cwd]
100 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
103 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
104 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
110 grep '^nobody' /etc/passwd | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
115 egrep '^no(body|group)' /etc/group | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
120 if [ "X$projid_file" == "X" ]; then
121 projid_file=/etc/projid
123 if [ ! -f $projid_file ]; then
127 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
133 umount $SCRATCH_DEV >/dev/null 2>&1
134 _scratch_mount || _fail "qmount failed"
135 chmod ugo+rwx $SCRATCH_MNT
140 # setup exactly what it is we'll be testing
142 if src/feature -u $SCRATCH_DEV
146 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
147 elif src/feature -g $SCRATCH_DEV
151 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
152 elif src/feature -p $SCRATCH_DEV
156 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
157 elif src/feature -U $SCRATCH_DEV
161 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
163 elif src/feature -G $SCRATCH_DEV
167 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
169 elif src/feature -P $SCRATCH_DEV
173 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
176 _notrun "No quota support at mount time"
179 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
180 echo "and using type=$type id=$id" >>$seq.full
184 # Ensures only the given quota mount option is used
188 # Replace any user defined quota options
189 # with the quota option that we want.
190 # Simplest to do this rather than delete existing ones first because
191 # of the variety of commas and spaces and multiple -o's
192 # that we'd have to cater for. Doesn't matter if we have duplicates.
193 # Use "QUOTA" string so that we don't have any substring confusion
194 # thanks to "quota" which will match with "uquota" and "gquota" etc.
195 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
196 | sed -e 's/uquota/QUOTA/g' \
197 -e 's/usrquota/QUOTA/g' \
198 -e 's/gquota/QUOTA/g' \
199 -e 's/grpquota/QUOTA/g' \
200 -e 's/pquota/QUOTA/g' \
201 -e 's/quota/QUOTA/g' \
202 -e 's/uqnoenforce/QUOTA/g' \
203 -e 's/gqnoenforce/QUOTA/g' \
204 -e 's/pqnoenforce/QUOTA/g' \
205 -e 's/qnoenforce/QUOTA/g' \
208 # Ensure we have the given quota option - duplicates are fine
209 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
210 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
213 # make sure this script returns success