#! /bin/sh
# FS QA Test No. 098. Modified from UDFQA test 035
#
# simple attr tests for EAs:
#  - set
#  - get
#  - list
#  - remove
# Basic testing.
# + udf_db checks.
# (033 + udf_db)
#
#-----------------------------------------------------------------------
#  Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
#-----------------------------------------------------------------------
#
# creator
owner=ajones@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()
{
    rm -f $tmp.*
}

# get standard environment, filters and checks
. ./common.rc
. ./common.filter

_db_filter()
{
    awk '
	/<file_entry name=/ { fe_on=1 }
	/<timestamp/  { ts_on=1; next }
	/<\/timestamp/ { ts_on=0; next }
	/<cksum/      { next }
	/<desc_crc/   { next }
	/<pos/        { next }
	/<tag_loc/    { next }
	/<lb_num/     { next }
	fe_on == 1 && ts_on == 0 { print; next }
	              { next }
    '
}

_umount_check_mount()
{
    cd /
    umount $SCRATCH_MNT

    udf_db -f $SCRATCH_DEV | _db_filter

    _scratch_mount
    cd $SCRATCH_MNT
}

# real QA test starts here
_supported_fs udf
_supported_os IRIX

_require_scratch
_setup_testdir

cd $SCRATCH_MNT

echo "create file foo"
echo "file_contents" >foo
cat foo

echo "should be no EAs for foo:"
attr -l foo

echo "set EA <noise,woof>:"
attr -s noise -V woof foo

echo "set EA <colour,blue>:"
attr -s colour -V blue foo

echo "set EA <size,small>:"
attr -s size -V small foo

echo "list the EAs for foo: noise, colour, size" 
attr -l foo

echo "check the list again for foo"
attr -l foo

echo "unmount the FS and see if EAs are persistent"
_umount_check_mount

echo "check the list again for foo after umount/mount"
attr -l foo

echo "get the value of the noise EA"
attr -g noise foo

echo "get the value of the colour EA which was removed earlier"
attr -g colour foo

echo "get the value of the size EA"
attr -g size foo

echo "remove the colour EA on foo"
attr -r colour foo

echo "list EAs for foo: noise, size"
attr -l foo

echo "get the value of the noise EA"
attr -g noise foo

echo "get the value of the colour EA which was removed earlier"
attr -g colour foo

echo "get the value of the size EA"
attr -g size foo

echo "list all the EAs again: noise, size"
attr -l foo

echo "change the value of the size EA from small to huge"
attr -s size -V huge foo

echo "get the size EA which should now have value huge"
attr -g size foo

echo "list EAs: noise, size"
attr -l foo

echo "remove the size EA from foo"
attr -r size foo

echo "list EAs: noise (size EA has been removed)"
attr -l foo

echo "get the noise EA: woof"
attr -g noise foo

echo "try removing non-existent EA named woof"
attr -r woof foo

echo "try removing already removed EA size"
attr -r size foo

echo "list EAs: noise"
attr -l foo

echo "try removing already removed EA colour"
attr -r colour foo

echo "list EAs: noise"
attr -l foo

echo "remove remaining EA noise"
attr -r noise foo

echo "list EAs: should be no EAs left now"
attr -l foo

echo "unmount the FS and see if EAs are persistent"
_umount_check_mount

echo "list EAs: should still be no EAs left"
attr -l foo

echo ""
echo "*** Test out the root namespace ***"
echo ""

echo "set EA <root:colour,marone>:"
attr -R -s colour -V marone foo

echo "set EA <user:colour,beige>:"
attr -s colour -V beige foo

echo "set EA <user:vomit,pizza>:"
attr -s vomit -V pizza foo

echo "set EA <root:noise,whack>:"
attr -R -s noise -V whack foo

echo "list root EAs: <root:colour,noise>:"
attr -R -l foo

echo "list user EAs: <user:colour,vomit>:"
attr -l foo

echo "get root EA colour: marone"
attr -R -g colour foo

echo "get root EA noise: whack"
attr -R -g noise foo

echo "get root EA vomit which is a user EA => find nothing"
attr -R -g vomit foo

echo ""
echo "unmount the FS and see if EAs are persistent"
echo ""
_umount_check_mount

echo "get root EA colour: marone"
attr -R -g colour foo

echo "get root EA noise: whack"
attr -R -g noise foo

echo "get user EA vomit: pizza" 
attr -g vomit foo

echo "remove the root colour EA"
attr -R -r colour foo

echo "list root EAs: <root:noise>:"
attr -R -l foo

echo "list user EAs: <user:colour,vomit>:"
attr -l foo

echo "remove the final root EA noise"
attr -R -r noise foo

echo "list root EAs: none"
attr -R -l foo

cd /
umount $SCRATCH_MNT

udf_db -f $SCRATCH_DEV | _db_filter

# Checks the udf filesystem
_check_udf_filesystem $SCRATCH_DEV

_scratch_mount
cd $SCRATCH_MNT

echo "delete the file foo - which will delete the associated streams"
rm foo

cd /
umount $SCRATCH_MNT

udf_db -f $SCRATCH_DEV | _db_filter

# Checks the udf filesystem
_check_udf_filesystem $SCRATCH_DEV

# optional stuff if your test has verbose output to help resolve problems
#echo
#echo "If failure, check $seq.full (this) and $seq.full.ok (reference)"

# success, all done
status=0
exit
