From root@gits.dyndns.org  Sat Jul  1 22:58:22 2000
Return-Path: <root@gits.dyndns.org>
Received: from camus.cybercable.fr (camus.cybercable.fr [212.198.0.200])
	by hub.freebsd.org (Postfix) with SMTP id D59D137B753
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  1 Jul 2000 22:58:20 -0700 (PDT)
	(envelope-from root@gits.dyndns.org)
Received: (qmail 6786044 invoked from network); 2 Jul 2000 05:58:18 -0000
Received: from r224m65.cybercable.tm.fr (HELO gits.dyndns.org) ([195.132.224.65]) (envelope-sender <root@gits.dyndns.org>)
          by camus.cybercable.fr (qmail-ldap-1.03) with SMTP
          for <FreeBSD-gnats-submit@freebsd.org>; 2 Jul 2000 05:58:18 -0000
Received: (from root@localhost)
	by gits.dyndns.org (8.9.3/8.9.3) id HAA71231;
	Sun, 2 Jul 2000 07:58:17 +0200 (CEST)
	(envelope-from root)
Message-Id: <200007020558.HAA71231@gits.dyndns.org>
Date: Sun, 2 Jul 2000 07:58:17 +0200 (CEST)
From: clefevre@citeweb.net
Sender: root@gits.dyndns.org
Reply-To: clefevre@citeweb.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: add -c for grand total to df(1), like du(1) does
X-Send-Pr-Version: 3.2

>Number:         19635
>Category:       bin
>Synopsis:       add -c for grand total to df(1), like du(1) does
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 01 23:00:01 PDT 2000
>Closed-Date:    Sun Apr 18 13:56:51 PDT 2004
>Last-Modified:  Sun Apr 18 13:56:51 PDT 2004
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
ACME
>Environment:

FreeBSD gits 4.0-STABLE FreeBSD 4.0-STABLE #11: Wed Jun 28 06:32:13 CEST 2000     root@gits:/disk2/4.0-stable/src/sys/compile/CUSTOM  i386

>Description:

	add -c for grand total to df(1), like du(1) does.

	sample of output :

# df -c
Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/da0s1a   1904559  1249983   502212    71%    /
/dev/da1s1c   2031922  1336326   533043    71%    /disk2
/dev/da2s1a   1904559  1484367   267828    85%    /disk1
/dev/da3s1a   1904559  1414623   337572    81%    /disk4
procfs              4        4        0   100%    /proc
total         7745603  5485303  1640655    77%

>How-To-Repeat:

	n/a

>Fix:

Index: /usr/src/bin/df/df.1
===================================================================
RCS file: /home/ncvs/src/bin/df/df.1,v
retrieving revision 1.18.2.2
diff -u -b -r1.18.2.2 df.1
--- /usr/src/bin/df/df.1	2000/07/01 03:02:08	1.18.2.2
+++ /usr/src/bin/df/df.1	2000/07/02 05:38:45
@@ -44,7 +44,7 @@
 .Fl b | h | H | k |
 .Fl m | P
 .Oc
-.Op Fl ain
+.Op Fl acin
 .Op Fl t Ar type
 .Op Ar file | Ar filesystem ...
 .Sh DESCRIPTION
@@ -71,6 +71,8 @@
 this overrides the
 .Ev BLOCKSIZE
 specification from the environment.
+.It Fl c
+Display a grand total.
 .It Fl g
 Use 1073741824-byte (1-Gbyte) blocks rather than the default.  Note that
 this overrides the
Index: /usr/src/bin/df/df.c
===================================================================
RCS file: /home/ncvs/src/bin/df/df.c,v
retrieving revision 1.23.2.1
diff -u -b -r1.23.2.1 df.c
--- /usr/src/bin/df/df.c	2000/06/13 03:19:40	1.23.2.1
+++ /usr/src/bin/df/df.c	2000/07/02 05:38:40
@@ -103,11 +103,12 @@
 void	  prthuman __P((struct statfs *, long));
 void	  prthumanval __P((double));
 void	  prtstat __P((struct statfs *, int));
+void	  addstat __P((struct statfs *, struct statfs *));
 int	  ufs_df __P((char *, int));
 unit_t	  unit_adjust __P((double *));
 void	  usage __P((void));
 
-int	aflag = 0, hflag, iflag, nflag;
+int	aflag = 0, cflag = 0, hflag, iflag, nflag;
 struct	ufs_args mdev;
 
 int
@@ -116,17 +117,22 @@
 	char *argv[];
 {
 	struct stat stbuf;
-	struct statfs statfsbuf, *mntbuf;
+	struct statfs statfsbuf, *mntbuf, totalbuf = { 0 };
 	long mntsize;
 	int ch, err, i, maxwidth, rv, width;
 	char *mntpt, *mntpath, **vfslist;
 
+	totalbuf.f_bsize = DEV_BSIZE;
+	strncpy (totalbuf.f_mntfromname, "total", MNAMELEN);
 	vfslist = NULL;
-	while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
+	while ((ch = getopt(argc, argv, "abcgHhikmnPt:")) != -1)
 		switch (ch) {
 		case 'a':
 			aflag = 1;
 			break;
+		case 'c':
+			cflag = 1;
+			break;
 		case 'b':
 				/* FALLTHROUGH */
 		case 'P':
@@ -191,9 +197,14 @@
 			}
 		}
 		for (i = 0; i < mntsize; i++) {
-			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
+			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) {
 				prtstat(&mntbuf[i], maxwidth);
+				if (cflag)
+					addstat(&totalbuf, &mntbuf[i]);
+			}
 		}
