#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/OEMVeritas/KLIB_OEMVeritas_getDiskGroupForFilesystem.sh 1.5 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2005,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)08        1.5 src/43haes/lib/ksh93/OEMVeritas/KLIB_OEMVeritas_getDiskGroupForFilesystem.sh, hacmp.utils, 61haes_r714 11/28/11 15:03:23
function KLIB_OEMVeritas_getDiskGroupForFilesystem {
	. /usr/es/lib/ksh93/func_include

	typeset filesystem=$1
	typeset dgs=$(KLIB_OEMVeritas_lsdg)
	typeset dg
	typeset fs
	for dg in $dgs; do
	        # If DG is active, read off of disk
		filesystems=$(KLIB_OEMVeritas_getFilesystemsForDiskGroup $dg)
		for fs in $filesystems; do
			if [[ "$fs" == "$filesystem" ]]; then
				echo $dg
				return 0
			fi
		done
	done

	# If DG is inactive, try /etc/filesystems
	dg=$(LANG="C" lsfs -v vxfs | grep -w $filesystem | awk -F"/" '{ print $5 }')
	if [[ -n $dg ]]; then
	        echo $dg
	        return 0
	fi

	# If dg not found, failure
	return 1
}
