MAJOR=4
MINOR=20
DEVNAME=tty20
  	   ˆÃÉ0ÂÇ  :   ˆl–ßi~”JClÊqA
àq¡)‹FÿÊ„eð _a–Ü4ý()¨‰P@Š»‚fão)‹FÿÉ ?÷     #!/usr/bin/bash
# Script to rescan SCSI bus, using the scsi add-single-device mechanism.
# (c) 1998--2010 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or v3
# (c) 2006--2018 Hannes Reinecke, GNU GPL v2 or later
# $Id: rescan-scsi-bus.sh,v 1.57 2012/03/31 14:08:48 garloff Exp $

VERSION="20180615"
SCAN_WILD_CARD=4294967295

setcolor ()
{
  red="\e[0;31m"
  green="\e[0;32m"
  yellow="\e[0;33m"
  bold="\e[0;1m"
  norm="\e[0;0m"
}

unsetcolor ()
{
  red=""; green=""
  yellow=""; norm=""
}

echo_debug()
{
  if [ "$debug" -eq 1 ] ; then
     echo "$1"
  fi
}

# Output some text and return cursor to previous position
# (only works for simple strings)
# Stores length of string in LN and returns it
print_and_scroll_back ()
{
  STRG="$1"
  LN=${#STRG}
  BK=""
  declare -i cntr=0
  while [ $cntr -lt "$LN" ] ; do BK="$BK\e[D"; let cntr+=1; done
  echo -en "$STRG$BK"
  return "$LN"
}

# Overwrite a text of length $LN with whitespace
white_out ()
{
  BK=""; WH=""
  declare -i cntr=0
  while [ $cntr -lt "$LN" ] ; do BK="$BK\e[D"; WH="$WH "; let cntr+=1; done
  echo -en "$WH$BK"
}

# Return hosts. sysfs must be mounted
findhosts_26 ()
{
  hosts=
  for hostdir in /sys/class/scsi_host/host* ; do
    [ -e "$hostdir" ] || continue
    hostno=${hostdir#/sys/class/scsi_host/host}
    if [ -f "$hostdir/isp_name" ] ; then
      hostname="qla2xxx"
    elif [ -f "$hostdir/lpfc_drvr_version" ] ; then
      hostname="lpfc"
    else
      hostname=$(cat "$hostdir/proc_name")
    fi
    hosts="$hosts $hostno"
    echo_debug "Host adapter $hostno ($hostname) found."
  done
  if [ -z "$hosts" ] ; then
    echo "No SCSI host adapters found in sysfs"
    exit 1;
  fi
  # Not necessary just use double quotes around variable to preserve new lines
  #hosts=$(echo $hosts | tr ' ' '\n')
}

# Return hosts. /proc/scsi/HOSTADAPTER/? must exist
findhosts ()
{
  hosts=
  for driverdir in /proc/scsi/*; do
    driver=${driverdir#/proc/scsi/}
    if [ "$driver" = scsi ] || [ "$driver" = sg ] || [ "$driver" = dummy ] || [ "$driver" = device_info  ] ; then continue; fi
    for hostdir in $driverdir/*; do
      name=${hostdir#/proc/scsi/*/}
      if [ "$name" = add_map ] || [ "$name" = map ]  || [ "$name" = mod_parm ] ; then continue; fi
      num=$name
      driverinfo=$driver
      if [ -r "$hostdir/status" ] ; then
        num=$(printf '%d\n' "$(sed -n 's/SCSI host number://p' "$hostdir/status")")
        driverinfo="$driver:$name"
      fi
      hosts="$hosts $num"
      echo "Host adapter $num ($driverinfo) found."
    done
  done
}

printtype ()
{
  local type=$1

  case "$type" in
    0) echo "Direct-Access" ;;
    1) echo "Sequential-Access" ;;
    2) echo "Printer" ;;
    3) echo "Processor" ;;
    4) echo "WORM" ;;
    5) echo "CD-ROM" ;;
    6) echo "Scanner" ;;
    7) echo "Optical-Device" ;;
    8) echo "Medium-Changer" ;;
    9) echo "Communications" ;;
    10) echo "Unknown" ;;
    11) echo "Unknown" ;;
    12) echo "RAID" ;;
    13) echo "Enclosure" ;;
    14) echo "Direct-Access-RBC" ;;
    *) echo "Unknown" ;;
  esac
}

print02i()
{
    if [ "$1" = "*" ] ; then
        echo "00"
    else
        printf "%02i" "$1"
    fi
}

# Get /proc/scsi/scsi info for device $host:$channel:$id:$lun
# Optional parameter: Number of lines after first (default = 2),
# result in SCSISTR, return code 1 means empty.
procscsiscsi ()
{
  if [ -z "$1" ] ; then
    LN=2
  else
    LN=$1
  fi
  CHANNEL=$(print02i "$channel")
  ID=$(print02i "$id")
  LUN=$(print02i "$lun")
  if [ -d /sys/class/scsi_device ]; then
    SCSIPATH="/sys/class/scsi_device/${host}:${channel}:${id}:${lun}"
    if [ -d  "$SCSIPATH" ] ; then
      SCSISTR="Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN"
      if [ "$LN" -gt 0 ] ; then
        IVEND=$(cat "${SCSIPATH}/device/vendor")
        IPROD=$(cat "${SCSIPATH}/device/model")
        IPREV=$(cat "${SCSIPATH}/device/rev")
        SCSIDEV=$(printf '  Vendor: %-08s Model: %-16s Rev: %-4s' "$IVEND" "$IPROD" "$IPREV")
        SC