#!/bin/sh
#
# Copyrighted as an unpublished work.
# (c) Copyright 1996,1997,1998 DESY Hamburg DMG-Division
# All rights reserved.
#
#
# RESTRICTED RIGHTS
#
# These programs are supplied under a license.  They may be used,
# disclosed, and/or copied only as permitted under such license
# agreement.  Any copy must contain the above copyright notice and
# this restricted rights notice.  Use, copying, and/or disclosure
# of the programs is strictly prohibited unless otherwise provided
# in the license agreement.
#
#set -x
#
if [ $# -lt 1 ] ; then
  echo "USAGE : md2pathfinder <filename> "
  exit 4 
fi
filename=$1
ls ".(const)(D)" 1>/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
   echo " Not in an pnfs Filesystem "
   exit 3
fi
pnfsid=`cat ".(id)($1)" 2>/dev/null`
if [ $? -ne 0 ] ; then
   nfile=`cat ".(nameof)($filename)" 2>/dev/null`

   if [ $? -ne 0 ] ; then
      echo " File not found : $filename "
      exit 45 ;
   fi
   pnfsid=$filename
   filename=$nfile
fi
echo $pnfsid $filename
sum=$filename
while : ; do
   pnfsid=`cat ".(parent)($pnfsid)" 2>/dev/null`
   if [ $? -ne 0 ] ; then break ; fi
   filename=`cat ".(nameof)($pnfsid)" 2>/dev/null`
   if [ $? -eq 0 ] ; then
      echo $pnfsid $filename
      sum=${filename}/$sum
   else 
      echo "$pnfsid -"
#    break
   fi
done
echo "/"$sum
exit 0

