summaryrefslogtreecommitdiff
path: root/tests/xfs/021
blob: 9432e2acb069e1cb68215aef05d3997eca444f87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# FS QA Test No. 021
#
# xfs_db type attr test (pv 797508 linux-xfs & IRIX)
#
. ./common/preamble
_begin_fstest db attr auto quick

status=0	# success is the default!
# Import common functions.
. ./common/filter
. ./common/attr

# Override the default cleanup function.
_cleanup()
{
	echo "*** unmount"
	_scratch_unmount 2>/dev/null
	rm -f $tmp.*
}

_attr()
{
	${ATTR_PROG} $* 2>$tmp.err >$tmp.out
	exit=$?
	sed \
	    -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
	    -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
		$tmp.out
	sed \
	    -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
	    -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
		$tmp.err 1>&2
	return $exit
}

do_getfattr()
{
	_getfattr $* 2>$tmp.err >$tmp.out
	exit=$?
	sed \
	    -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
	    -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
		$tmp.out
	sed \
	    -e "s#$SCRATCH_MNT[^ .:]*#<TESTFILE>#g" \
	    -e "s#$tmp[^ :]*#<TMPFILE>#g;" \
		$tmp.err 1>&2
	return $exit
}

# real QA test starts here
_supported_fs xfs

_require_scratch
_require_attrs

_scratch_unmount >/dev/null 2>&1

echo "*** mkfs"
_scratch_mkfs_xfs >/dev/null \
	|| _fail "mkfs failed"

echo "*** mount FS"
_scratch_mount

testfile=$SCRATCH_MNT/testfile
echo "*** make test file 1"

touch $testfile.1
echo "v1" | _attr -s "a1" $testfile.1 >/dev/null
echo "v2--" | _attr -s "a2--" $testfile.1 >/dev/null
do_getfattr --absolute-names $testfile.1
inum_1=`ls -li $testfile.1 | $AWK_PROG '{ print $1 }'`

echo "*** make test file 2"

touch $testfile.2
echo "value_1" | _attr -s "a1" $testfile.2 >/dev/null
echo "value_2" | _attr -s "a2-----" $testfile.2 >/dev/null
( echo start; POSIXLY_CORRECT=yes dd if=/dev/zero bs=65525 count=1; echo end )\
	| _attr -s "a3" $testfile.2 >/dev/null
do_getfattr --absolute-names $testfile.2

# print name and size from 1st line of output
_attr -g "a3" $testfile.2 > $tmp.hahahahaplonk
head -1 $tmp.hahahahaplonk
# NOTE:
# Above goo works around some truly bizzaro sh/sed/head interaction
# for some versions of these tools (fails on Redhat 7+, 6.2 worked)

# print out the rest of the data apart from the header
# the size is +1 for an extra \n at the end
echo -n "size of attr value = "
# wc inserts different amounts of whitespace in front...
_attr -g "a3" $testfile.2 | tail -3 | wc -c | sed -e "s/^ *//"
echo ""

inum_2=`ls -li $testfile.2 | $AWK_PROG '{ print $1 }'`

echo "*** unmount FS"
_scratch_unmount >>$seqres.full 2>&1 \
	|| _fail "umount failed"

echo "*** dump attributes (1)"

_scratch_xfs_db -r -c "inode $inum_1" -c "print a.sfattr"  | \
	sed -e '/secure = /d' | sed -e '/parent = /d'

echo "*** dump attributes (2)"

# There is a fair bit of filtering here to convert v5 filesystem output
# into the v4 format that holds the meaningful information for the test.
_scratch_xfs_db -r -c "inode $inum_2" -c "a a.bmx[0].startblock" -c print  \
	| perl -ne '
s/,secure//;
s/,parent//;
s/info.hdr/info/;
/hdr.info.crc/ && next;
/hdr.info.bno/ && next;
/hdr.info.uuid/ && next;
/hdr.info.lsn/ && next;
/hdr.info.owner/ && next;
s/^(hdr.info.magic =) 0x3bee/\1 0xfbee/;
s/^(hdr.firstused =) (\d+)/\1 FIRSTUSED/;
s/^(hdr.freemap\[0-2] = \[base,size]).*/\1 [FREEMAP..]/;
s/^(entries\[0-2] = \[hashval,nameidx,incomplete,root,local]).*/\1 [ENTRIES..]/;
	print unless /^\d+:\[.*/;'

echo "*** done"
exit