Subject: bin/11849: patch to add megabyte option to df
To: None <gnats-bugs@gnats.netbsd.org>
From: Chris Pinnock <C.J.E.Pinnock@qmw.ac.uk>
List: netbsd-bugs
Date: 12/30/2000 07:55:18
>Number:         11849
>Category:       bin
>Synopsis:       patch to add megabyte option to df
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Dec 30 07:55:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Chris Pinnock
>Release:        NetBSD-1.5
>Organization:
School of Mathematical Sciences, QM, Uni of LONDON, UK
>Environment:

System: NetBSD sylow.maths.qmw.ac.uk 1.5.1_ALPHA NetBSD 1.5.1_ALPHA (SYLOW) #6: Fri Dec 22 10:20:35 GMT 2000 cjep@sylow.maths.qmw.ac.uk:/usr/src/sys/arch/i386/compile/SYLOW i386


>Description:
	The following patch adds a -m option to df, to give output in
        megabytes rather than the default size or BLOCKSIZE.
 
        The patch includes changes to the manual page. This is against
        NetBSD-1.5.

diff -r -u -N /usr/src/bin/df/df.1 df/df.1
--- /usr/src/bin/df/df.1	Mon Mar 22 18:30:44 1999
+++ df/df.1	Thu Dec 21 22:14:09 2000
@@ -41,7 +41,7 @@
 .Nd display free disk space
 .Sh SYNOPSIS
 .Nm
-.Op Fl ikln
+.Op Fl iklmn
 .Op Fl t Ar type
 .Op Ar file | Ar file_system ...
 .Sh DESCRIPTION
@@ -77,6 +77,10 @@
 The
 .Fl k
 option causes the numbers to be reported in kilobyte counts.
+.It Fl m
+The 
+.Fl m
+option causes the numbers to be reported in megabyte 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
@@ -109,7 +113,9 @@
 .Ev BLOCKSIZE
 is set, and the
 .Fl k
-option is not specified, the block counts will be displayed in units of that
+and
+.Fl m
+options are not specified, the block counts will be displayed in units of that
 size block.
 .El
 .Sh SEE ALSO
diff -r -u -N /usr/src/bin/df/df.c df/df.c
--- /usr/src/bin/df/df.c	Fri Sep 24 14:35:21 1999
+++ df/df.c	Sat Dec 23 19:13:52 2000
@@ -79,7 +79,7 @@
 long	 regetmntinfo __P((struct statfs **, long));
 void	 usage __P((void));
 
-int	iflag, kflag, lflag, nflag;
+int	iflag, kflag, lflag, mflag, nflag;
 char	**typelist = NULL;
 struct	ufs_args mdev;
 
@@ -94,7 +94,7 @@
 	int ch, i, maxwidth, width;
 	char *mntpt;
 
-	while ((ch = getopt(argc, argv, "iklnt:")) != -1)
+	while ((ch = getopt(argc, argv, "iklmnt:")) != -1)
 		switch (ch) {
 		case 'i':
 			iflag = 1;
@@ -105,6 +105,9 @@
 		case 'l':
 			lflag = 1;
 			break;
+		case 'm':
+			mflag = 1;
+			break;
 		case 'n':
 			nflag = 1;
 			break;
@@ -343,7 +346,13 @@
 			header = "1K-blocks";
 			headerlen = strlen(header);
 		} else
+		if (mflag) {
+			blocksize = 1048576;
+			header = "1M-blocks";
+			headerlen = strlen(header);
+		} else
 			header = getbsize(&headerlen, &blocksize);
+		
 		(void)printf("%-*.*s %s     Used    Avail Capacity",
 		    maxwidth, maxwidth, "Filesystem", header);
 		if (iflag)
@@ -451,7 +460,7 @@
 void
 usage()
 {
-	(void)fprintf(stderr, "usage: df [-ikln] [-t type] [file | file_system ...]\n");
+	(void)fprintf(stderr, "usage: df [-iklmn] [-t type] [file | file_system ...]\n");
 	exit(1);
 	/* NOTREACHED */
 }



>How-To-Repeat:
	.
>Fix:
	.

>Release-Note:
>Audit-Trail:
>Unformatted: