Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jul 2000 07:58:17 +0200 (CEST)
From:      clefevre@citeweb.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/19635: add -c for grand total to df(1), like du(1) does
Message-ID:  <200007020558.HAA71231@gits.dyndns.org>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 01 23:00:01 PDT 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007020558.HAA71231>