Attempt to import Lite2's df.

This commit is contained in:
bde 1997-02-17 11:29:55 +00:00
parent 93e929e89a
commit ff8c96d7b6
3 changed files with 72 additions and 116 deletions

View File

@ -1,7 +1,12 @@
# @(#)Makefile 8.2 (Berkeley) 4/1/94
# @(#)Makefile 8.3 (Berkeley) 5/8/95
PROG= df
SRCS= df.c vfslist.c
BINGRP= operator
BINMODE=2555
MOUNT= ${.CURDIR}/../../sbin/mount
CFLAGS+= -I${MOUNT}
.PATH: ${MOUNT}
.include <bsd.prog.mk>

View File

@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)df.1 8.2 (Berkeley) 1/13/94
.\" @(#)df.1 8.3 (Berkeley) 5/8/95
.\"
.Dd January 13, 1994
.Dd May 8, 1995
.Dt DF 1
.Os BSD 4
.Sh NAME
@ -71,21 +71,30 @@ will not request new statistics from the filesystems, but will respond
with the possibly stale statistics that were previously obtained.
.It Fl t
Only print out statistics for filesystems of the specified types.
The recognized types are:
ufs, nfs, mfs, lfs, msdos, fdesc, portal, kernfs, procfs, afs and isofs.
along with the aggregates:
all (the default),
local (ufs, mfs, lfs, msdos, isofs),
and misc (fdesc, portal, kernfs, procfs).
The string ``no'' may be prepending to a type to get its complement
(e.g. ``nonfs'' to get non-NFS filesystems). The first
.Fl t
option overrides the default, additional such options will add to
(or subtract from) the current set of types; e.g. either
``df -t ufs -t lfs''
or
``df -t local -t nomfs''
will display statistics for UFS and LFS filesystems.
More than one type may be specified in a comma separated list.
The list of filesystem types can be prefixed with
.Dq no
to specify the filesystem types for which action should
.Em not
be taken.
For example, the
.Nm df
command:
.Bd -literal -offset indent
df -t nonfs,mfs
.Ed
.Pp
lists all filesystems except those of type
.Tn NFS
and
.Tn MFS .
The
.Xr sysctl 8
command can be used to find out the types of filesystems
that are available on the system:
.Bd -literal -offset indent
sysctl vfs
.Ed
.El
.Sh ENVIRONMENTAL VARIABLES
.Bl -tag -width BLOCKSIZE
@ -108,7 +117,8 @@ flags are ignored if a file or filesystem is specified.
.Xr getmntinfo 3 ,
.Xr fstab 5 ,
.Xr mount 8 ,
.Xr quot 8
.Xr quot 8 ,
.Xr sysctl 8
.Sh HISTORY
A
.Nm df

View File

