#!/sbin/sh -
# %W% %G% %U% - %Q%
#ident "%Z%unixvm:%M% %I%"

# Copyright (c) 2000 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
# 
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
# 
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043


: ${VOLROOT_DIR:-$__VXVM_ROOT_DIR}
: ${VOLADM_ROOT:=$VOLROOT_DIR/usr/lib/vxvm/voladm.d}
: ${VOLADM_LIB:=$VOLADM_ROOT/lib}
: ${VOL_CONFIG_DIR:=$VOLROOT_DIR/etc/vx}

RDIR=$VOL_CONFIG_DIR/reconfig.d
STATEDIR=$RDIR/state.d
SAVEDIR=$RDIR/saveconf.d
DEVDIR=$RDIR/savedev.d
NEWDIR=$SYSROOT/tmp/new.d
DISKDIR=$RDIR/disk.d
SYSROOT=$__VXVM_SYSTEM_ROOT_DIR

DIAGDIR=$VOL_CONFIG_DIR/diag.d

mkdbfile=$STATEDIR/install-db		# need database initialization

pnewfile=$STATEDIR/init-new-part	# partition new disks
pcapfile=$STATEDIR/init-cap-part	# partition encapsulated disks
pnewlist=$RDIR/disks-new-part		# list of new disks
pcaplist=$RDIR/disks-cap-part		# list of encapsulated disks
pnewerr=$RDIR/err-new-part		# new disks that failed partition
pcaperr=$RDIR/err-cap-part		# encap. disks that failed partition

newfile=$STATEDIR/init-new		# new disks to "vxdisk init..."
capfile=$STATEDIR/init-cap		# encapsulated disks to "colcap-vol"
newlist=$RDIR/disks-new			# list of new disks
caplist=$RDIR/disks-cap			# list of encapsulated disks
newerr=$RDIR/err-new			# list of failed new disks
caperr=$RDIR/err-cap			# list of failed encap. disks
rmvols=$STATEDIR/rmvols                 # rm these volumes after vxunroot
rmvmdisks=$STATEDIR/rmvmdisks           # rm these vm disks after vxunroot

rootfile=$STATEDIR/root-done		# volume has been rootified
rootsvfile=$STATEDIR/root-files		# files have been saved

relfile=$STATEDIR/reloc-needed		# relocate stand filesystem
reltmpslcfile=$STATEDIR/reloc-tmpslc	# temporary copy slice not created
relrestfile=$STATEDIR/reloc-rest	# restore from swap not done
relsavefile=$STATEDIR/reloc-save	# save to swap not done 
relvtocfile=$STATEDIR/reloc-vtoc	# temp vtoc not written

hrhistfile=$STATEDIR/hr-hist		# list of failed and destination disks
hrrecoverfile=$STATEDIR/hr-recover	# list of volumes to recover
hrresultfile=$STATEDIR/hr-result	# result of relocation

reconfigfile=$STATEDIR/reconfig

excltmpfile1=$RDIR/excltmpfile1		# used in the device exclude menu
excltmpfile2=$RDIR/excltmpfile2		# used in the device exclude menu
excltmpfile3=$RDIR/excltmpfile3
MAX_VENDORID=8				# max. allowed lengths for vendor id
MAX_PRODUCTID=16			# and product id returned by disks

rootdisk=				# root disk is not yet known

export RDIR STATEDIR SAVEDIR NEWDIR DISKDIR DIAGDIR

VOL_DEFAULTS_FILE=$SYSROOT/etc/default/vxassist
VOL_SAVECONFIG_DIR=$VOL_CONFIG_DIR/saveconfig.d

xcmd()
{
	if [ ! -z "$VOL_VERBOSE" ]; then 
		echo "!$VOL_XCMD $@" >&2
	fi
	$VOL_XCMD "$@"
	[ $? = 0 ] || bail
}

ecmd()
{
	if [ ! -z "$VOL_VERBOSE" ]; then 
		echo "!$VOL_XCMD $@" >&2
	fi
	$VOL_XCMD "$@"
}

volmkdirs()
{
	[ -d $RDIR ] || mkdir $RDIR
	[ -d $STATEDIR ] || mkdir $STATEDIR
	[ -d $SAVEDIR ] || mkdir $SAVEDIR
	[ -d $NEWDIR ] || mkdir $NEWDIR
	[ -d $DISKDIR ] || mkdir $DISKDIR
}

. $VOLADM_LIB/vxadm_lib.sh

set_OS_variables
