option to df(1)
To: None <gnats-admin@NetBSD.ORG>
From: None <mrg@mame.mu.OZ.AU>
List: netbsd-bugs
Date: 01/08/1995 13:35:05
>Number: 716
>Category: bin
>Synopsis: add a -t <fstype> option to df(1)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Jan 8 13:35:03 1995
>Originator: matthew green
>Organization:
bozotic softwar foundation
>Release: n/a
>Environment:
System: NetBSD splode.mame.mu.OZ.AU 1.0A NetBSD 1.0A (_splode_) #112: Fri Jan 6 22:48:01 EST 1995 mrg@splode.mame.mu.OZ.AU:/splode/build/src/sys/arch/sparc/compile/_splode_ sparc
>Description:
it's nice to be able to say "df -t ufs" to just list local disk,
or "df -t nfs", etc. it's also what 4.4-lite does.
>How-To-Repeat:
>Fix:
the patch below impliments the -t option as described in the 4.4-lite
df man page, but in a different way to the 4.4-lite df.c.
Index: df.1
===================================================================
RCS file: /local/cvs/src/bin/df/df.1,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 df.1
*** 1.1.1.1 1995/01/08 04:34:38
--- df.1 1995/01/08 11:41:07
***************
*** 40,45 ****
--- 40,46 ----
.Nd display free disk space
.Sh SYNOPSIS
.Nm df
+ .Op Fl t Ar type
.Op Fl ikln
.Op Ar file | Ar filesystem ...
.Sh DESCRIPTION
***************
*** 54,63 ****
statistics for all mounted filesystems are displayed
(subject to the
.Fl l
! option below).
.Pp
The following options are available:
.Bl -tag -width Ds
.It Fl i
Include statistics on the number of free inodes.
.It Fl k
--- 55,80 ----
statistics for all mounted filesystems are displayed
(subject to the
.Fl l
! and
! .Fl t
! options below).
.Pp
The following options are available:
.Bl -tag -width Ds
+ .It Fl t
+ Only print out statistics for filesystems of the specified types.
+ The follow additional types are recognised:
+ all (the default)
+ local (all filesystems with the MNT_LOCAL flag set).
+ 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.
+ ``df -t local -t nolfs''
+ will display statistics for all
+ .Dq local
+ file systems, except LFS.
.It Fl i
Include statistics on the number of free inodes.
.It Fl k
***************
*** 67,73 ****
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.
.It Fl n
Print out the previously obtained statistics from the filesystems.
This option should be used if it is possible that one or more
--- 84,92 ----
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. This option is deprecated by the
! .Dq -t local
! option above, and may be removed in a future release.
.It Fl n
Print out the previously obtained statistics from the filesystems.
This option should be used if it is possible that one or more
Index: df.c
===================================================================
RCS file: /local/cvs/src/bin/df/df.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 df.c
*** 1.1.1.1 1995/01/08 04:34:39
--- df.c 1995/01/08 11:41:56
***************
*** 63,74 ****
--- 63,82 ----
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));
+ struct fstype {
+ char *fs_name;
+ int fs_no;
+ };
+
int iflag, kflag = 0, nflag, lflag;
long blocksize, mntsize;
struct statfs *mntbuf;
struct ufs_args mdev;
+ struct fstype *fstypes;
+ int numfstypes, nolocal, defmatch = 1;
int
main(argc, argv)
***************
*** 81,87 ****
int ch, i;
char *mntpt;
! while ((ch = getopt(argc, argv, "ikln")) != EOF)
switch (ch) {
case 'i':
iflag = 1;
--- 89,95 ----
int ch, i;
char *mntpt;
! while ((ch = getopt(argc, argv, "iklnt:")) != EOF)
switch (ch) {
case 'i':
iflag = 1;
***************
*** 96,101 ****
--- 104,112 ----
case 'n':
nflag = 1;
break;
+ case 't':
+ add_fsmask(optarg);
+ break;
case '?':
default:
usage();
***************
*** 184,189 ****
--- 195,242 ----
return (0);
}
+ void
+ add_fsmask(fstype)
+ char *fstype;
+ {
+ int len, no = 0;
+
+ len = strlen(fstype);
+ if (len > 2 && 'n' == fstype[0] && 'o' == fstype[1]) {
+ no = 1;
+ len -= 2;
+ fstype += 2;
+ }
+ else
+ defmatch = 0;
+
+ if (!strcmp(fstype, "local")) {
+ if (no)
+ nolocal = 1;
+ else
+ lflag = 1;
+ return;
+ }
+
+ if (!strcmp(fstype, "all")) {
+ if (no) {
+ (void)fprintf(stderr, "I'm sorry. I can't do that, Dave.\n");
+ exit(1);
+ } else {
+ if (fstypes)
+ free(fstypes);
+ fstypes = NULL;
+ lflag = 0;
+ nolocal = 0;
+ }
+ }
+
+ 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,209 ****
--- 256,278 ----
static int headerlen, timesthrough;
static char *header;
long used, availblks, inodes;
+ int i, gotmatch = defmatch;
+ if (nolocal && sfsp->f_flags & MNT_LOCAL)
+ return;
+ if (lflag && !(sfsp->f_flags & MNT_LOCAL))
+ 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) {
>Audit-Trail:
>Unformatted: