1 #! /usr/bin/ksh -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 
  23 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 # NFSv4 named attributes support functions: 
  28 #
  29 
  30 [[ -n $DEBUG && $DEBUG != 0 ]] && set -x
  31 
  32 
  33 TESTSH=$TESTROOT/testsh
  34 if [ -r $TESTSH ]; then
  35         . $TESTSH
  36 else
  37         echo "$0 ERROR: Cannot read file $TESTSH. Terminating ..." >&2
  38         exit 6 /* UNINITIATED */
  39 fi
  40 
  41 
  42 function setup
  43 {
  44         # any arguments are silently ignored
  45         [[ -n $DEBUG && $DEBUG != 0 ]] && set -x
  46         NAME=`basename $0`
  47         DIR=`dirname $0`
  48         CDIR='pwd'
  49 
  50         LSAT='ls -@'
  51         LSATD='ls -@d'
  52         CPAT='cp -@'
  53         TESTFILE="foo.$$"
  54         TESTFILE2="foo2.$$"
  55         NEWFILE="newfoo.$$"
  56         TESTDIR1="dirobj1.$$"
  57         TESTDIR2="dirobj2.$$"
  58         TESTDIR3="dirobj3.$$"
  59         HLNK1="link1.$$"
  60         HLNK2="link2.$$"
  61         OLIST="TESTFILE TESTFILE2 NEWFILE HLNK1 HLNK2 TESTDIR1 TESTDIR2 \
  62                 TESTDIR3"
  63 
  64         . $TESTROOT/nfs4test.env
  65 
  66         TMPmnt=$ZONE_PATH/$NAME.$$
  67         export TMPmnt $OLIST
  68 
  69         is_root $NAME
  70 }
  71 
  72 function cleanup
  73 {
  74         [[ -n $DEBUG && $DEBUG != 0 ]] && set -x
  75         (( $# < 1 )) && echo "USAGE: cleanup return_code" && exit $OTHER
  76         typeset out=$1
  77 
  78         # clean all files created here
  79         for i in $OLIST
  80         do
  81                 typeset value=$(eval "echo \$${i}")
  82                 [ -e $TMPmnt/$value ] && rm -rf $TMPmnt/$value 2>&1 > /dev/null
  83                 [ -e $MNTPTR/$value ] && rm -rf $MNTPTR/$value 2>&1 > /dev/null
  84         done
  85 
  86         # unmount dir
  87         mount | grep "^$TMPmnt" > /dev/null 2>&1
  88         if [ $? -eq 0 ]; then
  89                 umount $TMPmnt > $TMPDIR/umount.out.$$
  90                 ret=$?
  91                 ckreturn $ret "Cannot unmount [$TMPmnt], returned $ret." \
  92                         $TMPDIR/$umount.out.$$ WARNING
  93                 if [ $? -ne 0 ]; then
  94                         umount -f $TMPmnt
  95                         ret=$?
  96                         [ $ret -ne 0 ] && \
  97                                 echo "umount -f $TMPmnt also failed ($ret)."
  98                 fi
  99         fi
 100 
 101         # clean dir
 102         mount | grep "^$TMPmnt" > /dev/null 2>&1
 103         [ $? -ne 0 ] && [ -d $TMPmnt ] && rm -rf $TMPmnt
 104 
 105         # Cleanup temp files
 106         rm -f $TMPDIR/*.out.$$ > /dev/null 2>&1
 107 
 108         [ $out -ne 0 ] && exit $out
 109 }