Subject: bin/11848: patch to add megabyte option to du
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:50:20
>Number:         11848
>Category:       bin
>Synopsis:       patch to add megabyte option to du
>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:50:01 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 du, to give output in
	megabytes rather than the default size or BLOCKSIZE. I have
	found it useful.

	The patch includes changes to the manual page. This is against
	NetBSD-1.5.

diff -r -u -N /usr/src/usr.bin/du/du.1 du/du.1
--- /usr/src/usr.bin/du/du.1	Sun Feb 15 17:08:17 1998
+++ du/du.1	Thu Dec 21 21:50:35 2000
@@ -43,7 +43,7 @@
 .Nm
 .Op Fl H | Fl L | Fl P
 .Op Fl a | Fl s
-.Op Fl ckrx
+.Op Fl ckmrx
 .Op Ar file ...
 .Sh DESCRIPTION
 The
@@ -73,9 +73,12 @@
 system call, i.e. 512-byte blocks.
 If the
 .Fl k
-flag is specified, the number displayed is the number of 1024-byte
-blocks.
-Partial numbers of blocks are rounded up.
+flag is specified, the number displayed is the number of kilobyte
+blocks. Partial numbers of blocks are rounded up.
+.It Fl m
+If the 
+.Fl m
+flag is specified, the number displayed is the number of megabyte blocks.
 .It Fl c
 Display the grand total after all the arguments have been processed.
 .It Fl r
@@ -118,8 +121,10 @@
 If the environment variable
 .Ev BLOCKSIZE
 is set, and the 
-.Fl k
-option is not specified, the block counts will be displayed in units of that
+.Fl k 
+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/usr.bin/du/du.c du/du.c
--- /usr/src/usr.bin/du/du.c	Sun Apr  2 13:46:04 2000
+++ du/du.c	Thu Dec 21 21:52:13 2000
@@ -75,14 +75,14 @@
 	FTSENT *p;
 	long blocksize, totalblocks;
 	int ftsoptions, listdirs, listfiles;
-	int Hflag, Lflag, Pflag, aflag, ch, cflag, kflag, notused, rval, sflag;
+	int Hflag, Lflag, Pflag, aflag, ch, cflag, kmflag, notused, rval, sflag;
 	char **save;
 
 	save = argv;
-	Hflag = Lflag = Pflag = aflag = cflag = kflag = sflag = 0;
+	Hflag = Lflag = Pflag = aflag = cflag = kmflag = sflag = 0;
 	totalblocks = 0;
 	ftsoptions = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "HLPackrsx")) != -1)
+	while ((ch = getopt(argc, argv, "HLPackmrsx")) != -1)
 		switch (ch) {
 		case 'H':
 			Hflag = 1;
@@ -104,8 +104,12 @@
 			break;
 		case 'k':
 			blocksize = 1024;
-			kflag = 1;
+			kmflag = 1;
 			break;
+		case 'm':
+			blocksize = 1048576;
+			kmflag = 1;
+			break; 
 		case 'r':
 			break;
 		case 's':
@@ -157,7 +161,7 @@
 		argv[1] = NULL;
 	}
 
-	if (!kflag)
+	if (!kmflag)
 		(void)getbsize(&notused, &blocksize);
 	blocksize /= 512;
 
@@ -250,6 +254,6 @@
 {
 
 	(void)fprintf(stderr,
-		"usage: du [-H | -L | -P] [-a | -s] [-ckrx] [file ...]\n");
+		"usage: du [-H | -L | -P] [-a | -s] [-ckmrx] [file ...]\n");
 	exit(1);
 }





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




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