#!/bin/csh -f set HELPFILE = /tmp/help.$$ echo "usage: $0 [-c] [-h] [-v] [str] [str]" > $HELPFILE cat >> $HELPFILE << EOF This script prints out the bytes per inode specification given to newfs when the filesystem was created. It also prints the bytes used per inode used for the structure (as shown by df). If the percentage of inodes used is greater than the percentage of space used (as shown by df), a warning is printed. The motivation for this script is that I *lost* the extra space I'd gained specifying "-i 6144" when newfs'ing some filesystems when someone recreated those filesystems during an emergency used the default. :^( There are three switches: -c just dump bytes/inodes specified, only if not the default -h print this message and exit -v dump a lot of debugging information daw, 8/30/96 EOF switch (`uname -s``uname -r`) case SunOS4*: set SUNOS # set DF = /bin/df set DFK set DFI = -i set DFL = "-t 4.2" breaksw case SunOS5*: set SOLARIS # set DF = /bin/df set DFK = -k set DFI = -oi set DFL = "-F ufs" breaksw default: exec echo ${0}: does not run on `uname -s` `uname -r` endsw set STRS set DEFAULT = 2048 while($#argv) switch ("$1") case -c: set CONFIG # just dump bytes/inodes, only if not default shift breaksw case -h: more $HELPFILE exec /bin/rm $HELPFILE breaksw case -p: set PERCENT # just give ratio of percentages used shift breaksw case -v: set VERBOSE shift breaksw default: set STRS = ( $STRS $1 ) shift breaksw endsw end /bin/rm $HELPFILE if ("$STRS" == "") then set STRS = `/bin/df $DFK $DFL | grep ^/dev/ | awk '{print $NF}' | sort` endif foreach STR ( $STRS ) set KLINE = `/bin/df $DFK $STR |& grep -v Mounted` if ($#KLINE != 6) then #echo \"/bin/df $DFK $STR\" returned \"$KLINE\" # take out when we see this is working sleep 1 set KLINE = `/bin/df $DFK $STR |& grep -v Mounted` if ($#KLINE != 6) exec echo \"/bin/df $DFK $STR\" returned \"$KLINE\" endif if ($?VERBOSE) echo KLINE = $KLINE @ TOTK = $KLINE[2] @ KUSED = $KLINE[3] @ PCTK = `echo $KLINE[5] | sed 's;%;;'` set ILINE = `/bin/df $DFI $STR |& grep -v Mounted` if ($#ILINE != 5) then #echo \"/bin/df $DFI $STR\" returned \"$ILINE\" # take out when we see this is working sleep 1 set ILINE = `/bin/df $DFI $STR |& grep -v Mounted` if ($#ILINE != 5) exec echo \"/bin/df $DFI $STR\" returned \"$ILINE\" endif if ($?VERBOSE) echo ILINE = $ILINE @ TOTI = $ILINE[2] + $ILINE[3] @ PCTI = `echo $ILINE[4] | sed 's;%;;'` if ($?VERBOSE) echo KUSED = $KUSED, K% = $PCTK, I = $TOTI, I% = $PCTI #MB = #SECTORS / 2048 #SECTORS = #cyls * #SEC_PER_CYL #SEC_PER_CYL = #sec_per_track * #heads_per_cyl if ($?SUNOS) then set DEV = `echo $ILINE[1] | sed 's;.*/;;'` set DKINFO = `/etc/dkinfo $DEV` if ($?VERBOSE) echo DKINFO = $DKINFO @ I = 2 while ( $I < $#DKINFO ) @ P = $I - 1 if ($DKINFO[$I] == "sectors") then @ SECS = $DKINFO[$P] break endif @ I++ end else if ($?SOLARIS) then # set PART = `echo $ILINE[1] | sed 's;.*/c.t.d.s;;'` # the above didn't work for metadisks set PART = `echo $ILINE[1] | sed 's;.*\(.\);\1;'` set PLINE = `/usr/sbin/prtvtoc $ILINE[1] |& awk '{if ($1 == '$PART') print}'` if ($?VERBOSE) echo PLINE = $PLINE if ($#PLINE) then @ SECS = $PLINE[5] else # prtvtoc does not work for metadisks. use total space available to estimate: @ SECS = $TOTK * 2 endif endif if ($?VERBOSE) echo SECS = $SECS # when this gets too large (eg, on /igor/ref) these generate # erroneous answers without indicating any problem! # @ BYTES = $SECS * 512 # @ BYTES = `echo "$SECS 512 * p" | dc` set BYTES = `echo "$SECS 512 * p" | dc` if ($?VERBOSE) echo BYTES = $BYTES @ BPI = `echo $BYTES $TOTI / p |dc` if ($?VERBOSE) echo BPI = $BPI # This bytes/inode figure is only approximately what was specified to # newfs. Determine the exact figure: @ ISPEC = 1024 while(1) @ DIFF = $ISPEC - $BPI if ($DIFF > -512 && $DIFF <= 512) break # sanity check: if ($DIFF > 1024) exec echo could not determine bpi for $STR @ ISPEC += 1024 end set BUSED = `echo "$KUSED 1024 * p" | dc` set UBPI = `echo $BUSED $ILINE[2] / p | dc` set UKPI = `echo 2k $UBPI 1024 / p | dc` set RATIO = `echo 2k $PCTI $PCTK / p | dc` if ($?VERBOSE) echo BUSED = $BUSED\; UBPI = "($BUSED / $ILINE[2])" $UBPI if ((!($PCTK > $PCTI)) && ($PCTK > 0)) then set WARN = " *";set WARNDONE else set WARN endif if ($?CONFIG) then if ($ISPEC != $DEFAULT || "$WARN" != "") echo ${STR}: \"-i $ISPEC\" specified to newfs"$WARN" else if ($?PERCENT) then echo ${STR}: inodes/kbytes usage percentage ratio: $RATIO"$WARN" else echo ${STR}: bytes/inode specified: $ISPEC\; used: $UBPI \(${UKPI}k\)"$WARN" endif end if ($?WARNDONE) then echo "*" Warning: inodes allocated for structure may be too few endif