summaryrefslogtreecommitdiffstats
path: root/bin/df
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
committerobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
commit3028e3f8aba938dfd0bf9fda987b8a72140b8027 (patch)
treeb2f038222ff8a70f687652441df00d2b564c8abe /bin/df
parent952a6d5a7cd3d3f9007acfa06805262fc04a105f (diff)
parent1d08d5f677c1dfa810e381073590adbae19cc69f (diff)
downloadFreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.zip
FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.tar.gz
Sync with HEAD.
Diffstat (limited to 'bin/df')
-rw-r--r--bin/df/df.1112
-rw-r--r--bin/df/df.c47
2 files changed, 116 insertions, 43 deletions
diff --git a/bin/df/df.1 b/bin/df/df.1
index 3c60b26..8d14248 100644
--- a/bin/df/df.1
+++ b/bin/df/df.1
@@ -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 free disk space on the specified
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 that were mounted with the
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,26 +161,53 @@ command can be used to find out the types of file systems
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 ,
-.Xr pstat 1 ,
.Xr quota 1 ,
-.Xr swapinfo 1 ,
.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 +220,13 @@ flag is ignored if a file or file system is specified.
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.
diff --git a/bin/df/df.c b/bin/df/df.c
index f865b8f1..77b7a40 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <ufs/ufs/ufsmount.h>
#include <err.h>
#include <libutil.h>
+#include <locale.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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,12 @@ main(int argc, char *argv[])
int ch, rv;
fstype = "ufs";
-
+ (void)setlocale(LC_ALL, "");
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 +182,9 @@ main(int argc, char *argv[])
case 'T':
Tflag = 1;
break;
+ case ',':
+ thousands = 1;
+ break;
case '?':
default:
usage();
@@ -388,16 +393,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 +410,18 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp)
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 +436,7 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp)
(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 +448,12 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp)
}
(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 +462,11 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp)
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 +483,11 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp)
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 +564,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);
}
OpenPOWER on IntegriCloud