1#!/usr/local/bin/ksh93 -p 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# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24 25. $STF_SUITE/include/libtest.kshlib 26. $STF_SUITE/tests/xattr/xattr_common.kshlib 27 28################################################################################ 29# 30# __stc_assertion_start 31# 32# ID: xattr_011_pos 33# 34# DESCRIPTION: 35# 36# Basic applications work with xattrs: cpio cp find mv pax tar 37# 38# STRATEGY: 39# 1. For each application 40# 2. Create an xattr and archive/move/copy/find files with xattr support 41# 3. Also check that when appropriate flag is not used, the xattr 42# doesn't get copied 43# 44# TESTABILITY: explicit 45# 46# TEST_AUTOMATION_LEVEL: automated 47# 48# CODING_STATUS: COMPLETED (2006-12-15) 49# 50# __stc_assertion_end 51# 52################################################################################ 53 54function cleanup { 55 56 log_must $RM $TESTDIR/myfile.${TESTCASE_ID} 57} 58 59log_assert "Basic applications work with xattrs: cpio cp find mv pax tar" 60log_onexit cleanup 61 62test_requires RUNAT 63 64# Create a file, and set an xattr on it. This file is used in several of the 65# test scenarios below. 66log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} 67create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd 68 69 70# For the archive applications below (tar, cpio, pax) 71# we create two archives, one with xattrs, one without 72# and try various cpio options extracting the archives 73# with and without xattr support, checking for correct behaviour 74 75 76log_note "Checking cpio" 77log_must $TOUCH $TESTDIR/cpio.${TESTCASE_ID} 78create_xattr $TESTDIR/cpio.${TESTCASE_ID} passwd /etc/passwd 79$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o@ > $TMPDIR/xattr.${TESTCASE_ID}.cpio 80$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o > $TMPDIR/noxattr.${TESTCASE_ID}.cpio 81 82# we should have no xattr here 83log_must $CPIO -iu < $TMPDIR/xattr.${TESTCASE_ID}.cpio 84log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 85 86# we should have an xattr here 87log_must $CPIO -iu@ < $TMPDIR/xattr.${TESTCASE_ID}.cpio 88log_must eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 89 90# we should have no xattr here 91log_must $CPIO -iu < $TMPDIR/noxattr.${TESTCASE_ID}.cpio 92log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 93 94# we should have no xattr here 95log_must $CPIO -iu@ < $TMPDIR/noxattr.${TESTCASE_ID}.cpio 96log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 97log_must $RM $TESTDIR/cpio.${TESTCASE_ID} $TMPDIR/xattr.${TESTCASE_ID}.cpio $TMPDIR/noxattr.${TESTCASE_ID}.cpio 98 99 100 101log_note "Checking cp" 102# check that with the right flag, the xattr is preserved 103log_must $CP -@ $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} 104compare_xattrs $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} passwd 105log_must $RM $TESTDIR/myfile2.${TESTCASE_ID} 106 107# without the right flag, there should be no xattr 108log_must $CP $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} 109log_mustnot eval "$RUNAT $TESTDIR/myfile2.${TESTCASE_ID} $LS passwd > /dev/null 2>&1" 110log_must $RM $TESTDIR/myfile2.${TESTCASE_ID} 111 112 113 114log_note "Checking find" 115# create a file without xattrs, and check that find -xattr only finds 116# our test file that has an xattr. 117log_must $MKDIR $TESTDIR/noxattrs 118log_must $TOUCH $TESTDIR/noxattrs/no-xattr 119 120$FIND $TESTDIR -xattr | $GREP myfile.${TESTCASE_ID} 121if [ $? -ne 0 ] 122then 123 log_fail "find -xattr didn't find our file that had an xattr." 124fi 125$FIND $TESTDIR -xattr | $GREP no-xattr 126if [ $? -eq 0 ] 127then 128 log_fail "find -xattr found a file that didn't have an xattr." 129fi 130log_must $RM -rf $TESTDIR/noxattrs 131 132 133 134log_note "Checking mv" 135# mv doesn't have any flags to preserve/ommit xattrs - they're 136# always moved. 137log_must $TOUCH $TESTDIR/mvfile.${TESTCASE_ID} 138create_xattr $TESTDIR/mvfile.${TESTCASE_ID} passwd /etc/passwd 139log_must $MV $TESTDIR/mvfile.${TESTCASE_ID} $TESTDIR/mvfile2.${TESTCASE_ID} 140verify_xattr $TESTDIR/mvfile2.${TESTCASE_ID} passwd /etc/passwd 141log_must $RM $TESTDIR/mvfile2.${TESTCASE_ID} 142 143 144log_note "Checking pax" 145log_must $TOUCH $TESTDIR/pax.${TESTCASE_ID} 146create_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd 147log_must $PAX -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.${TESTCASE_ID} 148log_must $PAX -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.${TESTCASE_ID} 149log_must $RM $TESTDIR/pax.${TESTCASE_ID} 150 151# we should have no xattr here 152log_must $PAX -r -f $TESTDIR/noxattr.pax 153log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 154log_must $RM $TESTDIR/pax.${TESTCASE_ID} 155 156# we should have no xattr here 157log_must $PAX -r@ -f $TESTDIR/noxattr.pax 158log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 159log_must $RM $TESTDIR/pax.${TESTCASE_ID} 160 161 162# we should have an xattr here 163log_must $PAX -r@ -f $TESTDIR/xattr.pax 164verify_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd 165log_must $RM $TESTDIR/pax.${TESTCASE_ID} 166 167# we should have no xattr here 168log_must $PAX -r -f $TESTDIR/xattr.pax 169log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 170log_must $RM $TESTDIR/pax.${TESTCASE_ID} $TESTDIR/noxattr.pax $TESTDIR/xattr.pax 171 172 173log_note "Checking tar" 174log_must $TOUCH $TESTDIR/tar.${TESTCASE_ID} 175create_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd 176log_must $TAR cf $TESTDIR/noxattr.tar $TESTDIR/tar.${TESTCASE_ID} 177log_must $TAR c@f $TESTDIR/xattr.tar $TESTDIR/tar.${TESTCASE_ID} 178log_must $RM $TESTDIR/tar.${TESTCASE_ID} 179 180# we should have no xattr here 181log_must $TAR xf $TESTDIR/xattr.tar 182log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 183log_must $RM $TESTDIR/tar.${TESTCASE_ID} 184 185# we should have an xattr here 186log_must $TAR x@f $TESTDIR/xattr.tar 187verify_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd 188log_must $RM $TESTDIR/tar.${TESTCASE_ID} 189 190# we should have no xattr here 191log_must $TAR xf $TESTDIR/noxattr.tar 192log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 193log_must $RM $TESTDIR/tar.${TESTCASE_ID} 194 195# we should have no xattr here 196log_must $TAR x@f $TESTDIR/noxattr.tar 197log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" 198log_must $RM $TESTDIR/tar.${TESTCASE_ID} $TESTDIR/noxattr.tar $TESTDIR/xattr.tar 199