Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 May 2001 11:30:02 -0700 (PDT)
From:      Peter Pentchev <roam@orbitel.bg>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/27240: df does not support '-l' option
Message-ID:  <200105101830.f4AIU2u37169@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/27240; it has been noted by GNATS.

From: Peter Pentchev <roam@orbitel.bg>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-bugs@FreeBSD.org
Subject: Re: bin/27240: df does not support '-l' option
Date: Thu, 10 May 2001 18:38:48 +0300

 On Thu, May 10, 2001 at 08:00:05AM -0700, Garrett Wollman wrote:
 > The following reply was made to PR bin/27240; it has been noted by GNATS.
 > 
 > From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
 > To: Jim.Pirzyk@disney.com
 > Cc: FreeBSD-gnats-submit@FreeBSD.ORG
 > Subject: bin/27240: df does not support '-l' option
 > Date: Thu, 10 May 2001 10:50:16 -0400 (EDT)
 > 
 >  <<On Wed, 9 May 2001 22:06:47 -0700 (PDT), Jim.Pirzyk@disney.com said:
 >  
 >  > + 		case 'l':
 >  > + 			if (vfslist != NULL)
 >  > + 				errx(1, "-l and -t are mutally exclusive.");
 >  > + 			vfslist = makevfslist("nonfs");
 >  > + 			break;
 >  
 >  Actually, that's not the right way to implement this function.  The
 >  correct way would be to scan the list of available filesystem types
 >  and look for ones without the VFCF_NETWORK flag.
 
 OK, how about the following patch - it just gets all filesystems, and then
 processes only those for which statfs(2) has set the MNT_LOCAL flag.
 
 G'luck,
 Peter
 
 -- 
 This sentence every third, but it still comprehensible.
 
 Index: src/bin/df/df.1
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.1,v
 retrieving revision 1.22
 diff -u -r1.22 df.1
 --- src/bin/df/df.1	2001/02/01 16:24:49	1.22
 +++ src/bin/df/df.1	2001/05/10 15:37:55
 @@ -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 @@
  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 @@
  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.
 Index: src/bin/df/df.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/df/df.c,v
 retrieving revision 1.26
 diff -u -r1.26 df.c
 --- src/bin/df/df.c	2001/05/09 08:44:15	1.26
 +++ src/bin/df/df.c	2001/05/10 15:37:56
 @@ -107,7 +107,7 @@
  unit_t	  unit_adjust __P((double *));
  void	  usage __P((void));
  
 -int	aflag = 0, hflag, iflag, nflag;
 +int	aflag, hflag, iflag, lflag, nflag;
  struct	ufs_args mdev;
  
  int
 @@ -124,7 +124,7 @@
  	fstype = "ufs";
  
  	vfslist = NULL;
 -	while ((ch = getopt(argc, argv, "abgHhikmnPt:")) != -1)
 +	while ((ch = getopt(argc, argv, "abgHhiklmnPt:")) != -1)
  		switch (ch) {
  		case 'a':
  			aflag = 1;
 @@ -154,6 +154,9 @@
  			putenv("BLOCKSIZE=1k");
  			hflag = 0;
  			break;
 +		case 'l':
 +			lflag = 1;
 +			break;
  		case 'm':
  			putenv("BLOCKSIZE=1m");
  			hflag = 0;
 @@ -188,12 +191,16 @@
  		if (vfslist != NULL) {
  			maxwidth = 0;
  			for (i = 0; i < mntsize; i++) {
 +				if (lflag && !(mntbuf[i].f_flags & MNT_LOCAL))
 +					continue;
  				width = strlen(mntbuf[i].f_mntfromname);
  				if (width > maxwidth)
  					maxwidth = width;
  			}
  		}
  		for (i = 0; i < mntsize; i++) {
 +			if (lflag && !(mntbuf[i].f_flags & MNT_LOCAL))
 +				continue;
  			if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
  				prtstat(&mntbuf[i], maxwidth);
  		}
 @@ -203,7 +210,7 @@
  	for (; *argv; argv++) {
  		if (stat(*argv, &stbuf) < 0) {
  			err = errno;
 -			if ((mntpt = getmntpt(*argv)) == 0) {
 +			if ((mntpt = getmntpt(*argv)) == NULL) {
  				warn("%s", *argv);
  				rv = 1;
  				continue;
 @@ -232,7 +239,9 @@
  					continue;
  				} else if (statfs(mntpt, &statfsbuf) == 0) {
  					statfsbuf.f_mntonname[0] = '\0';
 -					prtstat(&statfsbuf, maxwidth);
 +					if (!lflag ||
 +					    (statfsbuf.f_flags & MNT_LOCAL))
 +						prtstat(&statfsbuf, maxwidth);
  				} else {
  					warn("%s", *argv);
  					rv = 1;
 @@ -255,7 +264,8 @@
  		}
  		if (argc == 1)
  			maxwidth = strlen(statfsbuf.f_mntfromname) + 1;
 -		prtstat(&statfsbuf, maxwidth);
 +		if (!lflag || (statfsbuf.f_flags & MNT_LOCAL))
 +			prtstat(&statfsbuf, maxwidth);
  	}
  	return (rv);
  }
 @@ -289,12 +299,15 @@
  	int i, j;
  	struct statfs *mntbuf;
  
 -	if (vfslist == NULL)
 +	if (!lflag && (vfslist == NULL))
  		return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT));
  
  	mntbuf = *mntbufp;
  	for (j = 0, i = 0; i < mntsize; i++) {
 -		if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
 +		if (lflag && !(mntbuf[i].f_flags & MNT_LOCAL))
 +			continue;
 +		if ((vfslist != NULL) &&
 +		    checkvfsname(mntbuf[i].f_fstypename, vfslist))
  			continue;
  		if (!nflag)
  			(void)statfs(mntbuf[i].f_mntonname,&mntbuf[j]);
 @@ -462,7 +475,7 @@
  	sfsp = &statfsbuf;
  	sfsp->f_type = 1;
  	strcpy(sfsp->f_fstypename, "ufs");
 -	sfsp->f_flags = 0;
 +	sfsp->f_flags = MNT_LOCAL;
  	sfsp->f_bsize = sblock.fs_fsize;
  	sfsp->f_iosize = sblock.fs_bsize;
  	sfsp->f_blocks = sblock.fs_dsize;
 @@ -506,6 +519,6 @@
  {
  
  	(void)fprintf(stderr,
 -	    "usage: df [-b | -H | -h | -k | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
 +	    "usage: df [-b | -H | -h | -k | -l | -m | -P] [-ain] [-t type] [file | filesystem ...]\n");
  	exit(EX_USAGE);
  }

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105101830.f4AIU2u37169>