Rework test 018 slightly so that its more user friendly when it fails
[xfstests-dev.git] / 054
1 #! /bin/sh
2 # XFS QA Test No. 054
3 #
4 # Check behavior of chown with both user and group quota enabled,
5 # and changing both user and group together via chown(2).
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
9
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
13
14 # This program is distributed in the hope that it would be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like.  Any license provided herein, whether implied or
21 # otherwise, applies only to this software file.  Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
24
25 # You should have received a copy of the GNU General Public License along
26 # with this program; if not, write the Free Software Foundation, Inc., 59
27 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
29 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
30 # Mountain View, CA  94043, or:
31
32 # http://www.sgi.com 
33
34 # For further information regarding this notice, see: 
35
36 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #-----------------------------------------------------------------------
38 #
39 # creator
40 owner=nathans@sgi.com
41
42 seq=`basename $0`
43 echo "QA output created by $seq"
44
45 here=`pwd`
46 tmp=/tmp/$$
47 status=1        # failure is the default!
48
49 # get standard environment, filters and checks
50 . ./common.rc
51 . ./common.filter
52 . ./common.quota
53
54 _cleanup()
55 {
56         umount $SCRATCH_MNT 2>/dev/null
57         rm -f $tmp.*
58 }
59 trap "_cleanup; exit \$status" 0 1 2 3 15
60 cp /dev/null $seq.full
61 chmod ugo+rwx $seq.full
62
63 _require_scratch
64
65 _filter_stat()
66 {
67     sed "
68         /^Access:/d;
69         /^Modify:/d;
70         /^Change:/d;
71         s/Device: *[0-9][0-9]*,[0-9][0-9]*/Device: <DEVICE>/;
72         s/Inode: *[0-9][0-9]*/Inode: <INODE>/;
73         s,$SCRATCH_MNT,<MOUNT>,;
74     " | tr -s ' '
75 }
76
77 _exercise()
78 {
79         _scratch_mkfs_xfs >/dev/null 2>&1
80         _qmount
81
82         umask 022
83         touch $SCRATCH_MNT/testfile
84         if src/feature -c $SCRATCH_MNT/testfile; then
85                 :
86         else
87                 _notrun "Installed fileutils doesn't support 32 bit uids/gids"
88         fi
89
90         chown 12345 $SCRATCH_MNT/testfile
91         chgrp 54321 $SCRATCH_MNT/testfile
92         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
93
94         chown 34567 $SCRATCH_MNT/testfile
95         chgrp 76543 $SCRATCH_MNT/testfile
96         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
97
98         chown 56789 $SCRATCH_MNT/testfile
99         chgrp 98765 $SCRATCH_MNT/testfile
100         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
101
102         # finally give back to original owners
103         chown 12345 $SCRATCH_MNT/testfile
104         chgrp 54321 $SCRATCH_MNT/testfile
105         src/lstat64 $SCRATCH_MNT/testfile | _filter_stat
106
107         echo
108         umount $SCRATCH_MNT 2>/dev/null
109 }
110
111 # real QA test starts here
112 _scratch_mkfs_xfs $SCRATCH_DEV >/dev/null 2>&1
113 MOUNT_OPTIONS="$MOUNT_OPTIONS -ousrquota,grpquota"; export MOUNT_OPTIONS
114 _qmount
115 if src/feature -G $SCRATCH_DEV ; then
116         :
117 else
118         _notrun "No quota support at mount time"
119 fi
120 umount $SCRATCH_MNT 2>/dev/null
121
122 MOUNT_OPTIONS=""; export MOUNT_OPTIONS
123 echo "*** Default mount options"
124 _exercise
125
126 MOUNT_OPTIONS="-o usrquota"; export MOUNT_OPTIONS
127 echo "*** User quota mount option"
128 _exercise
129
130 MOUNT_OPTIONS="-o grpquota"; export MOUNT_OPTIONS
131 echo "*** Group quota mount option"
132 _exercise
133
134 MOUNT_OPTIONS="-o usrquota,grpquota"; export MOUNT_OPTIONS
135 echo "*** User and Group quota mount options"
136 _exercise
137
138 # success, all done
139 status=0
140 exit