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