+		if (cflag)
+			prtstat(&totalbuf, maxwidth);
 		exit(rv);
 	}
 
@@ -256,7 +267,11 @@
 		if (argc == 1)
 			maxwidth = strlen(statfsbuf.f_mntfromname) + 1;
 		prtstat(&statfsbuf, maxwidth);
+		if (cflag)
+			addstat(&totalbuf, &statfsbuf);
 	}
+	if (cflag)
+		prtstat(&totalbuf, maxwidth);
 	return (rv);
 }
 
@@ -380,6 +395,7 @@
 	static int headerlen, timesthrough;
 	static char *header;
 	long used, availblks, inodes;
+	int total;
 
 	if (maxwidth < 11)
 		maxwidth = 11;
@@ -411,14 +427,32 @@
 	}
 	(void)printf(" %5.0f%%",
 	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
+	total = !*sfsp->f_mntonname &&
+	    !strncmp(sfsp->f_mntfromname, "total", MNAMELEN);
 	if (iflag) {
 		inodes = sfsp->f_files;
 		used = inodes - sfsp->f_ffree;
 		(void)printf(" %7ld %7ld %5.0f%% ", used, sfsp->f_ffree,
 		   inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0);
-	} else
+	} else if (!total)
 		(void)printf("  ");
-	(void)printf("  %s\n", sfsp->f_mntonname);
+	if (!total)
+		(void)printf("  %s", sfsp->f_mntonname);
+	(void)printf("\n");
+}
+
+void
+addstat(totalfsp, statfsp)
+	struct statfs *totalfsp, *statfsp;
+{
+	totalfsp->f_blocks += (statfsp->f_blocks * statfsp->f_bsize) /
+	    totalfsp->f_bsize;
+	totalfsp->f_bfree += (statfsp->f_bfree * statfsp->f_bsize) /
+	    totalfsp->f_bsize;
+	totalfsp->f_bavail += (statfsp->f_bavail * statfsp->f_bsize) /
+	    totalfsp->f_bsize;
+	totalfsp->f_files += statfsp->f_files;
+	totalfsp->f_ffree += statfsp->f_ffree;
 }
 
 /*
@@ -506,6 +540,6 @@
 {
 
 	(void)fprintf(stderr,
-	    "usage: df [-b | -H | -h | -k | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
+	    "usage: df [-b | -H | -h | -k | -m | -P] [-acin] [-t type] [file | filesystem ...]\n");
 	exit(EX_USAGE);
 }

>Release-Note:
>Audit-Trail:

From: Will Andrews <andrews@technologist.com>
To: clefevre@citeweb.net
Cc: FreeBSD-gnats-submit@FreeBSD.org, current@FreeBSD.org
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Mon, 3 Jul 2000 21:21:52 -0400

 On Sun, Jul 02, 2000 at 07:58:17AM +0200, clefevre@citeweb.net wrote:
 > >Synopsis:       add -c for grand total to df(1), like du(1) does
 > >Description:
 > 
 > 	sample of output :
 > 
 > # df -c
 > Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
 > /dev/da0s1a   1904559  1249983   502212    71%    /
 > /dev/da1s1c   2031922  1336326   533043    71%    /disk2
 > /dev/da2s1a   1904559  1484367   267828    85%    /disk1
 > /dev/da3s1a   1904559  1414623   337572    81%    /disk4
 > procfs              4        4        0   100%    /proc
 > total         7745603  5485303  1640655    77%
 
 Does anyone else here think this is a good idea?  If so, I'd like to
 merge this in -CURRENT and MFC before 4.1-RELEASE.  It seems like a
 fairly nice addition to df(1), and can be useful for system accounting.
 
 -- 
 Will Andrews <andrewsw@purdue.edu> <will@FreeBSD.org>
 GCS/E/S @d- s+:+>+:- a--->+++ C++ UB++++ P+ L- E--- W+++ !N !o ?K w---
 ?O M+ V-- PS+ PE++ Y+ PGP+>+++ t++ 5 X++ R+ tv+ b++>++++ DI+++ D+ 
 G++>+++ e->++++ h! r-->+++ y?
 

From: Will Andrews <andrews@technologist.com>
To: Andy Farkas <andyf@speednet.com.au>
Cc: FreeBSD-gnats-submit@FreeBSD.org, current@FreeBSD.org
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Tue, 4 Jul 2000 01:35:45 -0400

 On Tue, Jul 04, 2000 at 03:32:11PM +1000, Andy Farkas wrote:
 > My only suggestion is to put a dashed line above the totals in order to
 > clearly say they are totals (like I did below).
 
 That might be nice, but I object on the grounds that it isn't consistent
 with du -c.
 
 -- 
 Will Andrews <andrewsw@purdue.edu> <will@FreeBSD.org>
 GCS/E/S @d- s+:+>+:- a--->+++ C++ UB++++ P+ L- E--- W+++ !N !o ?K w---
 ?O M+ V-- PS+ PE++ Y+ PGP+>+++ t++ 5 X++ R+ tv+ b++>++++ DI+++ D+ 
 G++>+++ e->++++ h! r-->+++ y?
 

From: Brad Knowles <blk@skynet.be>
To: Will Andrews <andrews@technologist.com>, clefevre@citeweb.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1)
 does
Date: Tue, 4 Jul 2000 10:11:06 +0200

 At 9:21 PM -0400 2000/7/3, Will Andrews wrote:
 
 >  Does anyone else here think this is a good idea?
 
 	If you're looking for votes, you've got mine.
 
 	BTW, will this play nicely with -h?  Consider me stupid if you 
 like, but I've recently been re-re-re-re-reading the man pages for 
 df(1), and ran across this option I had never heard of before, and I 
 quite like the way it adaptively summarizes the information.
 
 
 	Of course, now that you've got me started, I have to go 
 re-re-re-re-read the du(1) man page, too.  ;-)
 
 	Thanks!
 
 --
    These are my opinions -- not to be taken as official Skynet policy
 ======================================================================
 Brad Knowles, <blk@skynet.be>                || Belgacom Skynet SA/NV
 Systems Architect, Mail/News/FTP/Proxy Admin || Rue Colonel Bourg, 124
 Phone/Fax: +32-2-706.13.11/12.49             || B-1140 Brussels
 http://www.skynet.be                         || Belgium
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Will Andrews <andrews@technologist.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does 
Date: Tue, 04 Jul 2000 16:06:46 +0200

 On Mon, 03 Jul 2000 21:21:52 -0400, Will Andrews wrote:
 
 > Does anyone else here think this is a good idea?  If so, I'd like to
 > merge this in -CURRENT and MFC before 4.1-RELEASE.  It seems like a
 > fairly nice addition to df(1), and can be useful for system accounting.
 
 My only objection is that it seems to produce useless values.  Can you
 think of a use for these grand totals?
 
 Ciao,
 Sheldon.
 

From: Will Andrews <andrews@technologist.com>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: Will Andrews <andrews@technologist.com>,
	FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Tue, 4 Jul 2000 15:47:25 -0400

 On Tue, Jul 04, 2000 at 04:06:46PM +0200, Sheldon Hearn wrote:
 > My only objection is that it seems to produce useless values.  Can you
 > think of a use for these grand totals?
 
 They are helpful for monitoring total space; I would use them in
 administrative scripts to watch my space.
 
 Granted, this job could be done by shell scripts.. but I think it would
 be useful in df(1).
 
 -- 
 Will Andrews <andrewsw@purdue.edu> <will@FreeBSD.org>
 GCS/E/S @d- s+:+>+:- a--->+++ C++ UB++++ P+ L- E--- W+++ !N !o ?K w---
 ?O M+ V-- PS+ PE++ Y+ PGP+>+++ t++ 5 X++ R+ tv+ b++>++++ DI+++ D+ 
 G++>+++ e->++++ h! r-->+++ y?
 

From: Blaz Zupan <blaz@amis.net>
To: Will Andrews <andrews@technologist.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Tue, 4 Jul 2000 21:56:43 +0200 (CEST)

 > They are helpful for monitoring total space; I would use them in
 > administrative scripts to watch my space.
 
 Ok, so let's say my / is 100% full, my /usr is 50% full and my /var is 20%
 full. What would the total number tell me? That my file systems are 56.6%
 full. That tells me nothing about my root file system running out of space, so
 this number is completely useless to me. I have to agree with Sheldon, where
 is the use to this number?
 
 Blaz Zupan,  Medinet d.o.o, Linhartova 21, 2000 Maribor, Slovenia
 E-mail: blaz@amis.net, Tel: +386-2-320-6320, Fax: +386-2-320-6325
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Will Andrews <andrews@technologist.com>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does 
Date: Tue, 04 Jul 2000 22:34:41 +0200

 On Tue, 04 Jul 2000 15:47:25 -0400, Will Andrews wrote:
 
 > On Tue, Jul 04, 2000 at 04:06:46PM +0200, Sheldon Hearn wrote:
 > > My only objection is that it seems to produce useless values.  Can you
 > > think of a use for these grand totals?
 > 
 > They are helpful for monitoring total space; I would use them in
 > administrative scripts to watch my space.
 
 Okay, then.  Let me be more specific.  How is the notion of "total
 space" useful? :-)
 
 Ciao,
 Sheldon.
 

From: Will Andrews <andrews@technologist.com>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: Will Andrews <andrews@technologist.com>,
	FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Tue, 4 Jul 2000 16:37:03 -0400

 On Tue, Jul 04, 2000 at 10:34:41PM +0200, Sheldon Hearn wrote:
 > Okay, then.  Let me be more specific.  How is the notion of "total
 > space" useful? :-)
 
 Tells you when it's time to get new hard drives?
 
 I guess the originator of the PR should provide a reason. =\
 
 -- 
 Will Andrews <andrewsw@purdue.edu> <will@FreeBSD.org>
 GCS/E/S @d- s+:+>+:- a--->+++ C++ UB++++ P+ L- E--- W+++ !N !o ?K w---
 ?O M+ V-- PS+ PE++ Y+ PGP+>+++ t++ 5 X++ R+ tv+ b++>++++ DI+++ D+ 
 G++>+++ e->++++ h! r-->+++ y?
 

From: Robert Drehmel <robd@gmx.net>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: Will Andrews <andrews@technologist.com>, current@FreeBSD.ORG,
	FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Tue, 04 Jul 2000 23:48:45 +0200

 On Tue, 04 Jul 2000 22:34:41 +0200, Sheldon Hearn wrote:
 
 > > They are helpful for monitoring total space; I would use them in
 > > administrative scripts to watch my space.
 > 
 > Okay, then.  Let me be more specific.  How is the notion of "total
 > space" useful? :-)
 
 exactly. It will be more of statistical value rather than really useful,
 I think. But I don't see a reason not to merge it, anyway.
 
 -- 
 Robert Drehmel <robd@gmx.net>
 

From: Bill Fumerola <billf@chimesnet.com>
To: Blaz Zupan <blaz@amis.net>
Cc: Will Andrews <andrews@technologist.com>,
	FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Wed, 5 Jul 2000 13:58:02 -0400

 On Tue, Jul 04, 2000 at 09:56:43PM +0200, Blaz Zupan wrote:
 
 > Ok, so let's say my / is 100% full, my /usr is 50% full and my /var is 20%
 > full. What would the total number tell me? That my file systems are 56.6%
 > full. That tells me nothing about my root file system running out of space, so
 > this number is completely useless to me. I have to agree with Sheldon, where
 > is the use to this number?
 
 If you would use the "total" field to monitor diskusage on / then you get
 what you deserve.
 
 Think about doing something like
 
 $ df -c/disk0 /disk1 /disk2 ... /diskX
 
 To just monitor a cluster of disks.
 
 -- 
 Bill Fumerola - Network Architect / Computer Horizons Corp - CHIMES
 e-mail: billf@chimesnet.com / billf@FreeBSD.org
 
 
 
 

From: Paul Herman <pherman@frenchfries.net>
To: Bill Fumerola <billf@chimesnet.com>
Cc: Blaz Zupan <blaz@amis.net>,
	Will Andrews <andrews@technologist.com>,
	FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Thu, 6 Jul 2000 09:29:06 +0200 (CEST)

 On Wed, 5 Jul 2000, Bill Fumerola wrote:
 
 > On Tue, Jul 04, 2000 at 09:56:43PM +0200, Blaz Zupan wrote:
 > 
 > > this number is completely useless to me. I have to agree with Sheldon, where
 > > is the use to this number?
 > 
 > Think about doing something like
 > 
 > $ df -c/disk0 /disk1 /disk2 ... /diskX
 > 
 > To just monitor a cluster of disks.
 
 I'm all for adding options to get features you can't otherwise get
 (even *IF* the use of "total" is debatable), but c'mon, this is an awk
 one-liner.
 
 I would agree with Sheldon as well.  Let this one go.
 
 -Paul.
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Brian Hechinger <BHechinger@half.com>
Cc: 'Robert Drehmel' <robd@gmx.net>,
	Will Andrews <andrews@technologist.com>, current@FreeBSD.ORG,
	FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does 
Date: Thu, 06 Jul 2000 16:44:29 +0200

 On Thu, 06 Jul 2000 10:26:00 -0400, Brian Hechinger wrote:
 
 > beancounters don't understand that computers can have more than one disk let
 > alone multiple slices.  so it gives a nice total number to slap into a pie
 > chart so that you can requisition more hard drives for your machines.
 
 This argument from Bill Fumerola is what swayed me enough to bring me
 back to being neutral. ;-)
 
 Ciao,
 Sheldon.
 

From: Cyrille Lefevre <clefevre@no-spam.citeweb.net>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: Will Andrews <andrews@technologist.com>,
	freebsd-gnats-submit@FreeBSD.ORG, freebsd-current@FreeBSD.ORG
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: 08 Jul 2000 02:22:08 +0200

 Sheldon Hearn <sheldonh@uunet.co.za> writes:
 
 > On Tue, 04 Jul 2000 15:47:25 -0400, Will Andrews wrote:
 > 
 > > On Tue, Jul 04, 2000 at 04:06:46PM +0200, Sheldon Hearn wrote:
 > > > My only objection is that it seems to produce useless values.  Can you
 > > > think of a use for these grand totals?
 > > 
 > > They are helpful for monitoring total space; I would use them in
 > > administrative scripts to watch my space.
 > 
 > Okay, then.  Let me be more specific.  How is the notion of "total
 > space" useful? :-)
 
 statistics for backup tapes needed.
 
 for instance, at work, there is a big restructuration of departements.
 so, there are 10 gigs (about 300 GB) to move from servers to others. of
 course, I use some kind of awk scripts to do the same things. but, under
 FreeBSD, I saw that du has a -c option to do that job. why df couln't have
 the same option to do the same job ? for every scripts I write, I do it the
 more portable as possible I can. but if I can optimize the job, I'll do it.
 
 another way to say that is : how is it possible you don't like this option
 to df for any reason, while you have accepted the same option to du ?
 
 Cyrille.
 -- 
 home:mailto:clefevre@no-spam.citeweb.net Supprimer "no-spam." pour me repondre.
 work:mailto:Cyrille.Lefevre@no-spam.edf.fr Remove "no-spam." to answer me back.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does 
Date: Tue, 11 Jul 2000 15:16:17 +0200

 Just by the way, the flag used for a grand total in df(1) as defined in
 SUSv2 is -t, not -c. :-)
 
 Ciao,
 Sheldon.
 

From: Cyrille Lefevre <root@gits.dyndns.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc: will@FreeBSD.org
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Wed, 1 Nov 2000 03:13:14 +0100 (CET)

 Hi Will,
 
 I've found a -current machine where I could reproduce "the bug".
 in fact, I didn't have this bug, because I compile w/ -funroll-loops !
 so, I fix the addstat() function to bypass the long overflow using an
 intermediate variable as double in case of DEV_BSIZE > 512 (who knows :).
 
 here is a complete patch to df(1) w/ -c for grand total which seems to
 work whatever the system version and compiler options.
 
 ----------==========---------- cut here ----------==========----------
 Index: df.1
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.1,v
 retrieving revision 1.18.2.2
 diff -u -r1.18.2.2 df.1
 --- df.1	2000/07/01 03:02:08	1.18.2.2
 +++ df.1	2000/07/02 05:38:45
 @@ -44,7 +44,7 @@
  .Fl b | h | H | k |
  .Fl m | P
  .Oc
 -.Op Fl ain
 +.Op Fl acin
  .Op Fl t Ar type
  .Op Ar file | Ar filesystem ...
  .Sh DESCRIPTION
 @@ -71,6 +71,8 @@
  this overrides the
  .Ev BLOCKSIZE
  specification from the environment.
 +.It Fl c
 +Display a grand total.
  .It Fl g
  Use 1073741824-byte (1-Gbyte) blocks rather than the default.  Note that
  this overrides the
 Index: df.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.c,v
 retrieving revision 1.23.2.1
 diff -u -r1.23.2.1 df.c
 --- df.c	2000/06/13 03:19:40	1.23.2.1
 +++ df.c	2000/11/01 01:46:27
 @@ -103,11 +103,12 @@
  void	  prthuman __P((struct statfs *, long));
  void	  prthumanval __P((double));
  void	  prtstat __P((struct statfs *, int));
 +void	  addstat __P((struct statfs *, struct statfs *));
  int	  ufs_df __P((char *, int));
  unit_t	  unit_adjust __P((double *));
  void	  usage __P((void));
  
 -int	aflag = 0, hflag, iflag, nflag;
 +int	aflag = 0, cflag = 0, hflag, iflag, nflag;
  struct	ufs_args mdev;
  
  int
 @@ -116,17 +117,22 @@
  	char *argv[];
  {
  	struct stat stbuf;
 -	struct statfs statfsbuf, *mntbuf;
 +	struct statfs statfsbuf, *mntbuf, totalbuf = { 0 };
  	long mntsize;
  	int ch, err, i, maxwidth, rv, width;
  	char *mntpt, *mntpath, **vfslist;
  
 +	totalbuf.f_bsize = DEV_BSIZE;
 +	strncpy (totalbuf.f_mntfromname, "total", MNAMELEN);
  	vfslist = NULL;
 -	while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
 +	while ((ch = getopt(argc, argv, "abcgHhikmnPt:")) != -1)
  		switch (ch) {
  		case 'a':
  			aflag = 1;
  			break;
 +		case 'c':
 +			cflag = 1;
 +			break;
  		case 'b':
  				/* FALLTHROUGH */
  		case 'P':
 @@ -191,9 +197,14 @@
  			}
  		}
  		for (i = 0; i < mntsize; i++) {
 -			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
 +			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) {
  				prtstat(&mntbuf[i], maxwidth);
 +				if (cflag)
 +					addstat(&totalbuf, &mntbuf[i]);
 +			}
  		}
 +		if (cflag)
 +			prtstat(&totalbuf, maxwidth);
  		exit(rv);
  	}
  
 @@ -256,7 +267,11 @@
  		if (argc == 1)
  			maxwidth = strlen(statfsbuf.f_mntfromname) + 1;
  		prtstat(&statfsbuf, maxwidth);
 +		if (cflag)
 +			addstat(&totalbuf, &statfsbuf);
  	}
 +	if (cflag)
 +		prtstat(&totalbuf, maxwidth);
  	return (rv);
  }
  
 @@ -380,6 +395,7 @@
  	static int headerlen, timesthrough;
  	static char *header;
  	long used, availblks, inodes;
 +	int total;
  
  	if (maxwidth < 11)
  		maxwidth = 11;
 @@ -411,14 +427,31 @@
  	}
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
 +	total = !*sfsp->f_mntonname &&
 +	    !strncmp(sfsp->f_mntfromname, "total", MNAMELEN);
  	if (iflag) {
  		inodes = sfsp->f_files;
  		used = inodes - sfsp->f_ffree;
  		(void)printf(" %7ld %7ld %5.0f%% ", used, sfsp->f_ffree,
  		   inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0);
 -	} else
 +	} else if (!total)
  		(void)printf("  ");
 -	(void)printf("  %s\n", sfsp->f_mntonname);
 +	if (!total)
 +		(void)printf("  %s", sfsp->f_mntonname);
 +	(void)printf("\n");
 +}
 +
 +void
 +addstat(totalfsp, statfsp)
 +	struct statfs *totalfsp, *statfsp;
 +{
 +	double bsize = statfsp->f_bsize / totalfsp->f_bsize;
 +
 +	totalfsp->f_blocks += statfsp->f_blocks * bsize;
 +	totalfsp->f_bfree += statfsp->f_bfree * bsize;
 +	totalfsp->f_bavail += statfsp->f_bavail * bsize;
 +	totalfsp->f_files += statfsp->f_files;
 +	totalfsp->f_ffree += statfsp->f_ffree;
  }
  
  /*
 @@ -506,6 +539,6 @@
  {
  
  	(void)fprintf(stderr,
 -	    "usage: df [-b | -H | -h | -k | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
 +	    "usage: df [-b | -H | -h | -k | -m | -P] [-acin] [-t type] [file | filesystem ...]\n");
  	exit(EX_USAGE);
  }
 ----------==========---------- cut here ----------==========----------
 
 Cyrille.
 --
 home: mailto:clefevre@citeweb.net work: mailto:Cyrille.Lefevre@edf.fr
 

From: clefevre@citeweb.net
To: freebsd-gnats-submit@FreeBSD.org
Cc: will@freebsd.org
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Wed, 1 Nov 2000 03:13:14 +0100 (CET)

 Hi Will,
 
 I've found a -current machine where I could reproduce "the bug".
 in fact, I didn't have this bug, because I compile w/ -funroll-loops !
 so, I fix the addstat() function to bypass the long overflow using an
 intermediate variable as double in case of DEV_BSIZE > 512 (who knows :).
 
 here is a complete patch to df(1) w/ -c for grand total which seems to
 work whatever the system version and compiler options.
 
 ----------==========---------- cut here ----------==========----------
 Index: df.1
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.1,v
 retrieving revision 1.18.2.2
 diff -u -r1.18.2.2 df.1
 --- df.1	2000/07/01 03:02:08	1.18.2.2
 +++ df.1	2000/07/02 05:38:45
 @@ -44,7 +44,7 @@
  .Fl b | h | H | k |
  .Fl m | P
  .Oc
 -.Op Fl ain
 +.Op Fl acin
  .Op Fl t Ar type
  .Op Ar file | Ar filesystem ...
  .Sh DESCRIPTION
 @@ -71,6 +71,8 @@
  this overrides the
  .Ev BLOCKSIZE
  specification from the environment.
 +.It Fl c
 +Display a grand total.
  .It Fl g
  Use 1073741824-byte (1-Gbyte) blocks rather than the default.  Note that
  this overrides the
 Index: df.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.c,v
 retrieving revision 1.23.2.1
 diff -u -r1.23.2.1 df.c
 --- df.c	2000/06/13 03:19:40	1.23.2.1
 +++ df.c	2000/11/01 01:46:27
 @@ -103,11 +103,12 @@
  void	  prthuman __P((struct statfs *, long));
  void	  prthumanval __P((double));
  void	  prtstat __P((struct statfs *, int));
 +void	  addstat __P((struct statfs *, struct statfs *));
  int	  ufs_df __P((char *, int));
  unit_t	  unit_adjust __P((double *));
  void	  usage __P((void));
  
 -int	aflag = 0, hflag, iflag, nflag;
 +int	aflag = 0, cflag = 0, hflag, iflag, nflag;
  struct	ufs_args mdev;
  
  int
 @@ -116,17 +117,22 @@
  	char *argv[];
  {
  	struct stat stbuf;
 -	struct statfs statfsbuf, *mntbuf;
 +	struct statfs statfsbuf, *mntbuf, totalbuf = { 0 };
  	long mntsize;
  	int ch, err, i, maxwidth, rv, width;
  	char *mntpt, *mntpath, **vfslist;
  
 +	totalbuf.f_bsize = DEV_BSIZE;
 +	strncpy (totalbuf.f_mntfromname, "total", MNAMELEN);
  	vfslist = NULL;
 -	while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
 +	while ((ch = getopt(argc, argv, "abcgHhikmnPt:")) != -1)
  		switch (ch) {
  		case 'a':
  			aflag = 1;
  			break;
 +		case 'c':
 +			cflag = 1;
 +			break;
  		case 'b':
  				/* FALLTHROUGH */
  		case 'P':
 @@ -191,9 +197,14 @@
  			}
  		}
  		for (i = 0; i < mntsize; i++) {
 -			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
 +			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) {
  				prtstat(&mntbuf[i], maxwidth);
 +				if (cflag)
 +					addstat(&totalbuf, &mntbuf[i]);
 +			}
  		}
 +		if (cflag)
 +			prtstat(&totalbuf, maxwidth);
  		exit(rv);
  	}
  
 @@ -256,7 +267,11 @@
  		if (argc == 1)
  			maxwidth = strlen(statfsbuf.f_mntfromname) + 1;
  		prtstat(&statfsbuf, maxwidth);
 +		if (cflag)
 +			addstat(&totalbuf, &statfsbuf);
  	}
 +	if (cflag)
 +		prtstat(&totalbuf, maxwidth);
  	return (rv);
  }
  
 @@ -380,6 +395,7 @@
  	static int headerlen, timesthrough;
  	static char *header;
  	long used, availblks, inodes;
 +	int total;
  
  	if (maxwidth < 11)
  		maxwidth = 11;
 @@ -411,14 +427,31 @@
  	}
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
 +	total = !*sfsp->f_mntonname &&
 +	    !strncmp(sfsp->f_mntfromname, "total", MNAMELEN);
  	if (iflag) {
  		inodes = sfsp->f_files;
  		used = inodes - sfsp->f_ffree;
  		(void)printf(" %7ld %7ld %5.0f%% ", used, sfsp->f_ffree,
  		   inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0);
 -	} else
 +	} else if (!total)
  		(void)printf("  ");
 -	(void)printf("  %s\n", sfsp->f_mntonname);
 +	if (!total)
 +		(void)printf("  %s", sfsp->f_mntonname);
 +	(void)printf("\n");
 +}
 +
 +void
 +addstat(totalfsp, statfsp)
 +	struct statfs *totalfsp, *statfsp;
 +{
 +	double bsize = statfsp->f_bsize / totalfsp->f_bsize;
 +
 +	totalfsp->f_blocks += statfsp->f_blocks * bsize;
 +	totalfsp->f_bfree += statfsp->f_bfree * bsize;
 +	totalfsp->f_bavail += statfsp->f_bavail * bsize;
 +	totalfsp->f_files += statfsp->f_files;
 +	totalfsp->f_ffree += statfsp->f_ffree;
  }
  
  /*
 @@ -506,6 +539,6 @@
  {
  
  	(void)fprintf(stderr,
 -	    "usage: df [-b | -H | -h | -k | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
 +	    "usage: df [-b | -H | -h | -k | -m | -P] [-acin] [-t type] [file | filesystem ...]\n");
  	exit(EX_USAGE);
  }
 ----------==========---------- cut here ----------==========----------
 
 Cyrille.
 --
 home: mailto:clefevre@citeweb.net work: mailto:Cyrille.Lefevre@edf.fr
 

From: Cyrille Lefevre <clefevre-lists@noos.fr>
To: "Brad Knowles" <blk@skynet.be>
Cc: "\"Will Andrews\" <andrews@technologist.com>" <FreeBSD-gnats-submit@FreeBSD.ORG>,
	<current@FreeBSD.ORG>
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1)does
Date: 07 Jun 2001 01:14:15 +0200

 "Brad Knowles" <blk@skynet.be> writes:
 
 > At 9:21 PM -0400 2000/7/3, Will Andrews wrote:
 > 
 > >  Does anyone else here think this is a good idea?
 > 
 > 	If you're looking for votes, you've got mine.
 > 
 > 	BTW, will this play nicely with -h?  Consider me stupid if you
 
 yes since all internal values are counted in bytes as I remember me.
 juste the output is affected by -h or whatever option. -c just add
 a summary line.
 
 PS : take care, my email address have changed. no more citeweb.net
 (not reliable) nor poboxe.com (no more free). thanks.
 
 Cyrille.
 --
 home: mailto:clefevre@redirect.to   UNIX is user-friendly; it's just particular
 work: mailto:Cyrille.Lefevre@edf.fr   about who it chooses to be friends with.

From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Sun, 30 Jun 2002 03:03:04 +0200 (CEST)

 Hi,
 
 anyone to commit this PR ?
 
 thanks in advance.
 
 Cyrille.
 -- 
 Cyrille Lefevre                 mailto:cyrille.lefevre@laposte.net

From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: freebsd gnats <freebsd-gnats-submit@freebsd.org>,
	Will Andrews <will@freebsd.org>
Cc:  
Subject: Re: bin/19635: add -c for grand total to df(1), like du(1) does
Date: Thu, 4 Mar 2004 16:22:41 +0100

 cvs diff against -current (FreeBSD 5.2-CURRENT #1: Sat Jan 31 15:17:05 CET 2004)
 I'm using this patch for 2 years right now w/o any problems.
 could someone commit this PR ?
 thanks in advance.
 
 Index: df.1
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.1,v
 retrieving revision 1.30
 diff -u -I$Id.*$ -I$.+BSD.*$ -r1.30 df.1
 --- df.1	3 Jun 2003 12:00:35 -0000	1.30
 +++ df.1	21 Jun 2003 23:04:20 -0000
 @@ -44,6 +44,7 @@
  .Fl b | h | H | k |
  .Fl m | P
  .Oc
 +.Op Fl aciln
  .Op Fl ailn
  .Op Fl t Ar type
  .Op Ar file | filesystem ...
 @@ -73,6 +74,8 @@
  this overrides the
  .Ev BLOCKSIZE
  specification from the environment.
 +.It Fl c
 +Display a grand total.
  .It Fl g
  Use 1073741824-byte (1-Gbyte) blocks rather than the default.  Note that
  this overrides the
 Index: df.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.c,v
 retrieving revision 1.54
 diff -u -I$Id.*$ -I$.+BSD.*$ -r1.54 df.c
 --- df.c	8 Feb 2004 23:42:09 -0000	1.54
 +++ df.c	16 Feb 2004 15:43:28 -0000
 @@ -125,6 +125,7 @@
  static void	  prthuman(const struct statfs *, int64_t);
  static void	  prthumanval(double);
  static void	  prtstat(struct statfs *, struct maxwidths *);
 +static void	  addstat(struct statfs *, struct statfs *);
  static size_t	  regetmntinfo(struct statfs **, long, const char **);
  static unit_t	  unit_adjust(double *);
  static void	  update_maxwidths(struct maxwidths *, const struct statfs *);
 @@ -136,14 +137,14 @@
  	return (a > b ? a : b);
  }
  
 -static int	aflag = 0, hflag, iflag, nflag;
 +static int	aflag = 0, cflag = 0, hflag, iflag, nflag;
  static struct	ufs_args mdev;
  
  int
  main(int argc, char *argv[])
  {
  	struct stat stbuf;
 -	struct statfs statfsbuf, *mntbuf;
 +	struct statfs statfsbuf, *mntbuf, totalbuf;
  	struct maxwidths maxwidths;
  	const char *fstype;
  	char *mntpath, *mntpt;
 @@ -153,12 +154,18 @@
  
  	fstype = "ufs";
  
 +	memset (&totalbuf, 0, sizeof (totalbuf));
 +	totalbuf.f_bsize = DEV_BSIZE;
 +	strncpy (totalbuf.f_mntfromname, "total", MNAMELEN);
  	vfslist = NULL;
 -	while ((ch = getopt(argc, argv, "abgHhiklmnPt:")) != -1)
 +	while ((ch = getopt(argc, argv, "abcgHhiklmnPt:")) != -1)
  		switch (ch) {
  		case 'a':
  			aflag = 1;
  			break;
 +		case 'c':
 +			cflag = 1;
 +			break;
  		case 'b':
  				/* FALLTHROUGH */
  		case 'P':
 @@ -218,12 +225,18 @@
  	if (!*argv) {
  		mntsize = regetmntinfo(&mntbuf, mntsize, vfslist);
  		bzero(&maxwidths, sizeof(maxwidths));
 -		for (i = 0; i < mntsize; i++)
 -			update_maxwidths(&maxwidths, &mntbuf[i]);
  		for (i = 0; i < mntsize; i++) {
 +			if (cflag)
 +				addstat(&totalbuf, &mntbuf[i]);
 +			update_maxwidths(&maxwidths, &mntbuf[i]);
 +		}
 +		if (cflag)
 +			update_maxwidths(&maxwidths, &totalbuf);
 +		for (i = 0; i < mntsize; i++)
  			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
  				prtstat(&mntbuf[i], &maxwidths);
 -		}
 +		if (cflag)
 +			prtstat(&totalbuf, &maxwidths);
  		exit(rv);
  	}
  
 @@ -260,6 +273,8 @@
  				} else if (statfs(mntpt, &statfsbuf) == 0) {
  					statfsbuf.f_mntonname[0] = '\0';
  					prtstat(&statfsbuf, &maxwidths);
 +					if (cflag)
 +						addstat(&totalbuf, &statfsbuf);
  				} else {
  					warn("%s", *argv);
  					rv = 1;
 @@ -298,7 +313,11 @@
  			update_maxwidths(&maxwidths, &statfsbuf);
  		}
  		prtstat(&statfsbuf, &maxwidths);
 +		if (cflag)
 +			addstat(&totalbuf, &statfsbuf);
  	}
 +	if (cflag)
 +		prtstat(&totalbuf, &maxwidths);
  	return (rv);
  }
  
 @@ -387,11 +406,11 @@
  	unit = unit_adjust(&bytes);
  
  	if (bytes == 0)
 -		(void)printf("     0B");
 +		(void)printf("      0B");
  	else if (bytes > 10)
 -		(void)printf(" %5.0f%c", bytes, "BKMGTPE"[unit]);
 +		(void)printf(" % 6.0f%c", bytes, "BKMGTPE"[unit]);
  	else
 -		(void)printf(" %5.1f%c", bytes, "BKMGTPE"[unit]);
 +		(void)printf(" % 6.1f%c", bytes, "BKMGTPE"[unit]);
  }
  
  /*
 @@ -412,6 +431,7 @@
  	static int headerlen, timesthrough = 0;
  	static const char *header;
  	int64_t used, availblks, inodes;
 +	int total;
  
  	if (++timesthrough == 1) {
  		mwp->mntfrom = imax(mwp->mntfrom, (int)strlen("Filesystem"));
 @@ -453,15 +473,31 @@
  	}
  	(void)printf(" %5.0f%%",
  	    availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
 +	total = !*sfsp->f_mntonname &&
 +	    !strncmp(sfsp->f_mntfromname, "total", MNAMELEN);
  	if (iflag) {
  		inodes = sfsp->f_files;
  		used = inodes - sfsp->f_ffree;
 -		(void)printf(" %*jd %*jd %4.0f%% ", mwp->iused, (intmax_t)used,
 -		    mwp->ifree, (intmax_t)sfsp->f_ffree, inodes == 0 ? 100.0 :
 -		    (double)used / (double)inodes * 100.0);
 -	} else
 -		(void)printf("  ");
 -	(void)printf("  %s\n", sfsp->f_mntonname);
 +		(void)printf(" %*jd %*jd %4.0f%% ",
 +		    mwp->iused, (intmax_t)used,
 +		    mwp->ifree, (intmax_t)sfsp->f_ffree,
 +		    inodes == 0 ? 100.0 : (double)used / (double)inodes * 100.0);
 +	} else if (!total)
 +		(void)printf("  %s", sfsp->f_mntonname);
 +	(void)printf("\n");
 +}
 +
 +void
 +addstat(totalfsp, statfsp)
 +	struct statfs *totalfsp, *statfsp;
 +{
 +	double bsize = statfsp->f_bsize / totalfsp->f_bsize;
 +
 +	totalfsp->f_blocks += statfsp->f_blocks * bsize;
 +	totalfsp->f_bfree += statfsp->f_bfree * bsize;
 +	totalfsp->f_bavail += statfsp->f_bavail * bsize;
 +	totalfsp->f_files += statfsp->f_files;
 +	totalfsp->f_ffree += statfsp->f_ffree;
  }
  
  /*
 @@ -515,7 +551,7 @@
  {
  
  	(void)fprintf(stderr,
 -	    "usage: df [-b | -H | -h | -k | -m | -P] [-ailn] [-t type] [file | filesystem ...]\n");
 +	    "usage: df [-b | -H | -h | -k | -m | -P] [-aciln] [-t type] [file | filesystem ...]\n");
  	exit(EX_USAGE);
  }
  
 Cyrille Lefevre
 -- 
 mailto:cyrille.lefevre@laposte.net
State-Changed-From-To: open->closed 
State-Changed-By: obrien 
State-Changed-When: Sun Apr 18 13:56:46 PDT 2004 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=19635 
>Unformatted:
