#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/usr/sbin/cluster/cspoc/utilities/clshowfs2.sh 1.7.1.2 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2001,2016 
# 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 
# @(#)36        1.7.1.2  src/43haes/usr/sbin/cluster/cspoc/utilities/clshowfs2.sh, hacmp.cspoc, 61haes_r721, 1619A_hacmp721 5/2/16 06:26:19
#
# Function:
#
#   Return the 'lsfs -q -c' output for all file systems part of the cluster
#   definition on this node.  This is both file systems explicitly part
#   of a resource group, or by implication with the 'mount all' option.
#
#   The "-v" operand can be used to restrict output to JFS or JFS2 file
#   systems.
#
# Arguments:
#
#   -v [jfs|jfs2]       type of file systems of interest.  If a "-v" value
#                       is not specifed, both types will be displayed.
#
#   clshowfs2 -v [jfs|jfs2]
#
# Return Values:
#       0       success
#       1       failure
#
#
###############################################################################

# The output can be optionally restricted to either just JFS or just JFS2 file
# systems.  Since the SMIT panels for them are different, sometimes it is
# necessary to only look at one type.

PROGNAME=${0##*/}
[[ $VERBOSE_LOGGING == "high" ]] && version="1.7.1.2"

VFS=""
while getopts ":v:" OPT ; do
    case $OPT in
	v ) #	VFS type - jfs or jfs2
	    VFS=$OPTARG
	    ;;
	* ) #	Nothing else is valid
	    ;;
    esac
done
shift $(( $OPTIND - 1 ))

VG=$1					# pick up passed volume group
if [[ -z $VG ]]
then
    dspmsg -s 126 cspoc.msg 12 "${PROGNAME}: Volume group not specified\n" $PROGNAME
    return 1
fi

export LC_ALL=C				# make all the English parsing work

if lsvg | grep -qw $VG
then
lsvg -L -l $VG |
while read LV_name Type LPs PPs PVs  LV_state Mount_point rest ; do
    if [[ -n $Mount_point && $Mount_point != "N/A" ]]
    then
        if [[ -n $VFS && $Type == $VFS ]] || [[ -z $VFS && $Type == @(jfs|jfs2) ]]
        then
            #
            :   Display information for this particular type of file system
            :   If no file system type specified, provide both JFS and JFS2
            :
            :   Get log information
            loglv=$(grep -p "^${Mount_point}:$" /etc/filesystems | sed -n '/log.*=/s/^.*= \([^ ]*\).*/\1/p')
            lvType=$(grep -p "^${Mount_point}:$" /etc/filesystems | sed -n '/vfs.*=/s/^.*= \([^ ]*\).*/\1/p')
            export lsline
            lsline=$(ls$lvType $Mount_point 2>&1)
            lsline_rc=$?
            if [[ -n $lsline ]]
            then
               if (( $lsline_rc == 0 ))
               then
                  #
                  :   Display file system information preceeded by volume
                  :   group and followed by loglv, if any
                  #
                  lsline=$(print "$lsline" | tail +2)
                  print "${VG}:${lsline}${loglv##*/}:" 
               else
                  #
                  :   file system display did not work
                  :   show any error messages
                  #
                  #Write all error msg to stderr, otherwise cl_showfs2 will try
                  #to parse everything written on stdout 
	              print "${lsline}" | sed 's/^/# /' >&2
               fi
            fi
        fi
    fi
done
fi