[Midnightbsd-cvs] src [9400] trunk/bin/df: fixes to df
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Mar 4 16:30:17 EST 2017
Revision: 9400
http://svnweb.midnightbsd.org/src/?rev=9400
Author: laffer1
Date: 2017-03-04 16:30:17 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
fixes to df
Modified Paths:
--------------
trunk/bin/df/df.1
trunk/bin/df/df.c
Modified: trunk/bin/df/df.1
===================================================================
--- trunk/bin/df/df.1 2017-03-04 21:29:43 UTC (rev 9399)
+++ trunk/bin/df/df.1 2017-03-04 21:30:17 UTC (rev 9400)
@@ -30,7 +30,7 @@
.\" $FreeBSD: src/bin/df/df.1,v 1.42.2.1 2009/08/03 08:13:06 kensmith Exp $
.\" $MidnightBSD: src/bin/df/df.1,v 1.4 2010/03/27 21:46:55 laffer1 Exp $
.\"
-.Dd March 3, 2012
+.Dd January 24, 2013
.Dt DF 1
.Os
.Sh NAME
@@ -40,6 +40,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
@@ -51,7 +52,8 @@
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
@@ -66,48 +68,54 @@
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
@@ -120,10 +128,15 @@
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.
@@ -149,13 +162,29 @@
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 ,
@@ -165,10 +194,23 @@
.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
@@ -181,3 +223,13 @@
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: trunk/bin/df/df.c
===================================================================
--- trunk/bin/df/df.c 2017-03-04 21:29:43 UTC (rev 9399)
+++ trunk/bin/df/df.c 2017-03-04 21:30:17 UTC (rev 9400)
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
/* $FreeBSD: src/bin/df/df.c,v 1.74.2.1 2009/08/03 08:13:06 kensmith Exp $ */
-__MBSDID("$MidnightBSD: src/bin/df/df.c,v 1.10 2010/03/27 21:46:55 laffer1 Exp $");
+__MBSDID("$MidnightBSD$");
#include <sys/param.h>
#include <sys/stat.h>
@@ -54,6 +54,7 @@
#include <ufs/ufs/ufsmount.h>
#include <err.h>
#include <libutil.h>
+#include <locale.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -96,6 +97,7 @@
}
static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, Tflag;
+static int thousands;
static struct ufs_args mdev;
int
@@ -112,12 +114,13 @@
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;
@@ -181,6 +184,9 @@
case 'T':
Tflag = 1;
break;
+ case ',':
+ thousands = 1;
+ break;
case '?':
default:
usage();
@@ -196,7 +202,7 @@
} 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 */
@@ -205,13 +211,13 @@
/* 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) {
@@ -278,7 +284,7 @@
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]);
@@ -305,7 +311,7 @@
if (!strcmp(mntbuf[i].f_mntfromname, name))
return (mntbuf[i].f_mntonname);
}
- return (0);
+ return (NULL);
}
/*
@@ -389,16 +395,11 @@
/*
* 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);
}
/*
@@ -411,10 +412,18 @@
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 =
@@ -429,7 +438,7 @@
(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,
@@ -441,6 +450,12 @@
}
(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);
@@ -449,7 +464,11 @@
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),
@@ -466,7 +485,11 @@
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 :
@@ -543,7 +566,8 @@
{
(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);
}
More information about the Midnightbsd-cvs
mailing list