#!/bin/sh 


tmp_file_name=/tmp/GetLocalDiskList.$$
tmp_list_file=/tmp/GetLocalDiskList.lst.$$
disk_list_file=/tmp/GetLocalDiskList.out.$$
vxvm_encs=/tmp/GetLocalDiskList.encs.$$
tmp_vxlist_file=/tmp/GetLocalDiskList.vxlist.tmp.$$
tmp_vxdisks_file=/tmp/GetLocalDiskList.vxdisks.tmp.$$

sid=$SRMAGT_SCAN_ID
if [ "$sid" = "" ]
then
        sid="no_sid"
fi

# Set the names for the session specific temp filenames 
vx_encl_file="/tmp/GetVxvmEnclosures.vxvmdisks.$sid"
#vxvm_dmp_map="/tmp/GetLocalDiskList.dmp_map.$sid"


VERITAS_VXVM_PKG_NAME=""
VERITAS_VXVM_PKG_NAME1=VRTSvxvm
VERITAS_VXVM_PKG_NAME2=SUNWvxvm
omit_file=0
dont_omit_file=0
omit_list_file=./.omitdisks
dont_omit_list_file=./.dontomitdisks
dont_vxdmp_file=./dontresolvedmp


# strips the slice number of non-enclosure named disk names.
strip_slice()
{
        tst1=`echo $1 | sed -n '/c[0-9].*t*d[0-9].*s[0-9]/p'`
        tst2=`echo $1`
        if [ "$tst1" = "" ]
        then
              disk_name=$tst2
        else
              tst1=`echo "$tst1" | sed 's/s[0-9]$//'`
              disk_name=$tst1
        fi  
}


sid=$SRMAGT_SCAN_ID
if [ "$sid" = "" ]
then
	sid="no_sid"
fi

vx_encl_file="/tmp/GetVxvmEnclosures.vxvmdisks.$sid"
non_vx_encl_file="/tmp/GetVxvmEnclosures.non.$sid"

rm -f $disk_list_file
touch $disk_list_file

#Check for omit file
if [ -f $omit_list_file ]
then
	omit_file=1
fi

#Check for dont omit file
if [ -f $dont_omit_list_file ]
then
	dont_omit_file=1
fi

#Check for DMP file
do_vxdmp=1
if [ -f $dont_vxdmp_file ]
then
	do_vxdmp=0
fi

# check for use of veritas... make sure to handle enclosure names properly...
# especially when removing slices from some disk names.
vxlist=""
if	[ $do_vxdmp -ne 0 ]
then
	./GenerateVxvmDiskNameMap.sh -vxlist > $vxvm_encs
    vxlist=`cat $vxvm_encs`
fi

# Using gidu instead of format
#format < /dev/null | grep "<" > $tmp_file_name
giduadm -l | grep -v "^#" | awk '{print $1}' > $tmp_file_name

for i in `cat $tmp_file_name`
do
	if [ $omit_file -ne 0 ]
	then
		cnt=`grep -c $i $omit_list_file`
		if [ $cnt -gt 0 ]
		then
			continue
		fi
	fi
  
#  if [ $do_vxdmp -ne 0 -a "$vxlist" != "" ]
#  then
    # Use grep to compare the local disks with the vxdisks
#    cnt=`echo $vxlist | grep -c $i`

#    if [ $cnt -eq 0 ]
#    then
      # Check for multipathing in DMP map file
#      dmp_mp=`cat $vxvm_dmp_map | grep "$i"`
#      if [ "x$dmp_mp" = "x" ]
#      then
#        echo "$i" >> $disk_list_file
#      else
        # Write the dmp-node-name-based device name
#        echo $dmp_mp | cut -d" " -f1 >> $disk_list_file
#      fi
#      continue
#  else
#      cat $vxvm_encs | grep "$i" | awk '{ print $1}' >> $disk_list_file
#      continue
#    fi
#  fi
  
	echo "$i" >> $disk_list_file

done


if	[ $dont_omit_file -ne 0 ]
then
	cat $dont_omit_list_file >> $disk_list_file
fi

sort -u $disk_list_file

# get rid of temp files
rm -f $tmp_file_name
rm -f $tmp_list_file
rm -f $disk_list_file
rm -f $vxvm_encs
#rm -f $vxvm_dmp_map
rm -f $tmp_vxdisks_file 
exit 0
