Date: Mon, 22 Apr 2002 17:50:47 +1000 From: "Tim J. Robbins" <tim@robbins.dropbear.id.au> To: freebsd-standards@FreeBSD.ORG Subject: df -t option Message-ID: <20020422175047.A37860@treetop.robbins.dropbear.id.au>
next in thread | raw e-mail | index | archive | help
I've attached a patch that adds the XSI df -t option, but with a twist:
it uses -T because we already have a -t. The output format is modelled after
the Solaris output format, but uses the minimum field width possible like
BSD df usually does.
As I see it, we have three ways of attacking the problem of the conflicting
-t option:
a) Scrap support for our current `-t type' option in favour of the standard
b) Support -t with and without arguments via some heuristics
c) Add it as -T and document that fact
I'm leaning towards (c), but I'd be interested to hear what others think,
or whether there's a better way to solve the problem.
Tim
Index: df.1
===================================================================
RCS file: /home/ncvs/src/bin/df/df.1,v
retrieving revision 1.26
diff -u -r1.26 df.1
--- df.1 2002/04/16 20:00:45 1.26
+++ df.1 2002/04/22 08:45:15
@@ -32,7 +32,7 @@
.\" @(#)df.1 8.3 (Berkeley) 5/8/95
.\" $FreeBSD: src/bin/df/df.1,v 1.26 2002/04/16 20:00:45 charnier Exp $
.\"
-.Dd May 8, 1995
+.Dd April 22, 2002
.Dt DF 1
.Os
.Sh NAME
@@ -44,7 +44,7 @@
.Fl b | h | H | k |
.Fl m | P
.Oc
-.Op Fl ailn
+.Op Fl ailnT
.Op Fl t Ar type
.Op Ar file | filesystem ...
.Sh DESCRIPTION
@@ -114,6 +114,13 @@
Note that this overrides the
.Ev BLOCKSIZE
specification from the environment.
+.It Fl T
+Print information about the number of blocks and files (inodes) in use
+and available. When
+.Fl T
+is specified, the presence of
+.Fl h
+is ignored.
.It Fl t
Only print out statistics for filesystems of the specified types.
More than one type may be specified in a comma separated list.
@@ -145,12 +152,6 @@
.Ev BLOCKSIZE
is set, the block counts will be displayed in units of that size block.
.El
-.Sh BUGS
-The
-.Fl n
-and
-.Fl t
-flags are ignored if a file or filesystem is specified.
.Sh SEE ALSO
.Xr lsvfs 1 ,
.Xr quota 1 ,
@@ -161,8 +162,28 @@
.Xr fstab 5 ,
.Xr mount 8 ,
.Xr quot 8
+.Sh STANDARDS
+The
+.Nm
+utility conforms to
+.St -p1003.1-2001 .
+Due to a conflict with the existing
+.Bx
+.Nm
+.Fl t
+option, the
+.Tn XSI
+.Fl t
+option is present as
+.Fl T .
.Sh HISTORY
A
.Nm
command appeared in
.At v1 .
+.Sh BUGS
+The
+.Fl n
+and
+.Fl t
+flags are ignored if a file or filesystem is specified.
Index: df.c
===================================================================
RCS file: /home/ncvs/src/bin/df/df.c,v
retrieving revision 1.37
diff -u -r1.37 df.c
--- df.c 2002/03/26 20:32:37 1.37
+++ df.c 2002/04/22 08:45:17
@@ -93,10 +93,12 @@
/* Maximum widths of various fields. */
struct maxwidths {
+ int mnton;
int mntfrom;
int total;
int used;
int avail;
+ int itotal;
int iused;
int ifree;
};
@@ -117,14 +119,16 @@
char **makevfslist(char *);
void prthuman(struct statfs *, long);
void prthumanval(double);
+void prt(struct statfs *, struct maxwidths *);
void prtstat(struct statfs *, struct maxwidths *);
+void prttot(struct statfs *, struct maxwidths *);
long regetmntinfo(struct statfs **, long, char **);
int ufs_df(char *, struct maxwidths *);
unit_t unit_adjust(double *);
void update_maxwidths(struct maxwidths *, struct statfs *);
void usage(void);
-int aflag = 0, hflag, iflag, nflag;
+int aflag = 0, hflag, iflag, nflag, Tflag;
struct ufs_args mdev;
static __inline int imax(int a, int b)
@@ -146,7 +150,7 @@
fstype = "ufs";
vfslist = NULL;
- while ((ch = getopt(argc, argv, "abgHhiklmnPt:")) != -1)
+ while ((ch = getopt(argc, argv, "abgHhiklmnPTt:")) != -1)
switch (ch) {
case 'a':
aflag = 1;
@@ -188,6 +192,9 @@
case 'n':
nflag = 1;
break;
+ case 'T':
+ Tflag = 1;
+ break;
case 't':
if (vfslist != NULL)
errx(1, "only one -t option may be specified");
@@ -216,7 +223,7 @@
}
for (i = 0; i < mntsize; i++) {
if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
- prtstat(&mntbuf[i], &maxwidths);
+ prt(&mntbuf[i], &maxwidths);
}
exit(rv);
}
@@ -252,7 +259,7 @@
continue;
} else if (statfs(mntpt, &statfsbuf) == 0) {
statfsbuf.f_mntonname[0] = '\0';
- prtstat(&statfsbuf, &maxwidths);
+ prt(&statfsbuf, &maxwidths);
} else {
warn("%s", *argv);
rv = 1;
@@ -277,7 +284,7 @@
bzero(&maxwidths, sizeof(maxwidths));
update_maxwidths(&maxwidths, &statfsbuf);
}
- prtstat(&statfsbuf, &maxwidths);
+ prt(&statfsbuf, &maxwidths);
}
return (rv);
}
@@ -383,6 +390,18 @@
(num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
/*
+ * Print out status in requested format.
+ */
+void
+prt(struct statfs *sfsp, struct maxwidths *mwp)
+{
+ if (!Tflag)
+ prtstat(sfsp, mwp);
+ else
+ prttot(sfsp, mwp);
+}
+
+/*
* Print out status about a filesystem.
*/
void
@@ -442,6 +461,36 @@
}
/*
+ * Print out total allocated-space figures for filesystem (-T option).
+ */
+void
+prttot(struct statfs *sfsp, struct maxwidths *mwp)
+{
+ static long blocksize;
+ static int timesthrough;
+ int bwidth, dummy, fwidth;
+
+ if (blocksize == 0)
+ (void)getbsize(&dummy, &blocksize);
+
+ if (++timesthrough == 1)
+ mwp->mntfrom = imax(mwp->mntfrom, strlen("total"));
+
+ bwidth = imax(mwp->used, mwp->total);
+ fwidth = imax(mwp->iused, mwp->itotal);
+
+ (void)printf("%-*s (%-*s): %*ld blocks %*ld files\n",
+ mwp->mnton, sfsp->f_mntonname, mwp->mntfrom, sfsp->f_mntfromname,
+ bwidth, fsbtoblk(sfsp->f_blocks - sfsp->f_bfree, sfsp->f_bsize,
+ blocksize), fwidth, sfsp->f_files - sfsp->f_ffree);
+ (void)printf("%-*s %*s: %*ld blocks %*ld files\n",
+ mwp->mnton, "", mwp->mntfrom, "total", bwidth,
+ fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize), fwidth,
+ sfsp->f_files);
+}
+
+
+/*
* Update the maximum field-width information in `mwp' based on
* the filesystem specified by `sfsp'.
*/
@@ -454,6 +503,7 @@
if (blocksize == 0)
getbsize(&dummy, &blocksize);
+ mwp->mnton = imax(mwp->mnton, strlen(sfsp->f_mntonname));
mwp->mntfrom = imax(mwp->mntfrom, strlen(sfsp->f_mntfromname));
mwp->total = imax(mwp->total, longwidth(fsbtoblk(sfsp->f_blocks,
sfsp->f_bsize, blocksize)));
@@ -461,6 +511,7 @@
sfsp->f_bfree, sfsp->f_bsize, blocksize)));
mwp->avail = imax(mwp->avail, longwidth(fsbtoblk(sfsp->f_bavail,
sfsp->f_bsize, blocksize)));
+ mwp->itotal = imax(mwp->itotal, longwidth(sfsp->f_files));
mwp->iused = imax(mwp->iused, longwidth(sfsp->f_files -
sfsp->f_ffree));
mwp->ifree = imax(mwp->ifree, longwidth(sfsp->f_ffree));
@@ -536,7 +587,7 @@
mntpt = "";
memmove(&sfsp->f_mntonname[0], mntpt, (size_t)MNAMELEN);
memmove(&sfsp->f_mntfromname[0], file, (size_t)MNAMELEN);
- prtstat(sfsp, mwp);
+ prt(sfsp, mwp);
(void)close(rfd);
return (0);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020422175047.A37860>
