+ local cil controller_port controller_dev
+ # SCSI-FC device
+ fc_tgt_hcil="${DEV##*/}"
+ fc_tgt_lun="${fc_tgt_hcil##*:}"
+ fc_tgt_path="${DEV%/*}"
+ fc_tgt_num="${fc_tgt_path##*/}"
+ fc_tgt_dev="${fc_tgt_path}/fc_transport:${fc_tgt_num}"
+ if [ -e "$fc_tgt_dev/port_name" ]; then
+ read wwpn < $fc_tgt_dev/port_name
+ fi
+ if [ -z "$wwpn" ] ; then
+ : no WWPN
+ RESULT=1
+ return
+ fi
+ # Linux currently knows about 32bit luns
+ tmp_lun3=$(printf "%04x" $(($fc_tgt_lun & 0xFFFF)))
+ tmp_lun2=$(printf "%04x" $(( ($fc_tgt_lun >> 16) & 0xFFFF)))
+ tmp_lun1="0000"
+ tmp_lun0="0000"
+
+ if (($fc_tgt_lun == 0)) ; then
+ lun="0x0000000000000000"
+ else
+ lun="0x${tmp_lun3}${tmp_lun2}${tmp_lun1}${tmp_lun0}"
+ fi
+ controller_dev="${fc_tgt_path%/host[0-9]*}"
+
+ # FC devices are always endpoints
+ d="fc-${wwpn}:${lun}"
+ D="$controller_dev"
+ RESULT=0
+}
+
+handle_block_sas () {
+ : handle_block_sas $*
+ local DEV=$1
+ local cil adapter controller_dev
+ # SAS device
+ sas_host_path="${DEV%%/phy*}"
+ sas_phy_path="${DEV#*/host*/}"
+ sas_phy_path="${sas_phy_path%%/target*}"
+ sas_phy_id="${sas_phy_path%%/*}"
+ sas_rphy_id="${sas_phy_path##*/}"
+ sas_phy_dev="${sas_host_path}/${sas_phy_id}/sas_phy:${sas_phy_id}"
+ if [ -e "$sas_phy_dev/sas_address" ]; then
+ read phy_address < $sas_phy_dev/sas_address
+ read phy_port < $sas_phy_dev/port_identifier
+ read phy_id < $sas_phy_dev/phy_identifier
+ fi
+ if [ -z "$phy_address" ] ; then
+ : no initiator address
+ RESULT=1
+ return
+ fi
+ sas_phy_address="$phy_address:$phy_port:$phy_id"
+ sas_rphy_dev="${sas_host_path}/${sas_phy_id}/${sas_rphy_id}/sas_rphy:${sas_rphy_id}"
+ if [ -e "$sas_rphy_dev/sas_address" ]; then
+ read rphy_address < $sas_rphy_dev/sas_address
+ read rphy_id < $sas_rphy_dev/phy_identifier
+ fi
+ if [ -z "$rphy_address" ] ; then
+ : no initiator address
+ RESULT=1
+ return
+ fi
+ sas_rphy_address="$rphy_address:$rphy_id"
+
+ controller_dev="${sas_host_path%/host[0-9]*}"
+
+ # SAS devices are always endpoints
+ d="sas-${sas_phy_address}-${sas_rphy_address}"
+ D="$controller_dev"
+
+ RESULT=0
+}
+
+handle_usb () {
+: handle_usb $*
+ local DEV=$1
+ cd -P $1
+ DEV=${PWD}
+ port_id=${DEV##*/}
+ port_num=${port_id#*-}
+ host_dev_path=$DEV
+ while [ ! -z "$host_dev_path" ] ; do
+ case "$host_dev_path" in
+ */usb*)
+ usb_host_path=$host_dev_path
+ host_dev_path="${host_dev_path%/*}"