Subject: bin/2869: make df more liberal in command line parsing
To: None <gnats-bugs@gnats.netbsd.org, hubert.feyrer@rz.uni-regensburg.de>
From: Hubert Feyrer <feyrer@rfhs8002.fh-regensburg.de>
List: netbsd-bugs
Date: 10/20/1996 06:29:20
>Number: 2869
>Category: bin
>Synopsis: Make df be more liberal in command line parsing
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sat Oct 19 21:35:00 1996
>Last-Modified:
>Originator: Hubert Feyrer
>Organization:
>Release: 1.2
>Environment:
System: NetBSD fuchur 1.2 NetBSD 1.2 (FUCHUR) #2: Tue Oct 15 02:45:55 MET DST 1996 feyrer@fuchur:/usr/src/sys/arch/sparc/compile/FUCHUR sparc
>Description:
When using -l or -t option to df, one can't give any options
on the command line, neither valid (i.e. local on -l) or invalid.
>How-To-Repeat:
fuchur# df
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/sd0a 305258 284316 5678 98% /
mfs:15 9822 390 8940 4% /tmp
procfs 8 8 0 100% /proc
amd:57 0 0 0 100% /net
smaug:/disk1/ftp 5458282 3726116 1459250 72% /tmp_mnt/smaug/disk1/ftp
smaug:/disk1/homes 5458282 3726116 1459250 72% /tmp_mnt/smaug/disk1/homes
fuchur# cd /disk1/ftp
fuchur# pwd
/tmp_mnt/smaug/disk1/ftp
fuchur# df -kl .
df: -l or -t does not make sense with list of mount points
fuchur# df -t nfs /
df: -l or -t does not make sense with list of mount points
The two errors above are valid, but the following would be ok:
fuchur# pwd
/tmp_mnt/smaug/disk1/ftp
fuchur# df -t nfs .
df: -l or -t does not make sense with list of mount points
fuchur# cd /tmp
fuchur# df -l .
df: -l or -t does not make sense with list of mount points
>Fix:
The patch below df actually parse each argument and only issue some
warning where it's justified, i.e. when you give it the -l-flag AND
a non-local filesystem, or you give it some typelist (-t) and a
file system of a different type.
The whole thing is to make df simply more liberal in what it accepts.
Examples (/tmp/df is the df from 1.2 with the patch below):
fuchur# cd /disk1/ftp
fuchur# pwd
/tmp_mnt/smaug/disk1/ftp
fuchur# /tmp/df -kl .
df: Warning: . is not a local file system
fuchur# /tmp/df -t nfs /
df: Warning: / mounte as a ffs file system
fuchur# pwd
/tmp_mnt/smaug/disk1/ftp
fuchur# /tmp/df -t nfs .
Filesystem 512-blocks Used Avail Capacity Mounted on
smaug:/disk1/ftp 5458282 3726116 1459250 72% /tmp_mnt/smaug/disk1/ftp
fuchur# cd /tmp
fuchur# /tmp/df -l .
Filesystem 512-blocks Used Avail Capacity Mounted on
mfs:15 9822 392 8938 4% /tmp
Here's the corresponding patch es for df.c and df.1:
*** df.c-1.2 Sun Oct 20 03:27:25 1996
--- df.c Sun Oct 20 05:56:31 1996
***************
*** 114,122 ****
argc -= optind;
argv += optind;
- if (*argv && (lflag || typelist != NULL))
- errx(1, "-l or -t does not make sense with list of mount points");
-
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
if (mntsize == 0)
err(1, "retrieving information on mounted file systems");
--- 114,119 ----
***************
*** 166,171 ****
--- 163,174 ----
* implement nflag here.
*/
if (!statfs(mntpt, &mntbuf[mntsize]))
+ if (lflag && (mntbuf[mntsize].f_flags & MNT_LOCAL) == 0)
+ warnx("Warning: %s is not a local file system", *argv);
+ else if (!selected(mntbuf[mntsize].f_fstypename))
+ warnx("Warning: %s mounte as a %s file system", *argv,
+ mntbuf[mntsize].f_fstypename);
+ else
++mntsize;
else
warn("%s", *argv);
*** df.1-1.2 Sun Oct 20 06:00:33 1996
--- df.1 Sun Oct 20 06:08:56 1996
***************
*** 73,79 ****
option causes the numbers to be reported in kilobyte counts.
.It Fl l
Display statistics only about mounted file systems with the MNT_LOCAL
! flag set.
.It Fl n
Print out the previously obtained statistics from the file systems.
This option should be used if it is possible that one or more
--- 73,80 ----
option causes the numbers to be reported in kilobyte counts.
.It Fl l
Display statistics only about mounted file systems with the MNT_LOCAL
! flag set. If a non-local file system is given as an argument, a
! warning is issued and no information is given on that file system.
.It Fl n
Print out the previously obtained statistics from the file systems.
This option should be used if it is possible that one or more
***************
*** 91,97 ****
.Dq no
to specify the filesystem types for which action should
.Em not
! be taken.
.El
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width BLOCKSIZE
--- 92,100 ----
.Dq no
to specify the filesystem types for which action should
.Em not
! be taken. If a file system is given on the command line that is not of
! the specified type, a warning is issued and no information is given on
! that file system.
.El
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width BLOCKSIZE
>Audit-Trail:
>Unformatted: