#!/bin/sh --- perl =---
eval 'exec perl -S $0 ${1+"$@"}'
if 0;
#
# PURPOSE:
# This command dumps out the sd or ssd to c?t?d?s? mapping
#
# REQUIREMENTS:
# disks is run to maintain the /dev/rdsk/c*s2 names
#
# sar uses The /dev/sd* names
open(P2I, "/etc/path_to_inst") || die;
while (<P2I>) {
    if (/\/s*sd/) {
        $_ =~ s/"//g;
        chop;
        split;
        if (/\/sd/) {
          $SD{$_[0]} = $_[1];
        } else {
          $SSD{$_[0]} = $_[1];
        }
    }
}
$sonomadir="/dev/osa/dev/rdsk";
if ( -d  $sonomadir ) {
    open(CTDS2I, "ls -l /dev/osa/dev/rdsk/*s2|");
} else {
    open(CTDS2I, "ls -l /dev/rdsk/*s2|") || die;
}
while (<CTDS2I>) {
    # Chop off up to the io-unit....and also chop off the slice specifier.
    $LONGINSTANCENAME = $_;
    chop($LONGINSTANCENAME);
    $LONGINSTANCENAME =~ s^.*devices^^;
    $LONGINSTANCENAME =~ s^:[c],raw^^;
    $CTDSNAME = $_;
    $CTDSNAME =~ s^.*/rdsk/^^;
    $CTDSNAME =~ s^ .*^^;
    $CTDSNAME =~ s^s2^^;
    chop($CTDSNAME);
    $INST{$LONGINSTANCENAME} .= $CTDSNAME;
    $CTD{$LONGINSTANCENAME} = $CTDSNAME;
#    print "XX", $CTDSNAME, "\n";
}
if ($ARGV[0] eq "-a" || $#ARGV < 0 ) {
  while (($key, $value) = each (%CTD)) {
    if ( $SSD{$key} ne "" ) {
        print "ssd",  $SSD{$key}, " is an alias for $value\n";
    }
    if ( $SD{$key} ne "" ) {
        print "sd",  $SD{$key}, " is an alias for $value\n";
    }
  }
}

if ($ARGV[0] =~ "ssd") {
  $search = $ARGV[0];
  $search =~ s^ssd^^;
  while (($key, $value) = each (%CTD)) {
    if ( $SSD{$key} eq $search ) {
        print "ssd",  $SSD{$key}, " is an alias for $value\n";
    }
  }
}
if ($ARGV[0] =~ "sd") {
  $search = $ARGV[0];
  $search =~ s^sd^^;
  while (($key, $value) = each (%CTD)) {
    if ( $SD{$key} eq $search ) {
        print "sd",  $SD{$key}, " is an alias for $value\n";
    }
  }
}
if ($ARGV[0] =~ "c.*t.*d.*") {
  $search = $ARGV[0];
  $search =~ s^s.*^^;
  while (($key, $value) = each (%SSD)) {
    if ( $CTD{$key} eq $search ) {
        print $search, " is an alias for ssd$value\n";
    }
  }
  while (($key, $value) = each (%SD)) {
    if ( $CTD{$key} eq $search ) {
        print $search, " is an alias for sd$value\n";
    }
  }
}
