:
#	@(#) dfspace 22.1 90/06/05 
#
#
#	      UNIX is a registered trademark of AT&T
#		Portions Copyright 1976-1989 AT&T
#	Portions Copyright 1980-1989 Microsoft Corporation
#    Portions Copyright 1983-1989 The Santa Cruz Operation, Inc
#		      All Rights Reserved

#	Copyright (c) 1984, 1986, 1987, 1988 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident	"@(#)adm:dfspace	1.8"
# dfspace - d(isk) f(ree) space
# Calculate available disk space in all mounted filesystems.
# Alternately, report on filesystems/devices specified on cmd-line.
#   Filesystem may be 1K bytes/block, but, df uses 512 bytes/block.
#

# get free and allocated space.
df -t $* | awk '
BEGIN { FS=")"; free = -1; Blksize=512; Mbyte=1048576; CONST = Blksize / Mbyte }
{
  if (free == -1) {	# free is toggled every other line.
	split($1,fsptr,"("); FSYS=fsptr[1]
	split($2,freeptr," "); free=freeptr[2]+0
	if( free == 0 && substr(freeptr[1],1,1) != "0" ) {
		free = -1; next
	}
	FS=":"
	next
  }
  split($2,allocptr," "); alloc = allocptr[1]+0
  if (alloc == 0) next ;		# avoid division by zero
  TFREE= (free * CONST) - .005			# force rounding down.
  TALLOC= (alloc * CONST) - .005		# force rounding down.
  PCT=free * 100 / alloc
  if (TFREE < 0) TFREE=0
  if (TALLOC < 0) TALLOC=0
  printf ("%s:\tDisk space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", FSYS, TFREE, TALLOC, PCT)
  Cumfree += free; Cumalloc += alloc;
  free = -1	# reset flag/variable for next set of two lines
  FS=")"
}
END	{
	if (Cumalloc != 0) {
		CumPct=Cumfree * 100 / Cumalloc
		Cumfree= (Cumfree * CONST) - .005	# force rounding down.
		Cumalloc= (Cumalloc * CONST) - .005	# force rounding down.
		printf ("\nTotal Disk Space: %#6.2f MB of %#6.2f MB available (%#5.2f%%).\n", Cumfree, Cumalloc, CumPct)
	}
}'

# end of disk space calculation.
