#! /usr/bin/ksh
#
# @(#)findRMMDevices.sh	1.3	98/07/03 SMI
#
# Copyright (c) 1998, by Sun Microsystems, Inc.
# All rights reserved.
#
# findRMMDevices $name $number $loc
#
# Purpose:      To read the device classes out of the FRU EEPROM and assign
#               Device instances to represent the Devices realised by the FRU.
# Result:       The FRU $consitituent_names attributes will be set and a
#               space-separated string of device instances is returned.
#		Any problems encountered when probing the FRU EEPROM cause
#		the script to exit and produce no output. The caller (i.e.
#		the cmsdef) should then perform no further configuration
#		operations.
#
# Mandatory Parameters
# $name                 - class name of FRU
# $number               - instance number of FRU
# $location             - location of FRU

if [[ $# -ne 3 ]]
then
	cmsdebug "findRMMDevices: malformed command line: $*"
	exit 1
fi

name=$1
number=$2
loc=$3

allocation_per_rmm=2

((tape_inst_start=$number*$allocation_per_rmm))
((cdrom_inst_start=$number*$allocation_per_rmm))

dev_string=""

for i in 0 1
do
    device="$(cmsfruinfo -s -l $loc EE_RMM_RMM_DEV_${i}_DEVNAME)" || exit 2

    if [[ -n "$device" ]]
    then
	case "$device" in
	"tape") ((instance=$tape_inst_start+$i)) ;;
	"cdrom")((instance=$cdrom_inst_start+$i)) ;;
	*)	 cmsreport $name $number info "$device class not supported"
		exit 2 ;;
	esac

	device="$device $instance"
	cmsreport $name $number slot$i "$device"

	scsi_id=$(cmsfruinfo -s -l $loc EE_RMM_RMM_DEV_${i}_SCSI_ID) || exit 2
	if [[ $? -ne 0 ]] then exit 2; fi
	cmsreport $device _scsi_id $scsi_id

	if [[ -z "$dev_string" ]]
	then	dev_string="$device"
	else	dev_string="$dev_string $device"
	fi
    fi
done
echo $dev_string
