#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/aix/KLIB_AIX_get_fs_freespace.sh 1.4 
#  
# 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 
# @(#)75	1.4 src/43haes/lib/ksh93/aix/KLIB_AIX_get_fs_freespace.sh, hacmp.assist, 61haes_r714 11/28/11 15:09:59
#
#=head1 NAME
#
# KLIB_AIX_get_fs_freespace - Determine the amount of freespace for
#                             a filesystem in 512 blocks
#
#=head1 SYNOPSIS
#
# freespace_in_mb=$(KLIB_AIX_get_fs_freespace /tmp)
#
#=head1 DESCRIPTION
#
# This function determines the amount of freespace for the
# specified filesystem and echos that result to stdout
#
#=head1 ARGUMENTS
#
# 	1: [scalar] name of filesystem to determine free space
#
#=head1 RETURN
#
#	0: success, freespace is echo'd to stdout
# 	1: unable to determine filesystem freespace
#
#=head1 COPYRIGHT
#
#(C) COPYRIGHT International Business Machines Corp. 2005
#All Rights Reserved
#
#=cut
#
function KLIB_AIX_get_fs_freespace
{
	. /usr/es/lib/ksh93/func_include

        typeset fs=$1
        df -m $fs | tail -n 1 | while read tmp available freespace pcnt_used; do
                freespace=${freespace/\.*/}
                echo $freespace
                return 0
        done
        return 1
}
