xfstests: randholes: a few final cleanups
[xfstests-dev.git] / 021
1 #! /bin/bash
2 # FS 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
10 # modify it under the terms 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,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24 # creator
25 owner=dxm@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=0        # success is the default!
33 # get standard environment, filters and checks
34 . ./common.rc
35 . ./common.filter
36
37 _cleanup()
38 {
39         echo "*** unmount"
40         umount $SCRATCH_MNT 2>/dev/null
41         rm -f $tmp.*
42 }
43 trap "_cleanup; exit \$status" 0 1 2 3 15
44
45 _attr()
46 {
47         attr $* 2>$tmp.err >$tmp.out
48         exit=$?
49         sed \
50             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
51             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
52                 $tmp.out
53         sed \
54             -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
55             -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
56                 $tmp.err 1>&2
57         return $exit
58 }
59
60 _getfattr()
61 {
62         getfattr $* 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 # real QA test starts here
76 _supported_fs xfs
77 _supported_os Linux
78
79 [ -n $ATTR_PROG ] || _notrun "attr is not installed"
80 [ -n $GETFATTR_PROG ] || _notrun "getfattr is not installed"
81
82 _require_scratch
83
84 rm -f $seq.full
85 umount $SCRATCH_DEV >/dev/null 2>&1
86
87 echo "*** mkfs"
88 _scratch_mkfs_xfs >/dev/null \
89         || _fail "mkfs failed"
90
91 echo "*** mount FS"
92 _scratch_mount >/dev/null \
93         || _fail "mount failed"
94
95 testfile=$SCRATCH_MNT/testfile
96 echo "*** make test file 1"
97
98 touch $testfile.1
99 echo "v1" | _attr -s "a1" $testfile.1 >/dev/null
100 echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null
101 _getfattr --absolute-names $testfile.1
102 inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'`
103
104 echo "*** make test file 2"
105
106 touch $testfile.2
107 echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null
108 echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null
109 ( echo start; POSIXLY_CORRECT=yes dd if=/dev/zero bs=65525 count=1; echo end )\
110         | _attr -s "a3" $testfile.2 >/dev/null
111 _getfattr --absolute-names $testfile.2
112
113 # print name and size from 1st line of output
114 _attr -g "a3" $testfile.2 > $tmp.hahahahaplonk
115 head -1 $tmp.hahahahaplonk
116 # NOTE:
117 # Above goo works around some truly bizzaro sh/sed/head interaction
118 # for some versions of these tools (fails on Redhat 7+, 6.2 worked)
119
120 # print out the rest of the data apart from the header
121 # the size is +1 for an extra \n at the end
122 echo -n "size of attr value = "
123 # wc inserts different amounts of whitespace in front...
124 _attr -g "a3" $testfile.2 | tail -3 | wc -c | sed -e "s/^ *//"
125 echo ""
126
127 inum_2=`ls -li $testfile.2 | $AWK_PROG '{ print $1 }'`
128
129 echo "*** unmount FS"
130 umount $SCRATCH_DEV >>$seq.full 2>&1 \
131         || _fail "umount failed"
132
133 echo "*** dump attributes (1)"
134
135 xfs_db -r -c "inode $inum_1" -c "print a.sfattr" $SCRATCH_DEV | \
136         sed -e '/secure = /d' | sed -e '/parent = /d'
137
138 echo "*** dump attributes (2)"
139
140 xfs_db -r -c "inode $inum_2" -c "a a.bmx[0].startblock" -c print $SCRATCH_DEV \
141         | perl -ne '
142 s/,secure//;
143 s/,parent//;
144 s/^(hdr.firstused =) (\d+)/\1 FIRSTUSED/;
145 s/^(hdr.freemap\[0-2] = \[base,size]).*/\1 [FREEMAP..]/;
146 s/^(entries\[0-2] = \[hashval,nameidx,incomplete,root,local]).*/\1 [ENTRIES..]/;
147         print;'
148
149 echo "*** done"
150 exit