2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
7 # xfs_db type attr test (pv 797508 linux-xfs & IRIX)
10 _begin_fstest db attr auto quick
12 status=0 # success is the default!
13 # Import common functions.
17 # Override the default cleanup function.
21 _scratch_unmount 2>/dev/null
27 ${ATTR_PROG} $* 2>$tmp.err >$tmp.out
30 -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
31 -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
34 -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
35 -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
42 _getfattr $* 2>$tmp.err >$tmp.out
45 -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
46 -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
49 -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
50 -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
55 # real QA test starts here
61 _scratch_unmount >/dev/null 2>&1
64 _scratch_mkfs_xfs >/dev/null \
65 || _fail "mkfs failed"
70 testfile=$SCRATCH_MNT/testfile
71 echo "*** make test file 1"
74 echo "v1" | _attr -s "a1" $testfile.1 >/dev/null
75 echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null
76 do_getfattr --absolute-names $testfile.1
77 inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'`
79 echo "*** make test file 2"
82 echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null
83 echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null
84 ( echo start; POSIXLY_CORRECT=yes dd if=/dev/zero bs=65525 count=1; echo end )\
85 | _attr -s "a3" $testfile.2 >/dev/null
86 do_getfattr --absolute-names $testfile.2
88 # print name and size from 1st line of output
89 _attr -g "a3" $testfile.2 > $tmp.hahahahaplonk
90 head -1 $tmp.hahahahaplonk
92 # Above goo works around some truly bizzaro sh/sed/head interaction
93 # for some versions of these tools (fails on Redhat 7+, 6.2 worked)
95 # print out the rest of the data apart from the header
96 # the size is +1 for an extra \n at the end
97 echo -n "size of attr value = "
98 # wc inserts different amounts of whitespace in front...
99 _attr -g "a3" $testfile.2 | tail -3 | wc -c | sed -e "s/^ *//"
102 inum_2=`ls -li $testfile.2 | $AWK_PROG '{ print $1 }'`
104 echo "*** unmount FS"
105 _scratch_unmount >>$seqres.full 2>&1 \
106 || _fail "umount failed"
108 echo "*** dump attributes (1)"
110 _scratch_xfs_db -r -c "inode $inum_1" -c "print a.sfattr" | \
111 sed -e '/secure = /d' | sed -e '/parent = /d'
113 echo "*** dump attributes (2)"
115 # There is a fair bit of filtering here to convert v5 filesystem output
116 # into the v4 format that holds the meaningful information for the test.
117 _scratch_xfs_db -r -c "inode $inum_2" -c "a a.bmx[0].startblock" -c print \
122 /hdr.info.crc/ && next;
123 /hdr.info.bno/ && next;
124 /hdr.info.uuid/ && next;
125 /hdr.info.lsn/ && next;
126 /hdr.info.owner/ && next;
127 s/^(hdr.info.magic =) 0x3bee/\1 0xfbee/;
128 s/^(hdr.firstused =) (\d+)/\1 FIRSTUSED/;
129 s/^(hdr.freemap\[0-2] = \[base,size]).*/\1 [FREEMAP..]/;
130 s/^(entries\[0-2] = \[hashval,nameidx,incomplete,root,local]).*/\1 [ENTRIES..]/;
131 print unless /^\d+:\[.*/;'