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