1# vim: filetype=sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/include/libtest.kshlib
28
29# a function that takes a file, then creates and verifies
30# an xattr on that file. The xattr_contents is the file
31# that should appear in the xattr namespace.
32function create_xattr { # filename xattr_name xattr_contents
33	typeset FILE=$1
34	typeset XATTR_NAME=$2
35	typeset XATTR_CONTENTS=$3
36
37	# read any empty xattr on that file
38	log_must $RUNAT $FILE $LS
39	# create the xattr
40	log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME
41
42	verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
43}
44
45# a function that compares the a single xattr between two files
46# and checks to see if their contents are identical
47function compare_xattrs { # filename1 filename2 xattr_name
48	typeset FILE1=$1
49	typeset FILE2=$2
50	typeset XATTR_NAME=$3
51
52	$RUNAT $FILE1 $CAT $XATTR_NAME > $TMPDIR/file1.${TESTCASE_ID}
53	$RUNAT $FILE2 $CAT $XATTR_NAME > $TMPDIR/file2.${TESTCASE_ID}
54
55	log_must $DIFF $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID}
56	log_must $RM $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID}
57}
58
59function verify_xattr { # filename xattr_name xattr_contents
60	typeset FILE=$1
61	typeset XATTR_NAME=$2
62	typeset XATTR_CONTENTS=$3
63
64	# read the xattr, writing it to a temp file
65	log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1"
66	log_must $DIFF $XATTR_CONTENTS $TMPDIR/$XATTR_NAME.${TESTCASE_ID}
67	$RM $TMPDIR/$XATTR_NAME.${TESTCASE_ID}
68}
69
70function delete_xattr { # filename xattr_name
71        typeset FILE=$1
72        typeset XATTR_NAME=$2
73
74        # delete the xattr
75        log_must $RUNAT $FILE $RM $XATTR_NAME
76        log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1"
77}
78
79# not sure about this : really this should be testing write/append
80function verify_write_xattr { # filename xattr_name
81        typeset FILE=$1
82        typeset XATTR_NAME=$2
83
84        log_must eval "$RUNAT $FILE $DD if=/etc/passwd of=$XATTR_NAME"
85        log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1"
86        log_must $DD if=/etc/passwd of=$TMPDIR/passwd_dd.${TESTCASE_ID}
87        log_must $DIFF $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID}
88        log_must $RM $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID}
89}
90
91# this function is to create the expected output
92function create_expected_output  { # expected_output_file  contents_of_the_output
93   typeset FILE=$1
94   shift
95   if [[ -f $FILE ]]; then
96      log_must $RM $FILE
97   fi
98
99   for line in $@
100   do
101      log_must eval "$ECHO $line >> $FILE"
102   done
103 }
104