#!/bin/sh
#
# Name: sysfs_scandisk.sh
# Copyright: (c)Copyright 2006 Hewlett-Packard Development Company, L.P.

# Description: Given a particular SCSI host, generate a list
#              of SCSI devices attached to that SCSI host
#
# Revision History
#
# CD	04/19/06 Initial Development
#

# argument 1 should be the instance number of the device

INSTANCE=$1

if test "$INSTANCE" = ""
then
 echo "A SCSI host instance number needs to be specified"
 exit 1
fi

SCSIHOSTDIR=/sys/class/scsi_host/host${INSTANCE}

# Do a sanity check to make sure that the directory exists

if test -d $SCSIHOSTDIR
then
 cd /sys/class/scsi_host/host${INSTANCE}/device
else
 echo "$SCSIHOSTDIR does not exist"
 exit 1
fi

# Get the list of targets for this SCSI host

TARGETS=`ls -d target* 2>/dev/null`

# If we have not targets, then just exit
if test "$TARGETS" = ""
then
 exit 0
fi

# For each target, get the list of SCSI devices, print it 
# along with the vendor and model IDs

for i in $TARGETS
do
 OLDDIR=`pwd`
 cd $i
 DEVICES=`ls | grep -v detach_state | grep -v power`
 for j in $DEVICES
 do
	echo "$j   `cat $j/vendor` `cat $j/model`"
 done
 cd $OLDDIR
done


