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 XFS quota support in the kernel is enabled
25 # and that we have valid quota user tools installed.
29 src/feature -q $TEST_DEV
30 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
31 [ -x /usr/sbin/xfs_quota ] || _notrun "Quota user tools not installed"
35 # checks that the XFS project quota support in the kernel is enabled.
39 src/feature -p $TEST_DEV
40 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
44 # checks for user nobody in /etc/passwd and /etc/group.
48 grep -q '^nobody' /etc/passwd
49 [ $? -ne 0 ] && _notrun "/etc/passwd does not contain user nobody."
51 egrep -q '^no(body|group)' /etc/group
52 [ $? -ne 0 ] && _notrun "/etc/group does not contain nobody/nogroup."
55 # create a file as a specific user (uid)
56 # takes filename, id, type (u/g/p), blocksize, blockcount
60 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
64 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
65 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
66 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
68 magik='$>' # perlspeak for effective uid
70 magik='$)' # perlspeak for effective gid
72 _notrun "broken type in call to _file_as_id in test $seq"
75 perl <<EOF >>$seq.full 2>&1
82 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
83 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
86 # for debugging the above euid change, try... [need write in cwd]
87 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
90 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
91 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
97 grep '^nobody' /etc/passwd | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
102 egrep '^no(body|group)' /etc/group | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
107 if [ "X$projid_file" == "X" ]; then
108 projid_file=/etc/projid
110 if [ ! -f $projid_file ]; then
114 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
120 umount $SCRATCH_DEV >/dev/null 2>&1
121 _scratch_mount || _fail "qmount failed"
122 chmod ugo+rwx $SCRATCH_MNT
127 # setup exactly what it is we'll be testing
129 if src/feature -u $SCRATCH_DEV
133 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
134 elif src/feature -g $SCRATCH_DEV
138 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
139 elif src/feature -p $SCRATCH_DEV
143 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
144 elif src/feature -U $SCRATCH_DEV
148 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
150 elif src/feature -G $SCRATCH_DEV
154 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
156 elif src/feature -P $SCRATCH_DEV
160 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
163 _notrun "No quota support at mount time"
166 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
167 echo "and using type=$type id=$id" >>$seq.full
171 # Ensures only the given quota mount option is used
175 # Replace any user defined quota options
176 # with the quota option that we want.
177 # Simplest to do this rather than delete existing ones first because
178 # of the variety of commas and spaces and multiple -o's
179 # that we'd have to cater for. Doesn't matter if we have duplicates.
180 # Use "QUOTA" string so that we don't have any substring confusion
181 # thanks to "quota" which will match with "uquota" and "gquota" etc.
182 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
183 | sed -e 's/uquota/QUOTA/g' \
184 -e 's/usrquota/QUOTA/g' \
185 -e 's/gquota/QUOTA/g' \
186 -e 's/grpquota/QUOTA/g' \
187 -e 's/pquota/QUOTA/g' \
188 -e 's/quota/QUOTA/g' \
189 -e 's/uqnoenforce/QUOTA/g' \
190 -e 's/gqnoenforce/QUOTA/g' \
191 -e 's/pqnoenforce/QUOTA/g' \
192 -e 's/qnoenforce/QUOTA/g' \
195 # Ensure we have the given quota option - duplicates are fine
196 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
197 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
200 # make sure this script returns success