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 2010 Sun Microsystems, Inc.  All rights reserved.
  24 #
  25 
  26 #
  27 # NAME
  28 #       smbmount_init
  29 #
  30 # DESCRIPTION
  31 #       Create mount point for smbfs
  32 #
  33 # RETURN
  34 #       0 - create successfully
  35 #       1 - create failed
  36 #
  37 smbmount_init() {
  38         rm -rf $1
  39         cti_execute_cmd "mkdir $1"
  40         if [[ $? != 0 ]]; then
  41                 cti_unresolved "UNRESOLVED: mkdir $1 failed"
  42                 exit 1
  43         else
  44                 cti_report "PASS: mkdir $1 successfully"
  45         fi
  46         return 0
  47 }
  48 
  49 #
  50 # NAME
  51 #       testdir_init
  52 #
  53 # DESCRIPTION
  54 #       Create the test directory for smbfs testing
  55 #
  56 # RETURN
  57 #       0 - create successfully
  58 #       1 - create failed
  59 #
  60 testdir_init() {
  61         rm -rf $1
  62         cti_execute_cmd "mkdir $1"
  63         if [[ $? != 0 ]]; then
  64                 cti_unresolved "UNRESOLVED: mkdir $1 failed"
  65                 exit 1
  66         else
  67                 cti_report "PASS: mkdir $1 successfully"
  68         fi
  69         return 0
  70 }
  71 
  72 #
  73 # NAME
  74 #       smbmount_getmntopts
  75 #
  76 # DESCRIPTION
  77 #       Get the mount options string for the passed mount point,
  78 #       (i.e. remote/read/write/setuid/devices/intr/xattr/dev=...)
  79 #       which is copied to stdout for use by the caller.
  80 #
  81 # RETURN
  82 #       0 - the mount is found, and is an smbfs mount
  83 #       1 - any problem (no stdout in error cases)
  84 #
  85 smbmount_getmntopts() {
  86         typeset res on mp tp mtype opts rest
  87         /usr/sbin/mount -v |
  88         while read res on mp tp mtype opts rest
  89         do
  90                 if [[ "$mp" == "$1" ]] ; then
  91                         if [[ $mtype != smbfs ]] ; then
  92                                 echo "$1: not an smbfs mount" >&2
  93                                 return 1
  94                         fi
  95                         echo "$opts"
  96                         return 0
  97                 fi
  98         done
  99         echo "$1: no such mount point" >&2
 100         return 1
 101 }
 102 
 103 #
 104 # NAME
 105 #       smbmount_check
 106 #
 107 # DESCRIPTION
 108 #       verify the passed dir is an smbfs mount
 109 #
 110 # RETURN
 111 #       0 - it is an smbfs mount (successful)
 112 #       1 - it is not... (fail)
 113 #
 114 smbmount_check() {
 115         cti_execute FAIL smbmount_getmntopts "$1"
 116         return $?
 117 }
 118 
 119 #
 120 # NAME
 121 #       smbmount_clean
 122 #
 123 # DESCRIPTION
 124 #       umount the smbfs and cleanup the mount point
 125 #
 126 # RETURN
 127 #       0 - umount and cleanup  successfully
 128 #       1 - umount or cleanup failed
 129 #
 130 smbmount_clean() {
 131 
 132         # is it mounted?
 133         smbmount_getmntopts "$1" >/dev/null 2>&1
 134         if [[ $? == 0 ]]; then
 135                 cti_execute_cmd sudo -n "umount -f $1"
 136                 if [[ $? != 0 ]]; then
 137                         cti_report "umount -f $1 failed"
 138                         exit 1
 139                 fi
 140         fi
 141 
 142         rm -rf $1
 143         if [[ $? != 0 ]]; then
 144                 cti_report "rm -rf $1 failed"
 145                 exit 1
 146         fi
 147         return 0
 148 }