4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
33 # a function that takes a file, then creates and verifies
34 # an xattr on that file. The xattr_contents is the file
35 # that should appear in the xattr namespace.
36 function create_xattr { # filename xattr_name xattr_contents
39 typeset XATTR_CONTENTS=$3
41 # read any empty xattr on that file
42 log_must runat $FILE ls
44 log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME
46 verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS
49 # a function that compares the a single xattr between two files
50 # and checks to see if their contents are identical
51 function compare_xattrs { # filename1 filename2 xattr_name
56 runat $FILE1 cat $XATTR_NAME > /tmp/file1.$$
57 runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$
59 log_must diff /tmp/file1.$$ /tmp/file2.$$
60 log_must rm /tmp/file1.$$ /tmp/file2.$$
63 function verify_xattr { # filename xattr_name xattr_contents
66 typeset XATTR_CONTENTS=$3
68 # read the xattr, writing it to a temp file
69 log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
70 log_must diff $XATTR_CONTENTS /tmp/$XATTR_NAME.$$
71 rm /tmp/$XATTR_NAME.$$
74 function delete_xattr { # filename xattr_name
79 log_must runat $FILE rm $XATTR_NAME
80 log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1"
83 # not sure about this : really this should be testing write/append
84 function verify_write_xattr { # filename xattr_name
88 log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME"
89 log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1"
90 log_must dd if=/etc/passwd of=/tmp/passwd_dd.$$
91 log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
92 log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$
95 # this function is to create the expected output
96 function create_expected_output { # expected_output_file contents_of_the_output
99 if [[ -f $FILE ]]; then
105 log_must eval "echo $line >> $FILE"