--- /dev/null
+#! /bin/sh
+# FS QA Test No. 186
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved.
+#-----------------------------------------------------------------------
+#
+# Test out:
+# pv#979606: xfs bug in going from attr2 back to attr1
+#
+# Test bug in going from attr2 back to attr1 where xfs
+# (due to xfs_attr_shortform_bytesfit)
+# would reset the di_forkoff to the m_offset instead of
+# leaving the di_forkoff alone as was intended.
+#
+# We create enough dirents to push us past m_attroffset,
+# and create an EA so we have a fork offset
+# and then turn on attr1 and add one more EA which
+# will write over the shortform dirents.
+#
+#
+# creator
+owner=tes@emu.melbourne.sgi.com
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+ cd /
+ rm -f $tmp.*
+}
+
+_create_dirents()
+{
+ start_num=$1
+ end_num=$2
+ cd $fork_dir
+ for i in `seq $start_num $end_num`; do
+ touch file.$i
+ done
+}
+
+_create_eas()
+{
+ start_num=$1
+ end_num=$2
+ for i in `seq $start_num $end_num`; do
+ setfattr -n user.$i -v 0xbabe $fork_dir
+ done
+}
+
+_rmv_eas()
+{
+ start_num=$1
+ end_num=$2
+ for i in `seq $start_num $end_num`; do
+ setfattr -x user.$i $fork_dir
+ done
+}
+
+_filter_inode()
+{
+ tee -a $seq.full | egrep '^u.sfdir2|^a.sfattr|core.forkoff' |\
+ egrep -v 'inumber|parent'
+}
+
+_filter_version()
+{
+ tee -a $seq.full | tr ',' '\n' | grep ATTR
+}
+
+_print_inode()
+{
+ echo ""
+ echo "================================="
+ $XFS_DB_PROG -c "version" $SCRATCH_DEV 2>&1 | _filter_version
+ $XFS_DB_PROG -c "inode $inum" -c p $SCRATCH_DEV 2>&1 | _filter_inode
+ echo "================================="
+}
+
+_do_eas()
+{
+ echo ""
+ _scratch_mount
+ if [ $1 = "-r" ]; then
+ echo "*** remove EAs start $2 end $3 ***"
+ _rmv_eas $2 $3
+ else
+ echo "*** create EAs start $2 end $3 ***"
+ _create_eas $2 $3
+ fi
+ echo ""
+ cd /; $UMOUNT_PROG $SCRATCH_MNT
+ _print_inode
+}
+
+_do_dirents()
+{
+ num=`expr $2 - $1 + 1`
+ echo ""
+ echo "*** create $num dirents ***"
+ echo ""
+ _scratch_mount
+ _create_dirents $1 $2
+ cd /; $UMOUNT_PROG $SCRATCH_MNT
+ _print_inode
+}
+
+_changeto_attr1()
+{
+ echo ""
+ echo "Try setting attr1 by db"
+ echo ""
+ $XFS_DB_PROG -x -c "version attr1" $SCRATCH_DEV | _filter_version
+}
+
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs xfs
+_supported_os Linux
+_require_scratch
+rm -f $seq.full
+
+_scratch_mkfs -i attr=2,size=512 >/dev/null 2>&1
+
+# set inum to root dir ino
+# we'll add in dirents and EAs into the root directory
+eval `$XFS_DB_PROG -r -c 'sb 0' -c 'p rootino' $SCRATCH_DEV | $SED_PROG 's/ //g'`
+inum=$rootino
+fork_dir=$SCRATCH_MNT
+_print_inode
+
+# add enough dirents to be inline but more
+# than will fit for m_attroffset for 512b inodes
+# for attr2 this is not a problem
+_do_dirents 1 25
+
+# add 1 ea so we get our forkoff happening
+_do_eas -c 1 1
+
+# now change back to attr1 where forkoff is constant now
+_changeto_attr1
+
+# now add another EA
+# for a bug in xfs_add_shortform_bytesfit
+# where it resets the forkoff to m_attroffset>>3 instead of
+# leaving as di_forkoff
+# If it resets to m_attroffset which is in the middle of
+# the dirents then they will get corrupted
+_do_eas -c 2 2
+
+# success, all done
+status=0
+exit
--- /dev/null
+QA output created by 186
+
+=================================
+ATTR2
+core.forkoff = 0
+u.sfdir2.hdr.count = 0
+u.sfdir2.hdr.i8count = 0
+=================================
+
+*** create 25 dirents ***
+
+
+=================================
+ATTR2
+core.forkoff = 0
+u.sfdir2.hdr.count = 25
+u.sfdir2.hdr.i8count = 0
+u.sfdir2.list[0].namelen = 6
+u.sfdir2.list[0].offset = 0x30
+u.sfdir2.list[0].name = "file.1"
+u.sfdir2.list[1].namelen = 6
+u.sfdir2.list[1].offset = 0x48
+u.sfdir2.list[1].name = "file.2"
+u.sfdir2.list[2].namelen = 6
+u.sfdir2.list[2].offset = 0x60
+u.sfdir2.list[2].name = "file.3"
+u.sfdir2.list[3].namelen = 6
+u.sfdir2.list[3].offset = 0x78
+u.sfdir2.list[3].name = "file.4"
+u.sfdir2.list[4].namelen = 6
+u.sfdir2.list[4].offset = 0x90
+u.sfdir2.list[4].name = "file.5"
+u.sfdir2.list[5].namelen = 6
+u.sfdir2.list[5].offset = 0xa8
+u.sfdir2.list[5].name = "file.6"
+u.sfdir2.list[6].namelen = 6
+u.sfdir2.list[6].offset = 0xc0
+u.sfdir2.list[6].name = "file.7"
+u.sfdir2.list[7].namelen = 6
+u.sfdir2.list[7].offset = 0xd8
+u.sfdir2.list[7].name = "file.8"
+u.sfdir2.list[8].namelen = 6
+u.sfdir2.list[8].offset = 0xf0
+u.sfdir2.list[8].name = "file.9"
+u.sfdir2.list[9].namelen = 7
+u.sfdir2.list[9].offset = 0x108
+u.sfdir2.list[9].name = "file.10"
+u.sfdir2.list[10].namelen = 7
+u.sfdir2.list[10].offset = 0x120
+u.sfdir2.list[10].name = "file.11"
+u.sfdir2.list[11].namelen = 7
+u.sfdir2.list[11].offset = 0x138
+u.sfdir2.list[11].name = "file.12"
+u.sfdir2.list[12].namelen = 7
+u.sfdir2.list[12].offset = 0x150
+u.sfdir2.list[12].name = "file.13"
+u.sfdir2.list[13].namelen = 7
+u.sfdir2.list[13].offset = 0x168
+u.sfdir2.list[13].name = "file.14"
+u.sfdir2.list[14].namelen = 7
+u.sfdir2.list[14].offset = 0x180
+u.sfdir2.list[14].name = "file.15"
+u.sfdir2.list[15].namelen = 7
+u.sfdir2.list[15].offset = 0x198
+u.sfdir2.list[15].name = "file.16"
+u.sfdir2.list[16].namelen = 7
+u.sfdir2.list[16].offset = 0x1b0
+u.sfdir2.list[16].name = "file.17"
+u.sfdir2.list[17].namelen = 7
+u.sfdir2.list[17].offset = 0x1c8
+u.sfdir2.list[17].name = "file.18"
+u.sfdir2.list[18].namelen = 7
+u.sfdir2.list[18].offset = 0x1e0
+u.sfdir2.list[18].name = "file.19"
+u.sfdir2.list[19].namelen = 7
+u.sfdir2.list[19].offset = 0x1f8
+u.sfdir2.list[19].name = "file.20"
+u.sfdir2.list[20].namelen = 7
+u.sfdir2.list[20].offset = 0x210
+u.sfdir2.list[20].name = "file.21"
+u.sfdir2.list[21].namelen = 7
+u.sfdir2.list[21].offset = 0x228
+u.sfdir2.list[21].name = "file.22"
+u.sfdir2.list[22].namelen = 7
+u.sfdir2.list[22].offset = 0x240
+u.sfdir2.list[22].name = "file.23"
+u.sfdir2.list[23].namelen = 7
+u.sfdir2.list[23].offset = 0x258
+u.sfdir2.list[23].name = "file.24"
+u.sfdir2.list[24].namelen = 7
+u.sfdir2.list[24].offset = 0x270
+u.sfdir2.list[24].name = "file.25"
+=================================
+
+*** create EAs start 1 end 1 ***
+
+
+=================================
+ATTR
+ATTR2
+core.forkoff = 47
+u.sfdir2.hdr.count = 25
+u.sfdir2.hdr.i8count = 0
+u.sfdir2.list[0].namelen = 6
+u.sfdir2.list[0].offset = 0x30
+u.sfdir2.list[0].name = "file.1"
+u.sfdir2.list[1].namelen = 6
+u.sfdir2.list[1].offset = 0x48
+u.sfdir2.list[1].name = "file.2"
+u.sfdir2.list[2].namelen = 6
+u.sfdir2.list[2].offset = 0x60
+u.sfdir2.list[2].name = "file.3"
+u.sfdir2.list[3].namelen = 6
+u.sfdir2.list[3].offset = 0x78
+u.sfdir2.list[3].name = "file.4"
+u.sfdir2.list[4].namelen = 6
+u.sfdir2.list[4].offset = 0x90
+u.sfdir2.list[4].name = "file.5"
+u.sfdir2.list[5].namelen = 6
+u.sfdir2.list[5].offset = 0xa8
+u.sfdir2.list[5].name = "file.6"
+u.sfdir2.list[6].namelen = 6
+u.sfdir2.list[6].offset = 0xc0
+u.sfdir2.list[6].name = "file.7"
+u.sfdir2.list[7].namelen = 6
+u.sfdir2.list[7].offset = 0xd8
+u.sfdir2.list[7].name = "file.8"
+u.sfdir2.list[8].namelen = 6
+u.sfdir2.list[8].offset = 0xf0
+u.sfdir2.list[8].name = "file.9"
+u.sfdir2.list[9].namelen = 7
+u.sfdir2.list[9].offset = 0x108
+u.sfdir2.list[9].name = "file.10"
+u.sfdir2.list[10].namelen = 7
+u.sfdir2.list[10].offset = 0x120
+u.sfdir2.list[10].name = "file.11"
+u.sfdir2.list[11].namelen = 7
+u.sfdir2.list[11].offset = 0x138
+u.sfdir2.list[11].name = "file.12"
+u.sfdir2.list[12].namelen = 7
+u.sfdir2.list[12].offset = 0x150
+u.sfdir2.list[12].name = "file.13"
+u.sfdir2.list[13].namelen = 7
+u.sfdir2.list[13].offset = 0x168
+u.sfdir2.list[13].name = "file.14"
+u.sfdir2.list[14].namelen = 7
+u.sfdir2.list[14].offset = 0x180
+u.sfdir2.list[14].name = "file.15"
+u.sfdir2.list[15].namelen = 7
+u.sfdir2.list[15].offset = 0x198
+u.sfdir2.list[15].name = "file.16"
+u.sfdir2.list[16].namelen = 7
+u.sfdir2.list[16].offset = 0x1b0
+u.sfdir2.list[16].name = "file.17"
+u.sfdir2.list[17].namelen = 7
+u.sfdir2.list[17].offset = 0x1c8
+u.sfdir2.list[17].name = "file.18"
+u.sfdir2.list[18].namelen = 7
+u.sfdir2.list[18].offset = 0x1e0
+u.sfdir2.list[18].name = "file.19"
+u.sfdir2.list[19].namelen = 7
+u.sfdir2.list[19].offset = 0x1f8
+u.sfdir2.list[19].name = "file.20"
+u.sfdir2.list[20].namelen = 7
+u.sfdir2.list[20].offset = 0x210
+u.sfdir2.list[20].name = "file.21"
+u.sfdir2.list[21].namelen = 7
+u.sfdir2.list[21].offset = 0x228
+u.sfdir2.list[21].name = "file.22"
+u.sfdir2.list[22].namelen = 7
+u.sfdir2.list[22].offset = 0x240
+u.sfdir2.list[22].name = "file.23"
+u.sfdir2.list[23].namelen = 7
+u.sfdir2.list[23].offset = 0x258
+u.sfdir2.list[23].name = "file.24"
+u.sfdir2.list[24].namelen = 7
+u.sfdir2.list[24].offset = 0x270
+u.sfdir2.list[24].name = "file.25"
+a.sfattr.hdr.totsize = 10
+a.sfattr.hdr.count = 1
+a.sfattr.list[0].namelen = 1
+a.sfattr.list[0].valuelen = 2
+a.sfattr.list[0].root = 0
+a.sfattr.list[0].secure = 0
+a.sfattr.list[0].name = "1"
+a.sfattr.list[0].value = "\272\276"
+=================================
+
+Try setting attr1 by db
+
+ATTR
+
+*** create EAs start 2 end 2 ***
+
+
+=================================
+ATTR
+core.forkoff = 47
+u.sfdir2.hdr.count = 25
+u.sfdir2.hdr.i8count = 0
+u.sfdir2.list[0].namelen = 6
+u.sfdir2.list[0].offset = 0x30
+u.sfdir2.list[0].name = "file.1"
+u.sfdir2.list[1].namelen = 6
+u.sfdir2.list[1].offset = 0x48
+u.sfdir2.list[1].name = "file.2"
+u.sfdir2.list[2].namelen = 6
+u.sfdir2.list[2].offset = 0x60
+u.sfdir2.list[2].name = "file.3"
+u.sfdir2.list[3].namelen = 6
+u.sfdir2.list[3].offset = 0x78
+u.sfdir2.list[3].name = "file.4"
+u.sfdir2.list[4].namelen = 6
+u.sfdir2.list[4].offset = 0x90
+u.sfdir2.list[4].name = "file.5"
+u.sfdir2.list[5].namelen = 6
+u.sfdir2.list[5].offset = 0xa8
+u.sfdir2.list[5].name = "file.6"
+u.sfdir2.list[6].namelen = 6
+u.sfdir2.list[6].offset = 0xc0
+u.sfdir2.list[6].name = "file.7"
+u.sfdir2.list[7].namelen = 6
+u.sfdir2.list[7].offset = 0xd8
+u.sfdir2.list[7].name = "file.8"
+u.sfdir2.list[8].namelen = 6
+u.sfdir2.list[8].offset = 0xf0
+u.sfdir2.list[8].name = "file.9"
+u.sfdir2.list[9].namelen = 7
+u.sfdir2.list[9].offset = 0x108
+u.sfdir2.list[9].name = "file.10"
+u.sfdir2.list[10].namelen = 7
+u.sfdir2.list[10].offset = 0x120
+u.sfdir2.list[10].name = "file.11"
+u.sfdir2.list[11].namelen = 7
+u.sfdir2.list[11].offset = 0x138
+u.sfdir2.list[11].name = "file.12"
+u.sfdir2.list[12].namelen = 7
+u.sfdir2.list[12].offset = 0x150
+u.sfdir2.list[12].name = "file.13"
+u.sfdir2.list[13].namelen = 7
+u.sfdir2.list[13].offset = 0x168
+u.sfdir2.list[13].name = "file.14"
+u.sfdir2.list[14].namelen = 7
+u.sfdir2.list[14].offset = 0x180
+u.sfdir2.list[14].name = "file.15"
+u.sfdir2.list[15].namelen = 7
+u.sfdir2.list[15].offset = 0x198
+u.sfdir2.list[15].name = "file.16"
+u.sfdir2.list[16].namelen = 7
+u.sfdir2.list[16].offset = 0x1b0
+u.sfdir2.list[16].name = "file.17"
+u.sfdir2.list[17].namelen = 7
+u.sfdir2.list[17].offset = 0x1c8
+u.sfdir2.list[17].name = "file.18"
+u.sfdir2.list[18].namelen = 7
+u.sfdir2.list[18].offset = 0x1e0
+u.sfdir2.list[18].name = "file.19"
+u.sfdir2.list[19].namelen = 7
+u.sfdir2.list[19].offset = 0x1f8
+u.sfdir2.list[19].name = "file.20"
+u.sfdir2.list[20].namelen = 7
+u.sfdir2.list[20].offset = 0x210
+u.sfdir2.list[20].name = "file.21"
+u.sfdir2.list[21].namelen = 7
+u.sfdir2.list[21].offset = 0x228
+u.sfdir2.list[21].name = "file.22"
+u.sfdir2.list[22].namelen = 7
+u.sfdir2.list[22].offset = 0x240
+u.sfdir2.list[22].name = "file.23"
+u.sfdir2.list[23].namelen = 7
+u.sfdir2.list[23].offset = 0x258
+u.sfdir2.list[23].name = "file.24"
+u.sfdir2.list[24].namelen = 7
+u.sfdir2.list[24].offset = 0x270
+u.sfdir2.list[24].name = "file.25"
+a.sfattr.hdr.totsize = 16
+a.sfattr.hdr.count = 2
+a.sfattr.list[0].namelen = 1
+a.sfattr.list[0].valuelen = 2
+a.sfattr.list[0].root = 0
+a.sfattr.list[0].secure = 0
+a.sfattr.list[0].name = "1"
+a.sfattr.list[0].value = "\272\276"
+a.sfattr.list[1].namelen = 1
+a.sfattr.list[1].valuelen = 2
+a.sfattr.list[1].root = 0
+a.sfattr.list[1].secure = 0
+a.sfattr.list[1].name = "2"
+a.sfattr.list[1].value = "\272\276"
+=================================