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, 2016 by Delphix. All rights reserved. 29# 30 31. $STF_SUITE/include/libtest.shlib 32. $STF_SUITE/tests/functional/xattr/xattr.cfg 33 34# a function that takes a file, then creates and verifies 35# an xattr on that file. The xattr_contents is the file 36# that should appear in the xattr namespace. 37function create_xattr { # filename xattr_name xattr_contents 38 typeset FILE=$1 39 typeset XATTR_NAME=$2 40 typeset XATTR_CONTENTS=$3 41 42 if is_illumos; then 43 # read any empty xattr on that file 44 log_must runat $FILE ls 45 # create the xattr 46 log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME 47 else 48 log_mustnot get_xattr $XATTR_NAME $FILE 49 log_must set_xattr_stdin $XATTR_NAME $FILE < $XATTR_CONTENTS 50 fi 51 52 verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS 53} 54 55# a function that compares the a single xattr between two files 56# and checks to see if their contents are identical 57function compare_xattrs { # filename1 filename2 xattr_name 58 typeset FILE1=$1 59 typeset FILE2=$2 60 typeset XATTR_NAME=$3 61 62 if is_illumos; then 63 runat $FILE1 cat $XATTR_NAME > $TEST_BASE_DIR/file1.$$ 64 runat $FILE2 cat $XATTR_NAME > $TEST_BASE_DIR/file2.$$ 65 else 66 get_xattr $XATTR_NAME $FILE1 > $TEST_BASE_DIR/file1.$$ 67 get_xattr $XATTR_NAME $FILE2 > $TEST_BASE_DIR/file2.$$ 68 fi 69 70 log_must diff $TEST_BASE_DIR/file1.$$ $TEST_BASE_DIR/file2.$$ 71 log_must rm $TEST_BASE_DIR/file1.$$ $TEST_BASE_DIR/file2.$$ 72} 73 74function verify_xattr { # filename xattr_name xattr_contents 75 typeset FILE=$1 76 typeset XATTR_NAME=$2 77 typeset XATTR_CONTENTS=$3 78 79 # read the xattr, writing it to a temp file 80 if is_illumos; then 81 log_must eval \ 82 "runat $FILE cat $XATTR_NAME > $TEST_BASE_DIR/$XATTR_NAME.$$ 2>&1" 83 else 84 log_must eval \ 85 "get_xattr $XATTR_NAME $FILE > $TEST_BASE_DIR/$XATTR_NAME.$$" 86 fi 87 88 log_must diff $XATTR_CONTENTS $TEST_BASE_DIR/$XATTR_NAME.$$ 89 rm $TEST_BASE_DIR/$XATTR_NAME.$$ 90} 91 92function delete_xattr { # filename xattr_name 93 typeset FILE=$1 94 typeset XATTR_NAME=$2 95 96 # delete the xattr 97 if is_illumos; then 98 log_must runat $FILE rm $XATTR_NAME 99 log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1" 100 else 101 log_must rm_xattr $XATTR_NAME $FILE 102 log_mustnot get_xattr $XATTR_NAME $FILE 103 fi 104} 105 106# not sure about this : really this should be testing write/append 107function verify_write_xattr { # filename xattr_name 108 typeset FILE=$1 109 typeset XATTR_NAME=$2 110 111 if is_illumos; then 112 log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME" 113 log_must eval \ 114 "runat $FILE cat $XATTR_NAME > $TEST_BASE_DIR/$XATTR_NAME.$$ 2>&1" 115 else 116 log_must set_xattr_stdin $XATTR_NAME $FILE < /etc/passwd 117 log_must eval \ 118 "get_xattr $XATTR_NAME $FILE > $TEST_BASE_DIR/$XATTR_NAME.$$" 119 fi 120 log_must dd if=/etc/passwd of=$TEST_BASE_DIR/passwd_dd.$$ 121 log_must diff $TEST_BASE_DIR/passwd_dd.$$ $TEST_BASE_DIR/$XATTR_NAME.$$ 122 log_must rm $TEST_BASE_DIR/passwd_dd.$$ $TEST_BASE_DIR/$XATTR_NAME.$$ 123} 124 125# this function is to create the expected output 126function create_expected_output { # expected_output_file contents_of_the_output 127 typeset FILE=$1 128 shift 129 log_must rm -f $FILE 130 log_must eval "printf '%s\n' $* >> $FILE" 131} 132