#!/bin/bash
set -e
devpath=
devtype=
dev=
while test "$#" -gt 0
do
  : "$1"
  case "$1" in
    --devpath) devpath=$2 ; shift ;;
    --devtype) devtype=$2 ; shift ;;
    *) echo "$0: Unknown option $1" >&2 ; exit 1 ;;
  esac
  shift
done
test -n "${devpath}" || exit 1
test -n "${devtype}" || exit 1
cd "/sys/${devpath}"
case "${devtype}" in
  partition) cd .. ;;
esac
cd -P device
d="${PWD##*/}"
d="${d/-/\/}"
backend="`xenstore-read device/${d}/backend`"
dev="`xenstore-read \"${backend}\"/dev`"
test -n "${dev}" && echo "VBD_HD_SYMLINK=${dev}"
