Fix build - bsd changes from awhile ago introduced a m4 macro bug, only
[xfstests-dev.git] / 021
1 #! /bin/sh
2 # XFS QA Test No. 021
3 # $Id: 1.1 $
4 #
5 # xfs_db type attr test (pv 797508 linux-xfs & IRIX)
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=dxm@sgi.com
41
42 seq=`basename $0`
43 echo "QA output created by $seq"
44
45 here=`pwd`
46 tmp=/tmp/$$
47 status=0        # success is the default!
48 # get standard environment, filters and checks
49 . ./common.rc
50 . ./common.filter
51
52 _cleanup()
53 {
54         echo "*** unmount"
55         umount $SCRATCH_MNT 2>/dev/null
56         rm -f $tmp.*
57 }
58 trap "_cleanup; exit \$status" 0 1 2 3 15
59
60 _attr()
61 {
62         attr $* 2>$tmp.err >$tmp.out
63         exit=$?
64         sed \
65             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
66             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
67                 $tmp.out
68         sed \
69             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
70             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
71                 $tmp.err 1>&2
72         return $exit
73 }
74
75 _getfattr()
76 {
77         getfattr $* 2>$tmp.err >$tmp.out
78         exit=$?
79         sed \
80             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
81             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
82                 $tmp.out
83         sed \
84             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
85             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
86                 $tmp.err 1>&2
87         return $exit
88 }
89
90 # real QA test starts here
91 _require_scratch
92
93 rm -f $seq.full
94 umount $SCRATCH_DEV >/dev/null 2>&1
95
96 echo "*** mkfs"
97 mkfs_xfs $SCRATCH_DEV >/dev/null \
98         || _fail "mkfs failed"
99
100 echo "*** mount FS"
101 mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >/dev/null \
102         || _fail "mount failed"
103
104 testfile=$SCRATCH_MNT/testfile
105 echo "*** make test file 1"
106
107 touch $testfile.1
108 echo "v1" | _attr -s "a1" $testfile.1 >/dev/null
109 echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null
110 _getfattr --absolute-names $testfile.1
111 inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'`
112
113 echo "*** make test file 2"
114
115 touch $testfile.2
116 echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null
117 echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null
118 ( echo start ; dd if=/dev/zero bs=65525 count=1 ; echo end ) \
119         | _attr -s "a3" $testfile.2 >/dev/null
120 _getfattr --absolute-names $testfile.2
121
122 # print name and size from 1st line of output
123 _attr -g "a3" $testfile.2 > $tmp.hahahahaplonk
124 head -1 $tmp.hahahahaplonk
125 # NOTE:
126 # Above goo works around some truly bizzaro sh/sed/head interaction
127 # for some versions of these tools (fails on Redhat 7+, 6.2 worked)
128
129 # print out the rest of the data apart from the header
130 # the size is +1 for an extra \n at the end
131 echo -n "size of attr value = "
132 _attr -g "a3" $testfile.2 | tail -3 | wc -c
133 echo ""
134
135 inum_2=`ls -li $testfile.2 | $AWK_PROG '{ print $1 }'`
136         
137 echo "*** unmount FS"
138 umount $SCRATCH_DEV >>$seq.full 2>&1 \
139         || _fail "umount failed"
140
141 echo "*** dump attributes (1)"
142
143 xfs_db -r -c "inode $inum_1" -c "print a.sfattr" $SCRATCH_DEV
144
145 echo "*** dump attributes (2)"
146
147 xfs_db -r -c "inode $inum_2" -c "a a.bmx[0].startblock" -c print $SCRATCH_DEV \
148         | perl -ne '
149 s/^(hdr.firstused =) (\d+)/\1 FIRSTUSED/;
150 s/^(hdr.freemap\[0-2] = \[base,size]).*/\1 [FREEMAP..]/;
151 s/^(entries\[0-2] = \[hashval,nameidx,incomplete,root,local]).*/\1 [ENTRIES..]/;
152         print;'
153
154 echo "*** done"
155 exit