1 # 2 # CDDL HEADER START 3 # 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. 7 # 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. 12 # 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] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 27 # 28 # Copyright (c) 2013 by Delphix. All rights reserved. 29 # 30 31 . $STF_SUITE/include/libtest.shlib 32 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 37 typeset FILE=$1 38 typeset XATTR_NAME=$2 39 typeset XATTR_CONTENTS=$3 40 41 # read any empty xattr on that file 42 log_must $RUNAT $FILE $LS 43 # create the xattr 44 log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME 45 46 verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS 47 } 48 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 52 typeset FILE1=$1 53 typeset FILE2=$2 54 typeset XATTR_NAME=$3 55 56 $RUNAT $FILE1 $CAT $XATTR_NAME > /tmp/file1.$$ 57 $RUNAT $FILE2 $CAT $XATTR_NAME > /tmp/file2.$$ 58 59 log_must $DIFF /tmp/file1.$$ /tmp/file2.$$ 60 log_must $RM /tmp/file1.$$ /tmp/file2.$$ 61 } 62 63 function verify_xattr { # filename xattr_name xattr_contents 64 typeset FILE=$1 65 typeset XATTR_NAME=$2 66 typeset XATTR_CONTENTS=$3 67 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.$$ 72 } 73 74 function delete_xattr { # filename xattr_name 75 typeset FILE=$1 76 typeset XATTR_NAME=$2 77 78 # delete the xattr 79 log_must $RUNAT $FILE $RM $XATTR_NAME 80 log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1" 81 } 82 83 # not sure about this : really this should be testing write/append 84 function verify_write_xattr { # filename xattr_name 85 typeset FILE=$1 86 typeset XATTR_NAME=$2 87 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.$$ 93 } 94 95 # this function is to create the expected output 96 function create_expected_output { # expected_output_file contents_of_the_output 97 typeset FILE=$1 98 shift 99 if [[ -f $FILE ]]; then 100 log_must $RM $FILE 101 fi 102 103 for line in $@ 104 do 105 log_must eval "$ECHO $line >> $FILE" 106 done 107 }