##/bin/sh
#
# standard filters
#
# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
# Mountain View, CA 94043, or:
#
# http://www.sgi.com
#
# For further information regarding this notice, see:
#
# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
#
#
# Checks that given_value is in range of correct_value +/- tolerance.
# Tolerance can be an absolute value or a percentage of the correct value
# (see examples with tolerances below).
# Outputs suitable message to stdout if it's not in range.
#
# A verbose option, -v, may be used as the LAST argument
#
# e.g.
# foo: 0.0298 = 0.03 +/- 5%
# _within_tolerance "foo" 0.0298 0.03 5%
#
# foo: 0.0298 = 0.03 +/- 0.01
# _within_tolerance "foo" 0.0298 0.03 0.01
#
# foo: 0.0298 = 0.03 -0.01 +0.002
# _within_tolerance "foo" 0.0298 0.03 0.01 0.002
#
# foo: verbose output of 0.0298 = 0.03 +/- 5%
# _within_tolerance "foo" 0.0298 0.03 5% -v
_within_tolerance()
{
_name=$1
_given_val=$2
_correct_val=$3
_mintol=$4
_maxtol=$_mintol
_verbose=0
_debug=false
# maxtol arg is optional
# verbose arg is optional
if [ $# -ge 5 ]
then
if [ "$5" = "-v" ]
then
_verbose=1
else
_maxtol=$5
fi
fi
if [ $# -ge 6 ]
then
[ "$6" = "-v" ] && _verbose=1
fi
# find min with or without %
_mintolerance=`echo $_mintol | sed -e 's/%//'`
if [ $_mintol = $_mintolerance ]
then
_min=`echo "scale=5; $_correct_val-$_mintolerance" | bc`
else
_min=`echo "scale=5; $_correct_val-$_mintolerance*0.01*$_correct_val" | bc`
fi
# find max with or without %
_maxtolerance=`echo $_maxtol | sed -e 's/%//'`
if [ $_maxtol = $_maxtolerance ]
then
_max=`echo "scale=5; $_correct_val+$_maxtolerance" | bc`
else
_max=`echo "scale=5; $_correct_val+$_maxtolerance*0.01*$_correct_val" | bc`
fi
$_debug && echo "min = $_min"
$_debug && echo "max = $_max"
cat <<EOF >$tmp.bc.1
scale=5;
if ($_min <= $_given_val) 1;
if ($_min > $_given_val) 0;
EOF
cat <<EOF >$tmp.bc.2
scale=5;
if ($_given_val <= $_max) 1;
if ($_given_val > $_max) 0;
EOF
_above_min=`bc <$tmp.bc.1`
_below_max=`bc <$tmp.bc.2`
rm -f $tmp.bc.[12]
_in_range=`expr $_above_min \& $_below_max`
# fix up min, max precision for output
# can vary for 5.3, 6.2
_min=`echo $_min | sed -e 's/0*$//'` # get rid of trailling zeroes
_max=`echo $_max | sed -e 's/0*$//'` # get rid of trailling zeroes
if [ $_in_range -eq 1 ]
then
[ $_verbose -eq 1 ] && echo $_name is in range
return 0
else
[ $_verbose -eq 1 ] && echo $_name has value of $_given_val
[ $_verbose -eq 1 ] && echo $_name is NOT in range $_min .. $_max
return 1
fi
}
# ctime(3) dates
#
_filter_date()
{
sed \
-e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
}
# prints filtered output on stdout, values (use eval) on stderr
#
_filter_mkfs()
{
set -
perl -ne '
if (/^meta-data=([\w|\/.-]+)\s+isize=(\d+)\s+agcount=(\d+), agsize=(\d+) blks/) {
print STDERR "ddev=$1\nisize=$2\nagcount=$3\nagsize=$4\n";
print STDOUT "meta-data=DDEV isize=XXX agcount=N, agsize=XXX blks\n";
}
if (/^data\s+=\s+bsize=(\d+)\s+blocks=(\d+), imaxpct=(\d+)/) {
print STDERR "dbsize=$1\ndblocks=$2\nimaxpct=$3\n";
print STDOUT "data = bsize=XXX blocks=XXX, imaxpct=PCT\n";
}
if (/^\s+=\s+sunit=(\d+)\s+swidth=(\d+) blks, unwritten=(\d)/) {
print STDERR "sunit=$1\nswidth=$2\nunwritten=$3\n";
print STDOUT " = sunit=XXX swidth=XXX, unwritten=X\n";
}
if (/^naming\s+=version\s+(\d+)\s+bsize=(\d+)/) {
print STDERR "dirversion=$1\ndirbsize=$2\n";
print STDOUT "naming =VERN bsize=XXX\n";
}
if (/^log\s+=(internal log|[\w|\/.-]+)\s+bsize=(\d+)\s+blocks=(\d+),\s+version=(\d+)/) {
print STDERR "ldev=\"$1\"\nlbsize=$2\nlblocks=$3\nlversion=$4";
print STDOUT "log =LDEV bsize=XXX blocks=XXX\n";
}
if (/^realtime\s+=([\w|\/.-]+)\s+extsz=(\d+)\s+blocks=(\d+), rtextents=(\d+)/) {
print STDERR "rtdev=$1\nrtextsz=$2\nrtblocks=$3\nrtextents=$4\n";
print STDOUT "realtime =RDEV extsz=XXX blocks=XXX, rtextents=XXX\n";
}'
}
# make sure this script returns success
/bin/true