Add `-t' option from Matthew Green, hacked a bit by me.

This commit is contained in:
mycroft 1995-01-13 23:23:41 +00:00
parent 8f6e962b3e
commit 720e729421
2 changed files with 143 additions and 21 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)df.1 8.2 (Berkeley) 1/13/92
.\" $Id: df.1,v 1.7 1994/09/16 20:59:28 mycroft Exp $
.\" $Id: df.1,v 1.8 1995/01/13 23:23:41 mycroft Exp $
.\"
.Dd January 13, 1994
.Dt DF 1
@ -41,20 +41,25 @@
.Sh SYNOPSIS
.Nm df
.Op Fl ikln
.Op Ar file | Ar filesystem ...
.Op Fl t Ar type
.Op Ar file | Ar file_system ...
.Sh DESCRIPTION
.Nm Df
displays statistics about the amount of free disk space on the specified
.Ar filesystem
or on the filesystem of which
.Ar file_system
or on the file system of which
.Ar file
is a part.
Values are displayed in 512-byte per block block counts.
If neither a file or a filesystem operand is specified,
statistics for all mounted filesystems are displayed
If neither a file or a
.Ar file_system
operand is specified,
statistics for all mounted file systems are displayed
(subject to the
.Fl l
option below).
and
.Fl t
options below).
.Pp
The following options are available:
.Bl -tag -width Ds
@ -66,17 +71,37 @@ The
.Fl k
option causes the numbers to be reported in kilobyte counts.
.It Fl l
Display statistics only about mounted filesystems with the MNT_LOCAL
flag set.
Display statistics only about mounted file systems with the MNT_LOCAL
flag set. This option is deprecated by the
.Fl t\ local
option, and may be removed in a future release.
.It Fl n
Print out the previously obtained statistics from the filesystems.
Print out the previously obtained statistics from the file systems.
This option should be used if it is possible that one or more
filesystems are in a state such that they will not be able to provide
file systems are in a state such that they will not be able to provide
statistics without a long delay.
When this option is specified,
.Nm df
will not request new statistics from the filesystems, but will respond
will not request new statistics from the file systems, but will respond
with the possibly stale statistics that were previously obtained.
.It Fl t
Only print out statistics for file systems of the specified types.
The follow additional types are recognized:
all (the default),
local (all file systems with the MNT_LOCAL flag set),
ro (all file systems with the MNT_RDONLY flag set),
and rw (all file systems with the MNT_RDONLY flag clear).
The string ``no'' may be prepended to a type to get its complement
(e.g. ``nonfs'' to get non-NFS file systems). The first
.Fl t
option overrides the default, additional such options will add to
(or subtract from) the current set of types; e.g.
``df -t ufs -t lfs''
will display statistics for UFS and LFS file systems, and
``df -t local -t nolfs''
will display statistics for all
.Dq local
file systems except LFS.
.El
.Sh ENVIRONMENTAL VARIABLES
.Bl -tag -width BLOCKSIZE

View File

@ -44,7 +44,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)df.c 8.7 (Berkeley) 4/2/94";*/
static char rcsid[] = "$Id: df.c,v 1.15 1994/09/16 20:59:29 mycroft Exp $";
static char rcsid[] = "$Id: df.c,v 1.16 1995/01/13 23:23:43 mycroft Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -63,12 +63,21 @@ int bread __P((off_t, void *, int));
char *getmntpt __P((char *));
void prtstat __P((struct statfs *, int));
void ufs_df __P((char *, int));
void add_fsmask __P((char *));
void usage __P((void));
int iflag, kflag = 0, nflag, lflag;
struct fstype {
char *fs_name;
int fs_no;
};
int iflag, kflag, nflag, tflag;
long blocksize, mntsize;
struct statfs *mntbuf;
struct ufs_args mdev;
struct fstype *fstypes;
int numfstypes, defmatch = 1;
int posflags, negflags;
int
main(argc, argv)
@ -81,7 +90,7 @@ main(argc, argv)
int ch, i;
char *mntpt;
while ((ch = getopt(argc, argv, "ikln")) != EOF)
while ((ch = getopt(argc, argv, "iklnt:")) != -1)
switch (ch) {
case 'i':
iflag = 1;
@ -91,11 +100,16 @@ main(argc, argv)
kflag = 1;
break;
case 'l':
lflag = 1;
add_fsmask("local");
tflag = 1;
break;
case 'n':
nflag = 1;
break;
case 't':
add_fsmask(optarg);
tflag = 1;
break;
case '?':
default:
usage();
@ -103,8 +117,8 @@ main(argc, argv)
argc -= optind;
argv += optind;
if (*argv && lflag)
errx(1, "-l does not make sense with list of mount points");
if (*argv && tflag)
errx(1, "-l or -t does not make sense with list of mount points");
mntsize = getmntinfo(&mntbuf, (nflag ? MNT_NOWAIT : MNT_WAIT));
if (mntsize == 0)
@ -118,8 +132,7 @@ main(argc, argv)
if (!*argv) {
for (i = 0; i < mntsize; i++)
if (!lflag || mntbuf[i].f_flags & MNT_LOCAL)
prtstat(&mntbuf[i], maxwidth);
prtstat(&mntbuf[i], maxwidth);
exit(0);
}
@ -184,6 +197,74 @@ getmntpt(name)
return (0);
}
struct fsflags {
char *ff_name;
int ff_pos;
int ff_neg;
} fsflags[] = {
{"local", MNT_LOCAL, 0},
{"ro", MNT_RDONLY, 0},
{"rw", 0, MNT_RDONLY},
};
void
add_fsmask(fstype)
char *fstype;
{
int len, no, n;
len = strlen(fstype);
if (!bcmp(fstype, "no", 2)) {
no = 1;
defmatch = 1;
len -= 2;
fstype += 2;
} else {
no = 0;
defmatch = 0;
}
for (n = 0; n < sizeof(fsflags) / sizeof(fsflags[0]); n++) {
if (!bcmp(fstype, fsflags[n].ff_name, len+1)) {
if (!no) {
posflags |= fsflags[n].ff_pos;
posflags &= ~fsflags[n].ff_neg;
negflags |= fsflags[n].ff_neg;
negflags &= !fsflags[n].ff_pos;
} else {
posflags |= fsflags[n].ff_neg;
posflags &= ~fsflags[n].ff_pos;
negflags |= fsflags[n].ff_pos;
negflags &= ~fsflags[n].ff_neg;
}
return;
}
}
if (!bcmp(fstype, "all", len+1)) {
if (no) {
(void)fprintf(stderr, "I'm sorry. I can't do that, Dave.\n");
exit(1);
} else {
fstypes = NULL;
posflags = negflags = 0;
}
}
for (n = 0; n < numfstypes; n++) {
if (!bcmp(fstype, fstypes[n].fs_name, len+1)) {
fstypes[n].fs_no = no;
return;
}
}
numfstypes++;
fstypes = (struct fstype *) realloc(fstypes, sizeof(struct fstype) * numfstypes);
fstypes[numfstypes - 1].fs_name = strdup(fstype);
fstypes[numfstypes - 1].fs_no = no;
}
/*
* Convert statfs returned filesystem size into BLOCKSIZE units.
* Attempts to avoid overflow for large filesystems.
@ -203,7 +284,23 @@ prtstat(sfsp, maxwidth)
static int headerlen, timesthrough;
static char *header;
long used, availblks, inodes;
int i, gotmatch = defmatch;
if ((sfsp->f_flags & posflags) != posflags)
return;
if ((sfsp->f_flags & negflags) != 0)
return;
if (numfstypes) {
for (i = 0; i < numfstypes; i++)
if (!strcmp(sfsp->f_fstypename, fstypes[i].fs_name)) {
if (fstypes[i].fs_no)
return;
gotmatch = 1;
break;
}
if (!gotmatch)
return;
}
if (maxwidth < 11)
maxwidth = 11;
if (++timesthrough == 1) {
@ -322,6 +419,6 @@ bread(off, buf, cnt)
void
usage()
{
(void)fprintf(stderr, "usage: df [-ikln] [file | file_system ...]\n");
(void)fprintf(stderr, "usage: df [-ikln] [-t type] [file | file_system ...]\n");
exit(1);
}