From owner-svn-src-stable@FreeBSD.ORG Fri May 17 03:55:04 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7D41049A; Fri, 17 May 2013 03:55:04 +0000 (UTC) (envelope-from grog@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 601B02CC; Fri, 17 May 2013 03:55:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4H3t42G058788; Fri, 17 May 2013 03:55:04 GMT (envelope-from grog@svn.freebsd.org) Received: (from grog@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4H3t4rX058785; Fri, 17 May 2013 03:55:04 GMT (envelope-from grog@svn.freebsd.org) Message-Id: <201305170355.r4H3t4rX058785@svn.freebsd.org> From: Greg Lehey Date: Fri, 17 May 2013 03:55:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r250733 - stable/9/bin/df X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 May 2013 03:55:04 -0000 Author: grog Date: Fri May 17 03:55:03 2013 New Revision: 250733 URL: http://svnweb.freebsd.org/changeset/base/250733 Log: MFC revisions 243049,243129,244134,245871,245912,249698,249924 Modified: stable/9/bin/df/df.1 stable/9/bin/df/df.c Directory Properties: stable/9/bin/df/ (props changed) Modified: stable/9/bin/df/df.1 ============================================================================== --- stable/9/bin/df/df.1 Fri May 17 03:52:20 2013 (r250732) +++ stable/9/bin/df/df.1 Fri May 17 03:55:03 2013 (r250733) @@ -29,7 +29,7 @@ .\" @(#)df.1 8.3 (Berkeley) 5/8/95 .\" $FreeBSD$ .\" -.Dd March 3, 2012 +.Dd January 24, 2013 .Dt DF 1 .Os .Sh NAME @@ -39,6 +39,7 @@ .Nm .Op Fl b | g | H | h | k | m | P .Op Fl acilnT +.Op Fl \&, .Op Fl t Ar type .Op Ar file | filesystem ... .Sh DESCRIPTION @@ -50,7 +51,8 @@ displays statistics about the amount of or on the file system of which .Ar file is a part. -Values are displayed in 512-byte per block counts. +By default block counts are displayed with an assumed block size of +512 bytes. If neither a file or a file system operand is specified, statistics for all mounted file systems are displayed (subject to the @@ -65,48 +67,54 @@ Show all mount points, including those t flag. This is implied for file systems specified on the command line. .It Fl b -Use 512-byte blocks rather than the default. -Note that -this overrides the +Explicitly use 512 byte blocks, overriding any .Ev BLOCKSIZE specification from the environment. +This is the same as the +.Fl P +option. +The +.Fl k +option overrides this option. .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 +Use 1073741824 byte (1 Gibibyte) blocks rather than the default. +This overrides any .Ev BLOCKSIZE specification from the environment. .It Fl H .Dq Human-readable output. -Use unit suffixes: Byte, Kilobyte, Megabyte, -Gigabyte, Terabyte and Petabyte in order to reduce the number of -digits to four or fewer using base 10 for sizes. +Use unit suffixes: Byte, Kibibyte, Mebibyte, Gibibyte, Tebibyte and +Pebibyte (based on powers of 1024) in order to reduce the number of +digits to four or fewer. .It Fl h .Dq Human-readable output. Use unit suffixes: Byte, Kilobyte, Megabyte, -Gigabyte, Terabyte and Petabyte in order to reduce the number of -digits to four or fewer using base 2 for sizes. -Inodes statistics, if enabled with -.Fl i , -are always printed in base 10. +Gigabyte, Terabyte and Petabyte (based on powers of 1000) in order to +reduce the number of +digits to four or fewer. .It Fl i -Include statistics on the number of free inodes. +Include statistics on the number of free and used inodes. +In conjunction with the +.Fl h +or +.Fl H +options, the number of inodes is scaled by powers of 1000. .It Fl k -Use 1024-byte (1-Kbyte) blocks rather than the default. -Note that -this overrides the +Use 1024 byte (1 Kibibyte) blocks rather than the default. +This overrides the +.Fl P +option and any .Ev BLOCKSIZE specification from the environment. .It Fl l Only display information about locally-mounted file systems. .It Fl m -Use 1048576-byte (1-Mbyte) blocks rather than the default. -Note that -this overrides the +Use 1048576 byte (1 Mebibyte) blocks rather than the default. +This overrides any .Ev BLOCKSIZE specification from the environment. .It Fl n @@ -119,10 +127,15 @@ When this option is specified, will not request new statistics from the file systems, but will respond with the possibly stale statistics that were previously obtained. .It Fl P -Use POSIX compliant output of 512-byte blocks rather than the default. -Note that this overrides the +Explicitly use 512 byte blocks, overriding any .Ev BLOCKSIZE specification from the environment. +This is the same as the +.Fl b +option. +The +.Fl k +option overrides this option. .It Fl t Only print out statistics for file systems of the specified types. More than one type may be specified in a comma separated list. @@ -148,13 +161,29 @@ command can be used to find out the type that are available on the system. .It Fl T Include file system type. +.It Fl , +(Comma) Print sizes grouped and separated by thousands using the +non-monetary separator returned by +.Xr localeconv 3 , +typically a comma or period. +If no locale is set, or the locale does not have a non-monetary separator, this +option has no effect. .El .Sh ENVIRONMENT .Bl -tag -width BLOCKSIZE .It Ev BLOCKSIZE -If the environment variable -.Ev BLOCKSIZE -is set, the block counts will be displayed in units of that size block. +Specifies the units in which to report block counts. +This uses +.Xr getbsize 3 , +which allows units of bytes or numbers scaled with the letters +.Em k +(for multiples of 1024 bytes), +.Em m +(for multiples of 1048576 bytes) or +.Em g +(for gibibytes). +The allowed range is 512 bytes to 1 GB. +If the value is outside, it will be set to the appropriate limit. .El .Sh SEE ALSO .Xr lsvfs 1 , @@ -164,10 +193,23 @@ is set, the block counts will be display .Xr fstatfs 2 , .Xr getfsstat 2 , .Xr statfs 2 , +.Xr getbsize 3 , .Xr getmntinfo 3 , +.Xr localeconv 3 , .Xr fstab 5 , .Xr mount 8 , -.Xr quot 8 +.Xr quot 8 . +.Sh STANDARDS +With the exception of most options, +the +.Nm +utility conforms to +.St -p1003.1-2004 , +which defines only the +.Fl k , P +and +.Fl t +options. .Sh HISTORY A .Nm @@ -180,3 +222,13 @@ flag is ignored if a file or file system Also, if a mount point is not accessible by the user, it is possible that the file system information could be stale. +.Pp +The +.Fl b +and +.Fl P +options are identical. +The former comes from the BSD tradition, and the latter is required +for +.St -p1003.1-2004 +conformity. Modified: stable/9/bin/df/df.c ============================================================================== --- stable/9/bin/df/df.c Fri May 17 03:52:20 2013 (r250732) +++ stable/9/bin/df/df.c Fri May 17 03:55:03 2013 (r250733) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -95,6 +96,7 @@ imax(int a, int b) } static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, Tflag; +static int thousands; static struct ufs_args mdev; int @@ -111,12 +113,13 @@ main(int argc, char *argv[]) int ch, rv; fstype = "ufs"; - + (void)setlocale(LC_ALL, ""); + memset(&maxwidths, 0, sizeof(maxwidths)); memset(&totalbuf, 0, sizeof(totalbuf)); totalbuf.f_bsize = DEV_BSIZE; strlcpy(totalbuf.f_mntfromname, "total", MNAMELEN); vfslist = NULL; - while ((ch = getopt(argc, argv, "abcgHhiklmnPt:T")) != -1) + while ((ch = getopt(argc, argv, "abcgHhiklmnPt:T,")) != -1) switch (ch) { case 'a': aflag = 1; @@ -180,6 +183,9 @@ main(int argc, char *argv[]) case 'T': Tflag = 1; break; + case ',': + thousands = 1; + break; case '?': default: usage(); @@ -195,7 +201,7 @@ main(int argc, char *argv[]) } else { /* just the filesystems specified on the command line */ mntbuf = malloc(argc * sizeof(*mntbuf)); - if (mntbuf == 0) + if (mntbuf == NULL) err(1, "malloc()"); mntsize = 0; /* continued in for loop below */ @@ -204,13 +210,13 @@ main(int argc, char *argv[]) /* iterate through specified filesystems */ for (; *argv; argv++) { if (stat(*argv, &stbuf) < 0) { - if ((mntpt = getmntpt(*argv)) == 0) { + if ((mntpt = getmntpt(*argv)) == NULL) { warn("%s", *argv); rv = 1; continue; } } else if (S_ISCHR(stbuf.st_mode)) { - if ((mntpt = getmntpt(*argv)) == 0) { + if ((mntpt = getmntpt(*argv)) == NULL) { mdev.fspec = *argv; mntpath = strdup("/tmp/df.XXXXXX"); if (mntpath == NULL) { @@ -277,7 +283,7 @@ main(int argc, char *argv[]) mntbuf[mntsize++] = statfsbuf; } - bzero(&maxwidths, sizeof(maxwidths)); + memset(&maxwidths, 0, sizeof(maxwidths)); for (i = 0; i < mntsize; i++) { if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0) { update_maxwidths(&maxwidths, &mntbuf[i]); @@ -304,7 +310,7 @@ getmntpt(const char *name) if (!strcmp(mntbuf[i].f_mntfromname, name)) return (mntbuf[i].f_mntonname); } - return (0); + return (NULL); } /* @@ -388,16 +394,11 @@ prthumanvalinode(int64_t bytes) /* * Convert statfs returned file system size into BLOCKSIZE units. - * Attempts to avoid overflow for large file systems. */ static intmax_t fsbtoblk(int64_t num, uint64_t fsbs, u_long bs) { - - if (fsbs != 0 && fsbs < bs) - return (num / (intmax_t)(bs / fsbs)); - else - return (num * (intmax_t)(fsbs / bs)); + return (num * (intmax_t) fsbs / (int64_t) bs); } /* @@ -410,10 +411,18 @@ prtstat(struct statfs *sfsp, struct maxw static int headerlen, timesthrough = 0; static const char *header; int64_t used, availblks, inodes; + const char *format; if (++timesthrough == 1) { mwp->mntfrom = imax(mwp->mntfrom, (int)strlen("Filesystem")); mwp->fstype = imax(mwp->fstype, (int)strlen("Type")); + if (thousands) { /* make space for commas */ + mwp->total += (mwp->total - 1) / 3; + mwp->used += (mwp->used - 1) / 3; + mwp->avail += (mwp->avail - 1) / 3; + mwp->iused += (mwp->iused - 1) / 3; + mwp->ifree += (mwp->ifree - 1) / 3; + } if (hflag) { header = " Size"; mwp->total = mwp->used = mwp->avail = @@ -428,7 +437,7 @@ prtstat(struct statfs *sfsp, struct maxw (void)printf("%-*s", mwp->mntfrom, "Filesystem"); if (Tflag) (void)printf(" %-*s", mwp->fstype, "Type"); - (void)printf(" %-*s %*s %*s Capacity", mwp->total, header, + (void)printf(" %*s %*s %*s Capacity", mwp->total, header, mwp->used, "Used", mwp->avail, "Avail"); if (iflag) { mwp->iused = imax(hflag ? 0 : mwp->iused, @@ -440,6 +449,12 @@ prtstat(struct statfs *sfsp, struct maxw } (void)printf(" Mounted on\n"); } + /* Check for 0 block size. Can this happen? */ + if (sfsp->f_bsize == 0) { + warnx ("File system %s does not have a block size, assuming 512.", + sfsp->f_mntonname); + sfsp->f_bsize = 512; + } (void)printf("%-*s", mwp->mntfrom, sfsp->f_mntfromname); if (Tflag) (void)printf(" %-*s", mwp->fstype, sfsp->f_fstypename); @@ -448,7 +463,11 @@ prtstat(struct statfs *sfsp, struct maxw if (hflag) { prthuman(sfsp, used); } else { - (void)printf(" %*jd %*jd %*jd", + if (thousands) + format = " %*j'd %*j'd %*j'd"; + else + format = " %*jd %*jd %*jd"; + (void)printf(format, mwp->total, fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize), mwp->used, fsbtoblk(used, sfsp->f_bsize, blocksize), @@ -465,7 +484,11 @@ prtstat(struct statfs *sfsp, struct maxw prthumanvalinode(used); prthumanvalinode(sfsp->f_ffree); } else { - (void)printf(" %*jd %*jd", mwp->iused, (intmax_t)used, + if (thousands) + format = " %*j'd %*j'd"; + else + format = " %*jd %*jd"; + (void)printf(format, mwp->iused, (intmax_t)used, mwp->ifree, (intmax_t)sfsp->f_ffree); } (void)printf(" %4.0f%% ", inodes == 0 ? 100.0 : @@ -542,7 +565,8 @@ usage(void) { (void)fprintf(stderr, -"usage: df [-b | -g | -H | -h | -k | -m | -P] [-acilnT] [-t type] [file | filesystem ...]\n"); +"usage: df [-b | -g | -H | -h | -k | -m | -P] [-acilnT] [-t type] [-,]\n" +" [file | filesystem ...]\n"); exit(EX_USAGE); }