diff --git a/bin/df/df.1 b/bin/df/df.1 --- a/bin/df/df.1 +++ b/bin/df/df.1 @@ -118,6 +118,9 @@ specification from the environment. .It Fl l Only display information about locally-mounted file systems. +If used in combination with the +.Fl t Ar type +option, non-local file systems selected by that option will be excluded. .It Fl m Use 1048576 byte (1 Mebibyte) blocks rather than the default. This overrides any @@ -142,7 +145,7 @@ The .Fl k option overrides this option. -.It Fl t +.It Fl t Ar type Only print out statistics for file systems of the specified types. More than one type may be specified in a comma separated list. The list of file system types can be prefixed with @@ -150,6 +153,9 @@ to specify the file system types for which action should .Em not be taken. +If used in combination with the +.Fl l +option, non-local file systems will be excluded from the list. For example, the .Nm command: diff --git a/bin/df/df.c b/bin/df/df.c --- a/bin/df/df.c +++ b/bin/df/df.c @@ -88,7 +88,7 @@ static void prthumanval(const char *, int64_t); static intmax_t fsbtoblk(int64_t, uint64_t, u_long); static void prtstat(struct statfs *, struct maxwidths *); -static size_t regetmntinfo(struct statfs **, long, const char **); +static size_t regetmntinfo(struct statfs **, long, const char **, const char **); static void update_maxwidths(struct maxwidths *, const struct statfs *); static void usage(void); @@ -107,6 +107,8 @@ { NULL, no_argument, NULL, 0 }, }; +static int skipvfs_l, skipvfs_t; + int main(int argc, char *argv[]) { @@ -115,7 +117,7 @@ struct maxwidths maxwidths; struct statfs *mntbuf; char *mntpt; - const char **vfslist; + const char **vfslist_l, **vfslist_t; int i, mntsize; int ch, rv; @@ -124,7 +126,10 @@ memset(&totalbuf, 0, sizeof(totalbuf)); totalbuf.f_bsize = DEV_BSIZE; strlcpy(totalbuf.f_mntfromname, "total", MNAMELEN); - vfslist = NULL; + vfslist_l = NULL; + skipvfs_l = 0; + vfslist_t = NULL; + skipvfs_t = 0; argc = xo_parse_args(argc, argv); if (argc < 0) @@ -175,9 +180,7 @@ /* Ignore duplicate -l */ if (lflag) break; - if (vfslist != NULL) - xo_errx(1, "-l and -t are mutually exclusive."); - vfslist = makevfslist(makenetvfslist()); + vfslist_l = makevfslist2(makenetvfslist(), &skipvfs_l); lflag = 1; break; case 'm': @@ -188,11 +191,9 @@ nflag = 1; break; case 't': - if (lflag) - xo_errx(1, "-l and -t are mutually exclusive."); - if (vfslist != NULL) + if (vfslist_t != NULL) xo_errx(1, "only one -t option may be specified"); - vfslist = makevfslist(optarg); + vfslist_t = makevfslist2(optarg, &skipvfs_t); break; case 'T': Tflag = 1; @@ -211,7 +212,7 @@ if (!*argv) { /* everything (modulo -t) */ mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); - mntsize = regetmntinfo(&mntbuf, mntsize, vfslist); + mntsize = regetmntinfo(&mntbuf, mntsize, vfslist_l, vfslist_t); } else { /* just the filesystems specified on the command line */ mntbuf = malloc(argc * sizeof(*mntbuf)); @@ -259,7 +260,8 @@ * list a mount point that does not match the other args * we've been given (-l, -t, etc.). */ - if (checkvfsname(statfsbuf.f_fstypename, vfslist)) { + if (checkvfsname2(statfsbuf.f_fstypename, vfslist_l, skipvfs_l) || + checkvfsname2(statfsbuf.f_fstypename, vfslist_t, skipvfs_t)) { rv = 1; continue; } @@ -309,21 +311,24 @@ /* * Make a pass over the file system info in ``mntbuf'' filtering out - * file system types not in vfslist and possibly re-stating to get + * file system types not in vfslist_{l,t} and possibly re-stating to get * current (not cached) info. Returns the new count of valid statfs bufs. */ static size_t -regetmntinfo(struct statfs **mntbufp, long mntsize, const char **vfslist) +regetmntinfo(struct statfs **mntbufp, long mntsize, const char **vfslist_l, + const char **vfslist_t) { int error, i, j; struct statfs *mntbuf; - if (vfslist == NULL) + if (vfslist_l == NULL && vfslist_t == NULL) return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT)); mntbuf = *mntbufp; for (j = 0, i = 0; i < mntsize; i++) { - if (checkvfsname(mntbuf[i].f_fstypename, vfslist)) + if (vfslist_l && checkvfsname2(mntbuf[i].f_fstypename, vfslist_l, skipvfs_l)) + continue; + if (vfslist_t && checkvfsname2(mntbuf[i].f_fstypename, vfslist_t, skipvfs_t)) continue; /* * XXX statfs(2) can fail for various reasons. It may be diff --git a/sbin/mount/extern.h b/sbin/mount/extern.h --- a/sbin/mount/extern.h +++ b/sbin/mount/extern.h @@ -29,7 +29,9 @@ */ /* vfslist.c */ +int checkvfsname2(const char *, const char **, int); int checkvfsname(const char *, const char **); +const char **makevfslist2(char *, int *); const char **makevfslist(char *); int mount_fs(const char *, int, char *[]); diff --git a/sbin/mount/vfslist.c b/sbin/mount/vfslist.c --- a/sbin/mount/vfslist.c +++ b/sbin/mount/vfslist.c @@ -46,21 +46,27 @@ static int skipvfs; int -checkvfsname(const char *vfsname, const char **vfslist) +checkvfsname2(const char *vfsname, const char **vfslist, int skip) { if (vfslist == NULL) return (0); while (*vfslist != NULL) { if (strcmp(vfsname, *vfslist) == 0) - return (skipvfs); + return (skip); ++vfslist; } - return (!skipvfs); + return (!skip); +} + +int +checkvfsname(const char *vfsname, const char **vfslist) +{ + return (checkvfsname2(vfsname, vfslist, skipvfs)); } const char ** -makevfslist(char *fslist) +makevfslist2(char *fslist, int *skip) { const char **av; int i; @@ -68,10 +74,10 @@ if (fslist == NULL) return (NULL); - skipvfs = 0; + *skip = 0; if (fslist[0] == 'n' && fslist[1] == 'o') { fslist += 2; - skipvfs = 1; + *skip = 1; } for (i = 0, nextcp = fslist; *nextcp; nextcp++) if (*nextcp == ',') @@ -90,3 +96,9 @@ av[i++] = NULL; return (av); } + +const char ** +makevfslist(char *fslist) +{ + return (makevfslist2(fslist, &skipvfs)); +}