For parity with NetBSD/FreeBSD df(1). I made them incompatible with -P,
as -h is; NetBSD also only supports 512/1024 with -P and FreeBSD uses -P
to force 512.
---
bin/df/df.1 | 30 +-
bin/df/df.c | 33 -
2 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/bin/df/df.1 b/bin/df/df.1
index 89dd51aac8d..f4a29f67d99 100644
--- a/bin/df/df.1
+++ b/bin/df/df.1
@@ -64,6 +64,14 @@ options, below).
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl g
+By default, all sizes are reported in 512-byte block counts.
+The
+.Fl g
+option causes the numbers to be reported in gigabyte counts.
+This option is incompatible with the
+.Fl P
+option.
.It Fl h
"Human-readable" output.
Use unit suffixes: Byte, Kilobyte, Megabyte,
@@ -88,6 +96,14 @@ Display statistics only about mounted file systems with the
flag set.
If a non-local file system is given as an argument, a
warning is issued and no information is given on that file system.
+.It Fl m
+By default, all sizes are reported in 512-byte block counts.
+The
+.Fl m
+option causes the numbers to be reported in megabyte counts.
+This option is incompatible with the
+.Fl P
+option.
.It Fl n
Print out the previously obtained statistics from the file systems.
This option should be used if it is possible that one or more
@@ -117,9 +133,11 @@ that file system.
.Pp
It is not an error to specify more than one of
the mutually exclusive options
-.Fl h
+.Fl h ,
+.Fl k ,
+.Fl m ,
and
-.Fl k .
+.Fl g .
Where more than one of these options is specified,
the last option given overrides the others.
.Sh ENVIRONMENT
@@ -128,9 +146,11 @@ the last option given overrides the others.
If the environment variable
.Ev BLOCKSIZE
is set, and the
-.Fl h
+.Fl h ,
+.Fl k ,
+.Fl m ,
or
-.Fl k
+.Fl g
options are not specified, the block counts will be displayed in units of that
size block.
.El
@@ -159,7 +179,7 @@ utility is compliant with the
specification.
.Pp
The flags
-.Op Fl hiln ,
+.Op Fl ghilmn ,
as well as the
.Ev BLOCKSIZE
environment variable,
diff --git a/bin/df/df.c b/bin/df/df.c
index fd51f906f89..b33370792d7 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -63,7 +63,7 @@ extern int e2fs_df(int, char *, struct statfs *);
extern int ffs_df(int, char *, struct statfs *);
static int raw_df(char *, struct statfs *);
-inthflag, iflag, kflag, lflag, nflag, Pflag;
+intgflag, hflag, iflag, kflag, lflag, mflag, nflag, Pflag;
char **typelist = NULL;
int
@@ -79,11 +79,19 @@ main(int argc, char *argv[])
if (pledge("stdio rpath", NULL) == -1)
err(1, "pledge");
- while ((ch = getopt(argc, argv, "hiklnPt:")) != -1)
+ while ((ch = getopt(argc, argv, "ghiklmnPt:")) != -1)
switch (ch) {
+ case 'g':
+ gflag = 1;
+ hflag = 0;
+ kflag = 0;
+ mflag = 0;
+ break;
case 'h':
hflag = 1;
kflag = 0;
+ mflag = 0;
+ gflag = 0;
break;
case 'i':
iflag = 1;
@@ -91,10 +99,17 @@ main(int argc, char *argv[])
case 'k':
kflag = 1;
hflag = 0;
+ mflag = 0;
+ gflag = 0;
break;
case 'l':
lflag = 1;
break;
+ case 'm':
+ mflag = 1;
+ hflag = 0;
+ kflag = 0;
+ break;
case 'n':
nflag = 1;
break;
@@ -112,8 +127,8 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if ((iflag || hflag) && Pflag) {
- warnx("-h and -i are incompatible with -P");
+ if ((gflag || iflag || hflag || mflag) && Pflag) {
+ warnx("-g, -h, -i, and -m are incompatible with -P");
usage();
}
@@ -357,6 +372,14 @@ bsdprint(struct statfs *mntbuf, long mntsize, int maxwidth)
blocksize = 1024;
header = "1K-blocks";
headerlen = strlen(header);
+ } else if (mflag) {
+ blocksize = 1048576;
+ header = "1M-blocks";
+ headerlen = strlen(header);
+ } else if (gflag) {
+ blocksize = 1073741824;
+ header = "1G-blocks";
+ headerlen = strlen(header);
} else
header = getbsize(&headerlen, &blocksize);
(void)printf("%-*.*s %s Used Avail Capacity",
@@ -455,7 +478,7 @@ st