#!/bin/ksh -p
# $Id: //depot/stable/explorer/tools/disks#3 $
#
# Explorer Version:
EXP_VERSION=4.0
#
# Source tools functions
. ${EXP_LIB}/exp_tools

# Run if specified to do so
script=${0##*/}
which_gate_exit storage $script default all

# Run format
get_cmd "/usr/bin/echo 0 | /usr/sbin/format 2>&1 | sed -e '/^Specify disk/,\$d'" disks/format

# Diskinfo is sparc only
if [ "${EXP_HOME}" = "/" ]
then
    DISKINFO="${EXP_LIB}/diskinfo"
else
    DISKINFO="${EXP_HOME}/bin/diskinfo.`uname -p`"
fi
if [ -f "${DISKINFO}" ]
then
    get_cmd "${DISKINFO}" disks/diskinfo!
fi

get_cmd "/usr/bin/ls -lAR /dev /devices"   disks/
get_cmd "/usr/bin/ls -l /dev/fc"    ignore disks/ls-l_dev_fc
get_cmd "/usr/bin/ls -l /dev/rdsk"         disks/ls-l_dev_rdsk
get_cmd "/usr/bin/ls -l /dev/rmt*"         disks/ls-l_dev_rmt
get_cmd "/usr/bin/ls -lL /dev/rmt/"        disks/ls-lL_dev_rmt
get_cmd "/usr/bin/ls -l /dev/rst*"  ignore disks/ls-l_dev_rst
get_cmd "/usr/bin/ls -l /dev/nrst*" ignore disks/ls-l_dev_nrst

get_file "/kernel/drv/st.conf" disks
#get_file "/kernel/drv/sd.conf" disks

get_cmd "/usr/bin/iostat -E" disks/
get_cmd "/usr/sbin/swap -l" disks/swap-l
get_cmd "/usr/sbin/swap -s" disks/swap-s

# gather major/minor numbers, which may be needed in following through
# crash dumps.
get_cmd "/usr/bin/find /dev -type d -print | xargs ls -lL" disks/dev-lL
get_cmd "/usr/bin/ls -lL /dev/*dsk/*" disks/maj_min_dev_num
get_cmd "/usr/bin/ls -ld /tmp"        disks/ls-ld_tmp
get_cmd "/usr/bin/df -kl"              disks/df-kl
get_cmd "/usr/bin/df -al"              disks/df-al
get_cmd "/usr/bin/df -el"              disks/df-el
get_cmd "/usr/bin/df -gl"              disks/df-gl

# gather disk partition information
for i in `/bin/ls /dev/rdsk/*s2`
do
    diskname=`echo $i|sed s/.dev.rdsk.//|sed s/s2//| sed s/\$/\&s/`

    # we need devinfo to find a non zero length partition, since prtvtoc
    # will return "No such device or address" on a zero length partition.
    # prtvtoc will be executed on one partition only as the info is the same
    # for all partitions.
    for k in 0 1 2 3 4 5 6 7
    do
        if test "`devinfo -p /dev/rdsk/$diskname$k 2>/dev/null`" != ""
	then
            get_cmd "/usr/sbin/prtvtoc /dev/rdsk/$diskname$k" disks/prtvtoc/$diskname$k!
            break
        fi
    done
done


# Gather filesystem information
df -lFufs | sed -e "s/(/:/" -e "s/)/:/" | nawk -F: '{print $1,$2}' | while read fs dev
do
    bdev=`echo $dev | awk -F: '{ print $1 }' | sed 's/[\(\)]//g'`
    rdev=`echo $bdev | sed 's/dsk/rdsk/'`
    FS=`echo $fs | sed 's/\//_/g'`

    get_cmd "/usr/sbin/fstyp -v $bdev" disks/ufs/fstyp_-v=${FS}
done

# Gather mounted filesystem information
get_cmd "/usr/sbin/mount"			   disks/mount

#
#  Check for the E450 hw raid controller
#
if [ -x /opt/SUNWhwrdg/dptutil ]; then
    get_file "/var/opt/SUNWhwrdg/dptelog.*"        disks/hwraid
    get_cmd "/opt/SUNWhwrdg/dptutil -L all"        disks/hwraid/dptutil-L_all
    get_cmd "/opt/SUNWhwrdg/dptutil -L controller" disks/hwraid/dptutil-L_controller
    get_cmd "/opt/SUNWhwrdg/dptutil -L logical"    disks/hwraid/dptutil-L_logical
    get_cmd "/opt/SUNWhwrdg/dptutil -L physical"   disks/hwraid/dptutil-L_physical
    get_cmd "/opt/SUNWhwrdg/dptutil -L raid"       disks/hwraid/dptutil-L_raid
    get_cmd "/opt/SUNWhwrdg/dptutil -L spare"      disks/hwraid/dptutil-L_spare
fi

#
#  Get more info on disk arrays
#
if [ -d /dev/es ]; then
    for ES in `/bin/ls /dev/es`
    do
	get_cmd "/usr/sbin/luxadm inq /dev/es/${ES}" disks/luxadm_inq_dev_es_${ES}
	sleep 1
    done
fi

get_cmd "/usr/sbin/luxadm probe"             disks/luxadm_probe
sleep 1
get_cmd "/usr/sbin/luxadm probe -p"          disks/luxadm_probe_-p
sleep 1
#  fcode_download -p may cause SOC+ reset as LIP timed out error.
#  The command is removed to prevent i/o and production errors
#get_cmd "/usr/sbin/luxadm fcode_download -p" disks/luxadm_fcode_download_-p
#sleep 1
get_cmd "/usr/sbin/luxadm qlgc_s_download"   disks/luxadm_qlgc_s_download
sleep 1 
get_cmd "/usr/sbin/luxadm -e port"	     disks/luxadm_-e_port
