QA updates
[xfstests-dev.git] / 021
1 #! /bin/sh
2 # XFS QA Test No. 021
3 #
4 # xfs_db type attr test (pv 797508 linux-xfs & IRIX)
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=dxm@sgi.com
40
41 seq=`basename $0`
42 echo "QA output created by $seq"
43
44 here=`pwd`
45 tmp=/tmp/$$
46 status=0        # success is the default!
47 # get standard environment, filters and checks
48 . ./common.rc
49 . ./common.filter
50
51 _cleanup()
52 {
53         echo "*** unmount"
54         umount $SCRATCH_MNT 2>/dev/null
55         rm -f $tmp.*
56 }
57 trap "_cleanup; exit \$status" 0 1 2 3 15
58
59 _attr()
60 {
61         attr $* 2>$tmp.err >$tmp.out
62         exit=$?
63         sed \
64             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
65             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
66                 $tmp.out
67         sed \
68             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
69             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
70                 $tmp.err 1>&2
71         return $exit
72 }
73
74 _getfattr()
75 {
76         getfattr $* 2>$tmp.err >$tmp.out
77         exit=$?
78         sed \
79             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
80             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
81                 $tmp.out
82         sed \
83             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
84             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
85                 $tmp.err 1>&2
86         return $exit
87 }
88
89 # real QA test starts here
90 _require_scratch
91
92 rm -f $seq.full
93 umount $SCRATCH_DEV >/dev/null 2>&1
94
95 echo "*** mkfs"
96 _scratch_mkfs_xfs >/dev/null \
97         || _fail "mkfs failed"
98
99 echo "*** mount FS"
100 _scratch_mount >/dev/null \
101         || _fail "mount failed"
102
103 testfile=$SCRATCH_MNT/testfile
104 echo "*** make test file 1"
105
106 touch $testfile.1
107 echo "v1" | _attr -s "a1" $testfile.1 >/dev/null
108 echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null
109 _getfattr --absolute-names $testfile.1
110 inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'`
111
112 echo "*** make test file 2"
113
114 touch $testfile.2
115 echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null
116 echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null
117 ( echo start; POSIXLY_CORRECT=yes dd if=/dev/zero bs=65525 count=1; echo end )\
118         | _attr -s "a3" $testfile.2 >/dev/null
119 _getfattr --absolute-names $testfile.2
120
121 # print name and size from 1st line of output
122 _attr -g "a3" $testfile.2 > $tmp.hahahahaplonk
123 head -1 $tmp.hahahahaplonk
124 # NOTE:
125 # Above goo works around some truly bizzaro sh/sed/head interaction
126 # for some versions of these tools (fails on Redhat 7+, 6.2 worked)
127
128 # print out the rest of the data apart from the header
129 # the size is +1 for an extra \n at the end
130 echo -n "size of attr value = "
131 _attr -g "a3" $testfile.2 | tail -3 | wc -c
132 echo ""
133
134 inum_2=`ls -li $testfile.2 | $AWK_PROG '{ print $1 }'`
135         
136 echo "*** unmount FS"
137 umount $SCRATCH_DEV >>$seq.full 2>&1 \
138         || _fail "umount failed"
139
140 echo "*** dump attributes (1)"
141
142 xfs_db -r -c "inode $inum_1" -c "print a.sfattr" $SCRATCH_DEV
143
144 echo "*** dump attributes (2)"
145
146 xfs_db -r -c "inode $inum_2" -c "a a.bmx[0].startblock" -c print $SCRATCH_DEV \
147         | perl -ne '
148 s/^(hdr.firstused =) (\d+)/\1 FIRSTUSED/;
149 s/^(hdr.freemap\[0-2] = \[base,size]).*/\1 [FREEMAP..]/;
150 s/^(entries\[0-2] = \[hashval,nameidx,incomplete,root,local]).*/\1 [ENTRIES..]/;
151         print;'
152
153 echo "*** done"
154 exit