#!/bin/sh
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)scmountdev	1.6	05/03/07 SMI"

#
# script to mount /global/.devices/node@? locally
# so drvconfig and devfsadm can be run to configure global devices.
#

# Check if SMF is present
INCLUDE_FILE="/lib/svc/share/smf_include.sh"

if [ -f $INCLUDE_FILE ]
then
	. /lib/svc/share/smf_include.sh
	. /lib/svc/share/fs_include.sh
fi

# We need to enable vxvm volumes before trying to mount /global/.devices
# if the root disk has been encapsulated.

sedp=/usr/bin/sed

#
# If no vxrecover utility, infer VxVM package is not installed on this node.
#
if [ -x /usr/sbin/vxrecover ]
then
	/usr/sbin/vxrecover -n -s
fi

exec < $vfstab; readvfstab /global/.devices/node@`/usr/sbin/clinfo -n`

if [ "$mountp" ]; then
	# convert did device names to native solaris names
	if [ `echo $special | grep -c did` -gt 0 ] ; then

		diddev=`echo $special | $sedp 's/.*d/d/
		s/s.*//'`
		# May have two or more physical paths to the /global/.devices
		# filesytem on some machines such as V880s. Used head -1 to 
		# select only one.
		devspecial=`/usr/cluster/bin/scdidadm -l -o path $diddev| $sedp 's/ *$//'|head -1`
		slice=`echo $special|$sedp -e 's,..*\(..\)$,\1,'`
		fsckdev=$devspecial$slice
		special=`echo $fsckdev | $sedp s/rdsk/dsk/`
	fi

	checkfs ${fsckdev} ${fstype} ${mountp}
	if [ "x$mntopts" != x- ]; then
		# Strip out "global" option
		opts=`echo $mntopts | $sedp -e 's/^[	 ][	 ]*//' \
			-e 's/^global$//' -e 's/^global,//' \
			-e 's/,global//g'`
		#
		# 4274632: mount option warning for /global/.devices
		#
		/sbin/mount -m -o "$opts" $special $mountp
	else
		/sbin/mount -m $special $mountp
	fi
	mntlist="${mntlist}${special} ${mountp}\n"
fi
