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
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?
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?
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
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.
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?
> 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
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.
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?
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>
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
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.
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.
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.
Just by the way, the flag used for a grand total in df(1) as defined in SUSv2 is -t, not -c. :-) Ciao, Sheldon.
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
"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.
Hi, anyone to commit this PR ? thanks in advance. Cyrille. -- Cyrille Lefevre mailto:cyrille.lefevre@laposte.net
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