#!/bin/sh
#
# This maps between SAN mountpoints and SAN devices, using /etc/sanconfig.
# It has two uses which are mirrors of each other: device to mountpoint,
# and mountpoint to device.
#
# usage: mptmap [fsN/dNNN] [/export/whatever] [...]
#
# Output: always the other thing, or nothing if it can't find anything.
#
# FIXME: return status 1 if it can't find anything for at least one
# command line argument?
#
[ -f /etc/sanconfig ] && SANCF=/etc/sanconfig || SANCF=/slocal/share/adm/sanconfig2
awk '/^filesys[ 	]/ {print $2, $3}' $SANCF |
	(while read mpt dev; do
		for a in "$@"; do
			[ "$a" = "$mpt" ] && echo $dev
			[ "$a" = "$dev" ] && echo $mpt
			# allow specifying /h/.. and /w/.. and so on,
			# for convenience.
			case "$a" in
				/export/*) ;;
				/*) [ "/export$a" = "$mpt" ] && echo $dev;;
			esac
		done
	done)
