PR/36541: Greg A. Woods: fix -P option, and add solaris -g option.
This commit is contained in:
parent
1ee8f4a418
commit
98d594125d
34
bin/df/df.1
34
bin/df/df.1
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: df.1,v 1.40 2007/01/28 09:56:13 wiz Exp $
|
||||
.\" $NetBSD: df.1,v 1.41 2007/06/24 01:52:46 christos Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -29,7 +29,7 @@
|
||||
.\"
|
||||
.\" @(#)df.1 8.2 (Berkeley) 1/13/92
|
||||
.\"
|
||||
.Dd January 28, 2007
|
||||
.Dd June 23, 2007
|
||||
.Dt DF 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -37,7 +37,8 @@
|
||||
.Nd display free disk space
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl aghiklmnP
|
||||
.Op Fl aGklmn
|
||||
.Op Fl g | Fl i | Fl P
|
||||
.Op Fl t Ar type
|
||||
.Op Ar file | Ar file_system ...
|
||||
.Sh DESCRIPTION
|
||||
@ -71,11 +72,27 @@ Show all mount points,
|
||||
including those that were mounted with the
|
||||
.Dv MNT_IGNORE
|
||||
flag.
|
||||
.It Fl g
|
||||
.It Fl G
|
||||
The
|
||||
.Fl g
|
||||
.Fl G
|
||||
option causes the numbers to be reported in gigabytes (1024*1024*1024
|
||||
bytes).
|
||||
.It Fl g
|
||||
Display all the fields of the structure(s) returned by
|
||||
.Xr statvfs 2 .
|
||||
This option cannot be used with the
|
||||
.Fl i
|
||||
or
|
||||
.Fl P
|
||||
options.
|
||||
This option will override the
|
||||
.Fl G ,
|
||||
.Fl h ,
|
||||
.Fl k ,
|
||||
and
|
||||
.Fl m
|
||||
options, as well as any setting of
|
||||
.Ev BLOCKSIZE .
|
||||
.It Fl h
|
||||
"Human-readable" output.
|
||||
Use unit suffixes: Byte, Kilobyte, Megabyte,
|
||||
@ -136,6 +153,11 @@ The header line is followed by data formatted as follows:
|
||||
\*[Lt]space used\*[Gt], \*[Lt]space free\*[Gt], \*[Lt]percentage used\*[Gt],
|
||||
\*[Lt]file system root\*[Gt]
|
||||
.Ed
|
||||
.Pp
|
||||
Note that the
|
||||
.Fl i
|
||||
option may not be specified with
|
||||
.Fl P .
|
||||
.It Fl t Ar type
|
||||
Is used to indicate the actions should only be taken on
|
||||
filesystems of the specified type.
|
||||
@ -155,7 +177,7 @@ that file system.
|
||||
If the environment variable
|
||||
.Ev BLOCKSIZE
|
||||
is set, and the
|
||||
.Fl g ,
|
||||
.Fl G ,
|
||||
.Fl h ,
|
||||
.Fl k
|
||||
and
|
||||
|
132
bin/df/df.c
132
bin/df/df.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: df.c,v 1.72 2006/09/04 16:32:57 christos Exp $ */
|
||||
/* $NetBSD: df.c,v 1.73 2007/06/24 01:52:46 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1990, 1993, 1994
|
||||
@ -45,7 +45,7 @@ __COPYRIGHT(
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: df.c,v 1.72 2006/09/04 16:32:57 christos Exp $");
|
||||
__RCSID("$NetBSD: df.c,v 1.73 2007/06/24 01:52:46 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -77,8 +77,8 @@ void prthuman(struct statvfs *, int64_t, int64_t);
|
||||
const char *
|
||||
strpct64(uint64_t, uint64_t, u_int);
|
||||
|
||||
int aflag, hflag, iflag, lflag, nflag, Pflag;
|
||||
long usize = 0;
|
||||
int aflag, gflag, hflag, iflag, lflag, nflag, Pflag;
|
||||
long usize = 0;
|
||||
char **typelist = NULL;
|
||||
|
||||
int
|
||||
@ -90,15 +90,18 @@ main(int argc, char *argv[])
|
||||
int ch, i, maxwidth, width;
|
||||
char *mntpt;
|
||||
|
||||
while ((ch = getopt(argc, argv, "aghiklmnPt:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "aGghiklmnPt:")) != -1)
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
hflag = 0;
|
||||
usize = 1024 * 1024 * 1024;
|
||||
break;
|
||||
case 'g':
|
||||
gflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
hflag = 1;
|
||||
usize = 0;
|
||||
@ -132,6 +135,12 @@ main(int argc, char *argv[])
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if (gflag && (Pflag || iflag))
|
||||
errx(1, "only one of -g and -P or -i may be specified");
|
||||
if (Pflag && iflag)
|
||||
errx(1, "only one of -P and -i may be specified");
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@ -317,7 +326,7 @@ prthuman(struct statvfs *sfsp, int64_t used, int64_t bavail)
|
||||
|
||||
prthumanval(sfsp->f_blocks * sfsp->f_frsize, "");
|
||||
prthumanval(used * sfsp->f_frsize, " ");
|
||||
prthumanval(bavail * sfsp->f_frsize, " ");
|
||||
prthumanval(bavail * sfsp->f_frsize, " ");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -343,8 +352,52 @@ prtstat(struct statvfs *sfsp, int maxwidth)
|
||||
int64_t used, availblks, inodes;
|
||||
int64_t bavail;
|
||||
|
||||
if (maxwidth < 11)
|
||||
maxwidth = 11;
|
||||
if (gflag) {
|
||||
/*
|
||||
* From SunOS-5.6:
|
||||
*
|
||||
* /var (/dev/dsk/c0t0d0s3 ): 8192 block size 1024 frag size
|
||||
* 984242 total blocks 860692 free blocks 859708 available 249984 total files
|
||||
* 248691 free files 8388611 filesys id
|
||||
* ufs fstype 0x00000004 flag 255 filename length
|
||||
*
|
||||
*/
|
||||
(void)printf("%10s (%-12s): %7ld block size %12ld frag size\n",
|
||||
sfsp->f_mntonname, sfsp->f_mntfromname,
|
||||
sfsp->f_iosize, /* On UFS/FFS systems this is
|
||||
* also called the "optimal
|
||||
* transfer block size" but it
|
||||
* is of course the file
|
||||
* system's block size too.
|
||||
*/
|
||||
sfsp->f_bsize); /* not so surprisingly the
|
||||
* "fundamental file system
|
||||
* block size" is the frag
|
||||
* size.
|
||||
*/
|
||||
(void)printf("%10" PRId64 " total blocks %10" PRId64
|
||||
" free blocks %10" PRId64 " available\n",
|
||||
(uint64_t)sfsp->f_blocks, (uint64_t)sfsp->f_bfree,
|
||||
(uint64_t)sfsp->f_bavail);
|
||||
(void)printf("%10" PRId64 " total files %10" PRId64
|
||||
" free files %12lx filesys id\n",
|
||||
(uint64_t)sfsp->f_ffree, (uint64_t)sfsp->f_files,
|
||||
sfsp->f_fsid);
|
||||
(void)printf("%10s fstype %#15lx flag %17ld filename "
|
||||
"length\n", sfsp->f_fstypename, sfsp->f_flag,
|
||||
sfsp->f_namemax);
|
||||
(void)printf("%10lu owner %17" PRId64 " syncwrites %12" PRId64
|
||||
" asyncwrites\n\n", (unsigned long)sfsp->f_owner,
|
||||
sfsp->f_syncwrites, sfsp->f_asyncwrites);
|
||||
|
||||
/*
|
||||
* a concession by the structured programming police to the
|
||||
* indentation police....
|
||||
*/
|
||||
return;
|
||||
}
|
||||
if (maxwidth < 12)
|
||||
maxwidth = 12;
|
||||
if (++timesthrough == 1) {
|
||||
switch (blocksize = usize) {
|
||||
case 1024:
|
||||
@ -367,38 +420,70 @@ prtstat(struct statvfs *sfsp, int maxwidth)
|
||||
header = getbsize(&headerlen, &blocksize);
|
||||
break;
|
||||
}
|
||||
(void)printf("%-*.*s %s Used %9s Capacity",
|
||||
maxwidth, maxwidth, "Filesystem", header,
|
||||
Pflag ? "Available" : "Avail");
|
||||
if (iflag)
|
||||
(void)printf(" iused ifree %%iused");
|
||||
(void)printf(" Mounted on\n");
|
||||
if (Pflag) {
|
||||
/*
|
||||
* "Filesystem {1024,512}-blocks Used Available
|
||||
* Capacity Mounted on\n"
|
||||
*/
|
||||
(void)printf("Filesystem %s Used Available Capacity "
|
||||
"Mounted on\n", header);
|
||||
} else {
|
||||
(void)printf("%-*.*s %s Used Avail %%Cap",
|
||||
maxwidth - (headerlen - 9),
|
||||
maxwidth - (headerlen - 9),
|
||||
"Filesystem", header);
|
||||
if (iflag)
|
||||
(void)printf(" iUsed iAvail %%iCap");
|
||||
(void)printf(" Mounted on\n");
|
||||
}
|
||||
}
|
||||
(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
|
||||
used = sfsp->f_blocks - sfsp->f_bfree;
|
||||
bavail = sfsp->f_bfree - sfsp->f_bresvd;
|
||||
availblks = bavail + used;
|
||||
if (Pflag) {
|
||||
/*
|
||||
* "%s %d %d %d %s %s\n", <file system name>, <total space>,
|
||||
* <space used>, <space free>, <percentage used>,
|
||||
* <file system root>
|
||||
*/
|
||||
(void)printf("%s %" PRId64 " %" PRId64 " %" PRId64 " %s %s\n",
|
||||
sfsp->f_mntfromname,
|
||||
fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
|
||||
fsbtoblk(used, sfsp->f_bsize, blocksize),
|
||||
fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize),
|
||||
availblks == 0 ? full : strpct64((uint64_t) used,
|
||||
(uint64_t) availblks, 0), sfsp->f_mntonname);
|
||||
/*
|
||||
* another concession by the structured programming police to
|
||||
* the indentation police....
|
||||
*
|
||||
* Note iflag cannot be set when Pflag is set.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
|
||||
|
||||
if (hflag)
|
||||
prthuman(sfsp, used, bavail);
|
||||
else
|
||||
(void)printf(" %*" PRId64 " %9" PRId64 " %9" PRId64, headerlen,
|
||||
(void)printf("%10" PRId64 " %10" PRId64 " %10" PRId64,
|
||||
fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize),
|
||||
fsbtoblk(used, sfsp->f_frsize, blocksize),
|
||||
fsbtoblk(bavail, sfsp->f_frsize, blocksize));
|
||||
(void)printf("%7s",
|
||||
(void)printf(" %4s",
|
||||
availblks == 0 ? full :
|
||||
/* We know that these values are never negative */
|
||||
strpct64((uint64_t)used, (uint64_t)availblks, 0));
|
||||
if (iflag) {
|
||||
inodes = sfsp->f_files;
|
||||
used = inodes - sfsp->f_ffree;
|
||||
(void)printf(" %8ld %8ld %6s ",
|
||||
(void)printf(" %8ld %8ld %4s",
|
||||
(u_long)used, (u_long)sfsp->f_ffree,
|
||||
inodes == 0 ? (used == 0 ? empty : full) :
|
||||
strpct64((uint64_t)used, (uint64_t)inodes, 0));
|
||||
} else
|
||||
(void)printf(" ");
|
||||
(void)printf(" %s\n", sfsp->f_mntonname);
|
||||
}
|
||||
(void)printf(" %s\n", sfsp->f_mntonname);
|
||||
}
|
||||
|
||||
void
|
||||
@ -406,7 +491,8 @@ usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: %s [-aghiklmnP] [-t type] [file | file_system ...]\n",
|
||||
"Usage: %s [-aGghklmn] [-i|-p] [-t type] [file | "
|
||||
"file_system ...]\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
|
Loading…
Reference in New Issue
Block a user