Module Name: src
Committed By: kre
Date: Sat Aug 3 05:27:58 UTC 2024
Modified Files:
src/bin/df: df.1 df.c
Log Message:
Add -M and -q options to df(1).
-q suppresses warning output (rather than redirecting stderr, which
also buries error messages, which -q does not).
-M requires each arg given to be the name of a mount point, and
issues a warning, and ignores the arg, if it is not. This allows
scripts (etc) to have a whole list of places for which to produce df
output, while only listing the ones that are actually mounted (rather
than simply listing the filesystem containing the mount point instead -
perhaps several times). (If there are no args, -M is a no-op).
If the options aren't given, nothing alters.
To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/bin/df/df.1
cvs rdiff -u -r1.102 -r1.103 src/bin/df/df.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/df/df.1
diff -u src/bin/df/df.1:1.59 src/bin/df/df.1:1.60
--- src/bin/df/df.1:1.59 Sat Aug 3 04:04:54 2024
+++ src/bin/df/df.1 Sat Aug 3 05:27:58 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: df.1,v 1.59 2024/08/03 04:04:54 kre Exp $
+.\" $NetBSD: df.1,v 1.60 2024/08/03 05:27:58 kre Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)df.1 8.2 (Berkeley) 1/13/92
.\"
-.Dd August 8, 2022
+.Dd August 3, 2024
.Dt DF 1
.Os
.Sh NAME
@@ -37,7 +37,7 @@
.Nd display free disk space
.Sh SYNOPSIS
.Nm
-.Op Fl aclnW
+.Op Fl aclMnqW
.Op Fl G | Fl bkP | Fl bfgHhikmN
.Op Fl t Ar type
.Oo Ar file | Ar file_system Oc Ns ...
@@ -173,6 +173,23 @@ Display statistics only about mounted fi
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 M
+Each
+.Ar file
+.Pq or Ar file_system
+specified as an argument must give a path to a mount point
+in the tree, at which a file system is currently mounted.
+Information for that mounted file system is, if not otherwise
+excluded, provided.
+If a
+.Ar file
+which does not name a mount point is specified,
+a warning is issued,
+and no information is given for the file system on which that
+.Ar file
+resides (unless some other
+.Ar file
+names its mount point).
.It Fl m
The
.Fl m
@@ -217,6 +234,8 @@ option may not be specified with
and the
.Ar blksize
is required to be 512 or 1024.
+.It Fl q
+Suppress all warning output.
.It Fl t Ar type
Is used to indicate the actions should only be taken on
file systems of the specified type.
Index: src/bin/df/df.c
diff -u src/bin/df/df.c:1.102 src/bin/df/df.c:1.103
--- src/bin/df/df.c:1.102 Mon Dec 18 08:27:24 2023
+++ src/bin/df/df.c Sat Aug 3 05:27:58 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: df.c,v 1.102 2023/12/18 08:27:24 kre Exp $ */
+/* $NetBSD: df.c,v 1.103 2024/08/03 05:27:58 kre Exp $ */
/*
* Copyright (c) 1980, 1990, 1993, 1994
@@ -45,7 +45,7 @@ __COPYRIGHT(
#if 0
static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: df.c,v 1.102 2023/12/18 08:27:24 kre Exp $");
+__RCSID("$NetBSD: df.c,v 1.103 2024/08/03 05:27:58 kre Exp $");
#endif
#endif /* not lint */
@@ -77,7 +77,7 @@ static void prthumanval(int64_t, int);
static void prthuman(const struct statvfs *, int64_t, int64_t);
static int aflag, cflag, fflag, gflag, hflag, iflag, lflag;
-static int Nflag, nflag, Pflag, Wflag;
+static int Mflag, Nflag, nflag, Pflag, qflag, Wflag;
static long usize;
static char **typelist;
static size_t mntcount;
@@ -88,6 +88,9 @@ static int blksize_width = WIDTH_BLKSIZE
static int fudgeunits = 0;
+#define streq(a, b) (strcmp((a), (b)) == 0)
+#define warnq(args) do { if (!qflag) warnx args; } while (0)
+
int
main(int argc, char *argv[])
{
@@ -100,7 +103,7 @@ main(int argc, char *argv[])
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "abcfGgHhiklmNnPt:W")) != -1)
+ while ((ch = getopt(argc, argv, "abcfGgHhiklMmNnPqt:W")) != -1)
switch (ch) {
case 'a':
aflag = 1;
@@ -139,6 +142,9 @@ main(int argc, char *argv[])
case 'l':
lflag = 1;
break;
+ case 'M':
+ Mflag = 1;
+ break;
case 'm':
hflag = 0;
usize = 1024 * 1024;
@@ -152,6 +158,9 @@ main(int argc, char *argv[])
case 'P':
Pflag = 1;
break;
+ case 'q':
+ qflag = 1;
+ break;
case 'W':
Wflag = 1;
break;
@@ -203,7 +212,8 @@ main(int argc, char *argv[])
for (/*EMPTY*/; *argv != NULL; argv++) {
if (stat(*argv, &stbuf) < 0) {
if ((mntpt = getmntpt(*argv)) == 0) {
- warn("%s", *argv);
+ if (!qflag)
+ warn("%s", *argv);
continue;
}
} else if (S_ISBLK(stbuf.st_mode)) {
@@ -211,25 +221,30 @@ main(int argc, char *argv[])
mntpt = *argv;
} else
mntpt = *argv;
+
/*
* Statfs does not take a `wait' flag, so we cannot
* implement nflag here.
*/
- if (!statvfs(mntpt, &mntbuf[mntcount]))
- if (lflag &&
+ if (!statvfs(mntpt, &mntbuf[mntcount])) {
+ if (Mflag &&
+ !streq(mntpt, mntbuf[mntcount].f_mntonname))
+ warnq(("%s is not a mount point",
+ mntpt));
+ else if (lflag &&
(mntbuf[mntcount].f_flag & MNT_LOCAL) == 0)
- warnx("Warning: %s is not a local %s",
- *argv, "file system");
+ warnq(("Warning: %s is not a local %s",
+ *argv, "file system"));
else if
(!selected(mntbuf[mntcount].f_fstypename,
sizeof(mntbuf[mntcount].f_fstypename)))
- warnx("Warning: %s mounted as a %s %s",
+ warnq(("Warning: %s mounted as a %s %s",
*argv,
mntbuf[mntcount].f_fstypename,
- "file system");
+ "file system"));
else
++mntcount;
- else
+ } else if (!qflag)
warn("%s", *argv);
}
}
@@ -277,7 +292,7 @@ getmntpt(const char *name)
if (count == 0)
err(EXIT_FAILURE, "Can't get mount information");
for (i = 0; i < count; i++) {
- if (!strcmp(mntbuf[i].f_mntfromname, name))
+ if (streq(mntbuf[i].f_mntfromname, name))
return mntbuf[i].f_mntonname;
}
return 0;
@@ -628,7 +643,7 @@ usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-aclnW] [-G|-bkP|-bfgHhikmN] [-t type] [file | "
+ "Usage: %s [-aclMnqW] [-G|-bkP|-bfgHhikmN] [-t type] [file | "
"file_system]...\n",
getprogname());
exit(1);