Added the -l option to df, so to be compatable with other unicies.

PR:		bin/27240
Reviewed by:	GAWollman
MFC after:	2 weeks
This commit is contained in:
Jim Pirzyk 2001-06-04 23:07:15 +00:00
parent 35f3d11437
commit a25695c3a4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77734
2 changed files with 59 additions and 4 deletions

View file

@ -44,7 +44,7 @@
.Fl b | h | H | k |
.Fl m | P
.Oc
.Op Fl ain
.Op Fl ailn
.Op Fl t Ar type
.Op Ar file | filesystem ...
.Sh DESCRIPTION
@ -91,6 +91,8 @@ Use 1024-byte (1-Kbyte) blocks rather than the default. Note that
this overrides the
.Ev BLOCKSIZE
specification from the environment.
.It Fl l
Only display information about locally-mounted filesystems.
.It Fl m
Use 1048576-byte (1-Mbyte) blocks rather than the default. Note that
this overrides the
@ -106,7 +108,7 @@ When this option is specified,
will not request new statistics from the filesystems, but will respond
with the possibly stale statistics that were previously obtained.
.It Fl P
Use POSIX compliant output of 512-byte blocks rather than the default.
Use POSIX compliant output of 512-byte blocks rather than the default.
Note that this overrides the
.Ev BLOCKSIZE
specification from the environment.

View file

@ -54,6 +54,7 @@ static const char rcsid[] =
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <ufs/ufs/ufsmount.h>
#include <err.h>
@ -99,6 +100,7 @@ int bread __P((off_t, void *, int));
int checkvfsname __P((const char *, char **));
char *getmntpt __P((char *));
int main __P((int, char *[]));
char *makenetvfslist __P((void));
char **makevfslist __P((char *));
void prthuman __P((struct statfs *, long));
void prthumanval __P((double));
@ -126,7 +128,7 @@ main(argc, argv)
fstype = "ufs";
vfslist = NULL;
while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
while ((ch = getopt(argc, argv, "abgHhiklmnPt:")) != -1)
switch (ch) {
case 'a':
aflag = 1;
@ -156,6 +158,11 @@ main(argc, argv)
putenv("BLOCKSIZE=1k");
hflag = 0;
break;
case 'l':
if (vfslist != NULL)
errx(1, "-l and -t are mutually exclusive.");
vfslist = makevfslist(makenetvfslist());
break;
case 'm':
putenv("BLOCKSIZE=1m");
hflag = 0;
@ -507,6 +514,52 @@ usage()
{
(void)fprintf(stderr,
"usage: df [-b | -H | -h | -k | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
"usage: df [-b | -H | -h | -k | -m | -P] [-ailn] [-t type] [file | filesystem ...]\n");
exit(EX_USAGE);
}
char *makenetvfslist()
{
char *str, *strptr, **listptr;
int mib[3], maxvfsconf, miblen, cnt=0, i;
struct ovfsconf *ptr;
mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM;
miblen=sizeof(maxvfsconf);
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &maxvfsconf, &miblen, NULL, 0)) {
warnx("sysctl failed");
return (NULL);
}
if ((listptr=malloc(sizeof(char*) * maxvfsconf)) == NULL) {
warnx("malloc failed");
return (NULL);
}
for (ptr=getvfsent();ptr;ptr=getvfsent())
if (ptr->vfc_flags & VFCF_NETWORK) {
listptr[cnt++] = strdup (ptr->vfc_name);
if (! listptr[cnt-1]) {
warnx("malloc failed");
return (NULL);
}
}
if ((str = malloc(sizeof(char)*(32*cnt+cnt+2))) == NULL) {
warnx("malloc failed");
free(listptr);
return (NULL);
}
*str = 'n'; *(str+1) = 'o';
for (i = 0,strptr=str+2; i < cnt; i++,strptr++) {
strncpy (strptr, listptr[i], 32);
strptr+=strlen(listptr[i]);
*strptr=',';
free(listptr[i]);
}
*(--strptr) = NULL;
free(listptr);
return (str);
}