@ -43,12 +43,13 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
static char sccsid[] = "@(#)df.c 8.9 (Berkeley) 5/8/95";
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <ufs/ufs/ufsmount.h>
#include <err.h>
#include <errno.h>
@ -58,56 +59,16 @@ static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
#include <string.h>
#include <unistd.h>
/* XXX assumes MOUNT_MAXTYPE < 32 */
#define MT(m) (1 << (m))
int checkvfsname __P((const char *, char **));
char **makevfslist __P((char *));
long regetmntinfo __P((struct statfs **, long, char **));
int bread __P((off_t, void *, int));
char *getmntpt __P((char *));
void prtstat __P((struct statfs *, int));
void ufs_df __P((char *, int));
void usage __P((void));
/* fixed values */
#define MT_NONE (0)
#define MT_ALL (MT(MOUNT_MAXTYPE+1)-1)
/* subject to change */
#define MT_LOCAL \
(MT(MOUNT_UFS)|MT(MOUNT_MFS)|MT(MOUNT_LFS)|MT(MOUNT_MSDOS)|MT(MOUNT_CD9660))
#define MT_DEFAULT MT_ALL
struct typetab {
char *str;
long types;
} typetab[] = {
"ufs", MT(MOUNT_UFS),
"local", MT_LOCAL,
"all", MT_ALL,
"nfs", MT(MOUNT_NFS),
"mfs", MT(MOUNT_MFS),
"lfs", MT(MOUNT_LFS),
"msdos", MT(MOUNT_MSDOS),
"fdesc", MT(MOUNT_FDESC),
"portal", MT(MOUNT_PORTAL),
#if 0
/* return fsid of underlying FS */
"lofs", MT(MOUNT_LOFS),
"null", MT(MOUNT_NULL),
"umap", MT(MOUNT_UMAP),
#endif
"kernfs", MT(MOUNT_KERNFS),
"procfs", MT(MOUNT_PROCFS),
"afs", MT(MOUNT_AFS),
"iso9660fs", MT(MOUNT_CD9660),
"cdfs", MT(MOUNT_CD9660),
"misc", MT(MOUNT_LOFS)|MT(MOUNT_FDESC)|MT(MOUNT_PORTAL)|
MT(MOUNT_KERNFS)|MT(MOUNT_PROCFS),
NULL, 0
};
long addtype __P((long, char *));
long regetmntinfo __P((struct statfs **, long, long));
int bread __P((off_t, void *, int));
char *getmntpt __P((char *));
void prtstat __P((struct statfs *, int));
void ufs_df __P((char *, int));
void usage __P((void));
int iflag, nflag, tflag;
int iflag, nflag;
struct ufs_args mdev;
int
@ -117,10 +78,11 @@ main(argc, argv)
{
struct stat stbuf;
struct statfs statfsbuf, *mntbuf;
long fsmask, mntsize;
long mntsize;
int ch, err, i, maxwidth, width;
char *mntpt;
char *mntpt, **vfslist;
vfslist = NULL;
while ((ch = getopt(argc, argv, "int:")) != EOF)
switch (ch) {
case 'i':
@ -130,8 +92,9 @@ main(argc, argv)
nflag = 1;
break;
case 't':
fsmask = addtype(fsmask, optarg);
tflag = 1;
if (vfslist != NULL)
errx(1, "only one -t option may be specified.");
vfslist = makevfslist(optarg);
break;
case '?':
default:
@ -149,10 +112,8 @@ main(argc, argv)
}
if (!*argv) {
if (!tflag)
fsmask = MT_DEFAULT;
mntsize = regetmntinfo(&mntbuf, mntsize, fsmask);
if (fsmask != MT_ALL) {
mntsize = regetmntinfo(&mntbuf, mntsize, vfslist);
if (vfslist != NULL) {
maxwidth = 0;
for (i = 0; i < mntsize; i++) {
width = strlen(mntbuf[i].f_mntfromname);
@ -183,7 +144,7 @@ main(argc, argv)
warn("%s", mntpt);
continue;
}
if (mount(MOUNT_UFS, mntpt, MNT_RDONLY,
if (mount("ufs", mntpt, MNT_RDONLY,
&mdev) != 0) {
ufs_df(*argv, maxwidth);
(void)rmdir(mntpt);
@ -229,55 +190,32 @@ getmntpt(name)
return (0);
}
long
addtype(omask, str)
long omask;
char *str;
{
struct typetab *tp;
/*
* If it is one of our known types, add it to the current mask
*/
for (tp = typetab; tp->str; tp++)
if (strcmp(str, tp->str) == 0)
return (tp->types | (tflag ? omask : MT_NONE));
/*
* See if it is the negation of one of the known values
*/
if (strlen(str) > 2 && str[0] == 'n' && str[1] == 'o')
for (tp = typetab; tp->str; tp++)
if (strcmp(str+2, tp->str) == 0)
return (~tp->types & (tflag ? omask : MT_ALL));
errx(1, "unknown type `%s'", str);
}
/*
* Make a pass over the filesystem info in ``mntbuf'' filtering out
* filesystem types not in ``fsmask'' and possibly re-stating to get
* filesystem types not in vfslist and possibly re-stating to get
* current (not cached) info. Returns the new count of valid statfs bufs.
*/
long
regetmntinfo(mntbufp, mntsize, fsmask)
regetmntinfo(mntbufp, mntsize, vfslist)
struct statfs **mntbufp;
long mntsize, fsmask;
long mntsize;
char **vfslist;
{
int i, j;
struct statfs *mntbuf;
if (fsmask == MT_ALL)
if (vfslist == NULL)
return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT));
mntbuf = *mntbufp;
j = 0;
for (i = 0; i < mntsize; i++) {
if (fsmask & MT(mntbuf[i].f_type)) {
if (!nflag)
(void)statfs(mntbuf[i].f_mntonname,&mntbuf[j]);
else if (i != j)
mntbuf[j] = mntbuf[i];
j++;
}
for (j = 0, i = 0; i < mntsize; i++) {
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
if (!nflag)
(void)statfs(mntbuf[i].f_mntonname,&mntbuf[j]);
else if (i != j)
mntbuf[j] = mntbuf[i];
j++;
}
return (j);
}
@ -336,6 +274,7 @@ prtstat(sfsp, maxwidth)
* This code constitutes the pre-system call Berkeley df code for extracting
* information from filesystem superblocks.
*/
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <errno.h>
#include <fstab.h>
@ -370,7 +309,8 @@ ufs_df(file, maxwidth)
return;
}
sfsp = &statfsbuf;
sfsp->f_type = MOUNT_UFS;
sfsp->f_type = 1;
strcpy(sfsp->f_fstypename, "ufs");
sfsp->f_flags = 0;
sfsp->f_bsize = sblock.fs_fsize;
sfsp->f_iosize = sblock.fs_bsize;
@ -415,6 +355,7 @@ bread(off, buf, cnt)
void
usage()
{
(void)fprintf(stderr, "usage: df [-in] [file | file_system ...]\n");
(void)fprintf(stderr,
"usage: df [-in] [-t type] [file | file_system ...]\n");
exit(1);
}