#!/bin/csh -f
#
# This script locates all mounted disks "c" partitions
# and prints their names to stdout
#
# If the diskconfig.stresstest file exists and is readable,
# the list of disks is read from the file instead of determined
# automatically.
#
set path = ( /usr/etc /usr/bin /usr/ucb /usr/diag/sysdiag ) 

if (-e diskconfig.stresstest && -r diskconfig.stresstest) then
    #
    # disconfig.stresstest file must be formatted as follows:
    # /dev/sd0 /dev/sd1 /dev/sd3 ... etc
    #
    set DISKc = `cat diskconfig.stresstest`
else
	set DISKc = `mount | awk -f /usr/diag/sysdiag/stress.awk`
endif

set STRING
foreach i ($DISKc)
    #
    # only perform test on "c" partition of specified disks
    #
    if (!(-e ${i}c)) then #{
		echo2 "*ERROR(`hostname`): ${i}c does not exist (no entry in /dev directory)"
		exit(1)
    else if (!(-r ${i}c)) then
		echo2 "*ERROR(`hostname`): Cannot read ${i}c in /dev directory (permission denied)"
		exit(1)
    #
    # vdev probes the disk to verify that it is online
    #
    else if (`vdev -r ${i}c` == "") then
		echo2 "*ERROR(`hostname`): ${i} does not respond (is disk installed?)"
		exit(1)
    else
		# 
		# get the disk size
		#
		set m_tmp =  `echo $i | awk '{print (substr($0,7,length($0)))}'`
		set tmp_size = `dkinfo $m_tmp |& grep c: | grep -v grep | awk '{print $2 * 512}'`

		#
		# if the size is greater than 2G-slop, truncate to 2G-slop
		#
		set max = 2147360768
		set size = `echo $tmp_size $max | awk '{ if ($1 > $2) {print $2} else {print $1}}'`

		#
		# if size is valid, then echo this device name
		#
		if ($size > 0) then 
			set STRING = ($STRING $size${i}c)
		else if ($size == "") then
			echo2 "*ERROR(`hostname`): Cannot obtain size for ${i}c"
			exit(1)
		else
			echo2 "*ERROR(`hostname`): Invalid disk size ($size)"
			exit(1)
		endif
	endif
end
echo "$STRING"
exit(0)
