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