MNTPT=/mnt/temp

#format test fs
touch img
mkfs.ext3 -F -b 4096 -I 512 img 50000 > /dev/null
mount -t ext3 -o loop,user_xattr img  $MNTPT
touch $MNTPT/foo

# create EAs so that extra space in inode is filled and external block is needed
for (( i = 0; i < 20; i++ )); do 
	setfattr -n user.foobar$i -v foobar $MNTPT/foo
done

umount $MNTPT
# note EA block no
old_blk=`debugfs -R "stat foo" img 2>&1 | grep "ACL" | cut -d' ' -f3`
echo "Old xattr block no: $old_blk"

mount -t ext3 -o loop,user_xattr img  $MNTPT
# replace in-inode EA such that it should "overflow" into external EA blok
setfattr -n user.foobar1 -v foobarfoobarfoobarfoobarfoobarfoobarfoobar $MNTPT/foo

getfattr -d $MNTPT/foo # shows that EAs from external block are lost
umount $MNTPT
# EA block no should not change with these operations - but it does
new_blk=`debugfs -R "stat foo" img 2>&1 | grep "ACL" | cut -d' ' -f3`

if [ $old_blk -ne $new_blk ]; then
	echo "new xattr block no: $new_blk - old xattr's except the one being replaced are lost"
fi
