From nobody@FreeBSD.org  Wed Sep  4 15:19:55 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 633A737B400
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  4 Sep 2002 15:19:55 -0700 (PDT)
Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 17D2043E6A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  4 Sep 2002 15:19:55 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g84MJsOT099191
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 4 Sep 2002 15:19:54 -0700 (PDT)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.4/8.12.4/Submit) id g84MJsxW099190;
	Wed, 4 Sep 2002 15:19:54 -0700 (PDT)
Message-Id: <200209042219.g84MJsxW099190@www.freebsd.org>
Date: Wed, 4 Sep 2002 15:19:54 -0700 (PDT)
From: Fork <bouloumag@hotmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Add -m option to du(1) for compatibility to GNU [PATCH]
X-Send-Pr-Version: www-1.0

>Number:         42430
>Category:       bin
>Synopsis:       Add -m option to du(1) for compatibility to GNU [PATCH]
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 04 15:20:02 PDT 2002
>Closed-Date:    Sun Jul 18 08:00:50 GMT 2004
>Last-Modified:  Sun Jul 18 08:00:50 GMT 2004
>Originator:     Fork
>Release:        FreeBSD 4.6.2-RELEASE
>Organization:
>Environment:
FreeBSD asterix.local.qc 4.6.2-RELEASE FreeBSD 4.6.2-RELEASE #1: Tue Sep  3 00:25:58 EDT 2002 gaudrs@asterix.local.qc:/usr/obj/usr/src/sys/ASTERIX  i386   
>Description:
I have somes problem to port a script from our RedHat server to our new FreeBSD server. The problem is that FreeBSD does not have a -m option in the du(1) command. Since the same script will run the two plateforme, I need a -m option in FreeBSD.

The GNU version of du(1) had a -m option that display block counts in 1048576-byte (1-Mbyte) blocks. This is equivalent to set BLOCKSIZE=1048576.
>How-To-Repeat:
      
>Fix:
The following patch (against  4.6.2-RELEASE) add the -m option to du(1) :

 diff -crN du.orig/du.1 du/du.1
*** du.orig/du.1	Wed Sep  4 18:06:28 2002
--- du/du.1	Wed Sep  4 18:02:45 2002
***************
*** 44,50 ****
  .Op Fl I Ar mask
  .Op Fl a | s | d Ar depth
  .Op Fl c
! .Op Fl h | k
  .Op Fl x
  .Op Ar
  .Sh DESCRIPTION
--- 44,50 ----
  .Op Fl I Ar mask
  .Op Fl a | s | d Ar depth
  .Op Fl c
! .Op Fl h | k | m
  .Op Fl x
  .Op Ar
  .Sh DESCRIPTION
***************
*** 98,103 ****
--- 98,105 ----
  Display a grand total.
  .It Fl k
  Display block counts in 1024-byte (1-Kbyte) blocks.
+ .It Fl m
+ Display block counts in 1048576-byte (1-Mbyte) blocks.
  .It Fl x
  Filesystem mount points are not traversed.
  .El
***************
*** 125,140 ****
  .It Ev BLOCKSIZE
  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
! size block.
! If
  .Ev BLOCKSIZE
! is not set, and the
! .Fl k
! option is not specified, the block counts will be displayed in 512-byte blocks.
! .El
  .Sh SEE ALSO
  .Xr df 1 ,
  .Xr fts 3 ,
--- 127,143 ----
  .It Ev BLOCKSIZE
  If the environment variable
  .Ev BLOCKSIZE
! is set the block counts will be displayed in units of that
! size block, unless the 
  .Fl k
! , 
! .Fl m 
! or 
! .Fl h 
! option is specified.
! If 
  .Ev BLOCKSIZE
! is not set, and the previous options are not specified, the block counts will be displayed in 512-byte blocks.
  .Sh SEE ALSO
  .Xr df 1 ,
  .Xr fts 3 ,
diff -crN du.orig/du.c du/du.c
*** du.orig/du.c	Wed Sep  4 18:06:28 2002
--- du/du.c	Wed Sep  4 17:50:49 2002
***************
*** 125,131 ****
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  	
! 	while ((ch = getopt(argc, argv, "HI:LPasd:chkrx")) != -1)
  		switch (ch) {
  			case 'H':
  				Hflag = 1;
--- 125,131 ----
  	depth = INT_MAX;
  	SLIST_INIT(&ignores);
  	
! 	while ((ch = getopt(argc, argv, "HI:LPasd:chkmrx")) != -1)
  		switch (ch) {
  			case 'H':
  				Hflag = 1;
***************
*** 169,174 ****
--- 169,177 ----
  			case 'k':
  				putenv("BLOCKSIZE=1024");
  				break;
+ 		        case 'm':                /* Compatibility with GNU */
+ 			        putenv("BLOCKSIZE=1048576");
+ 				break;
  			case 'r':		 /* Compatibility. */
  				break;
  			case 'x':
***************
*** 390,396 ****
  usage()
  {
  	(void)fprintf(stderr,
! 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k] [-x] [-I mask] [file ...]\n");
  	exit(EX_USAGE);
  }
  
--- 393,399 ----
  usage()
  {
  	(void)fprintf(stderr,
! 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-x] [-I mask] [file ...]\n");
  	exit(EX_USAGE);
  }
  
  
>Release-Note:
>Audit-Trail:

From: "fork __" <bouloumag@hotmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/42430: Add -m option to du(1) for compatibility to GNU [PATCH]
Date: Thu, 05 Sep 2002 05:35:34 +0000

 Hi,
 	I think that the version is more clean. I had remove the putenv call, and 
 replace it by the use of the "blocksize" variable.
 
 	Also, I had do some cleanout on the manpage (sorry, my english is a little 
 poor ... )
 
 	Anyway, this is the new patch against FreeBSD 4.6.2-RELEASE
 
 -=========================================-
 
 diff -crN du.orig/du.1 du/du.1
 *** du.orig/du.1	Thu Sep  5 00:35:41 2002
 --- du/du.1	Thu Sep  5 01:24:54 2002
 ***************
 *** 44,50 ****
   .Op Fl I Ar mask
   .Op Fl a | s | d Ar depth
   .Op Fl c
 ! .Op Fl h | k
   .Op Fl x
   .Op Ar
   .Sh DESCRIPTION
 --- 44,50 ----
   .Op Fl I Ar mask
   .Op Fl a | s | d Ar depth
   .Op Fl c
 ! .Op Fl h | k | m
   .Op Fl x
   .Op Ar
   .Sh DESCRIPTION
 ***************
 *** 55,66 ****
   argument.
   If no file is specified, the block usage of the hierarchy rooted in
   the current directory is displayed.
   If the
   .Fl k
 ! flag is specified, the number of 1024-byte
 ! blocks used by the file is displayed, otherwise
 ! .Xr getbsize 3
 ! is used to determine the preferred block size.
   Partial numbers of blocks are rounded up.
   .Pp
   The options are as follows:
 --- 55,71 ----
   argument.
   If no file is specified, the block usage of the hierarchy rooted in
   the current directory is displayed.
 + By default, the preferred block size is determined by the value
 + returned by the
 + .Xr getbsize 3
 + system call, i.e., 512-byte blocks.
   If the
   .Fl k
 ! flag is specified, the number displayed is the number of 1024-byte
 ! blocks. By the same way, if the
 ! .Fl m
 ! flag is specified, the number displayed is the number of 1048576-byte
 ! blocks.
   Partial numbers of blocks are rounded up.
   .Pp
   The options are as follows:
 ***************
 *** 79,86 ****
   .It Fl a
   Display an entry for each file in a file hierarchy.
   .It Fl h
 ! "Human-readable" output.  Use unit suffixes: Byte, Kilobyte, Megabyte,
 ! Gigabyte, Terabyte and Petabyte
   .It Fl r
   Generate messages about directories that cannot be read, files
   that cannot be opened, and so on.  This is the default case.
 --- 84,92 ----
   .It Fl a
   Display an entry for each file in a file hierarchy.
   .It Fl h
 ! Display numbers in a human readable form.
 ! Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte in order 
 to
 ! reduce the number of digits to four or less.
   .It Fl r
   Generate messages about directories that cannot be read, files
   that cannot be opened, and so on.  This is the default case.
 ***************
 *** 98,103 ****
 --- 104,111 ----
   Display a grand total.
   .It Fl k
   Display block counts in 1024-byte (1-Kbyte) blocks.
 + .It Fl m
 + Display block counts in 1048576-byte (1-Mbyte) blocks.
   .It Fl x
   Filesystem mount points are not traversed.
   .El
 ***************
 *** 123,140 ****
   .Sh ENVIRONMENT
   .Bl -tag -width BLOCKSIZE
   .It Ev BLOCKSIZE
 ! 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
 ! size block.
 ! If
 ! .Ev BLOCKSIZE
 ! is not set, and the
   .Fl k
 ! option is not specified, the block counts will be displayed in 512-byte 
 blocks.
 ! .El
   .Sh SEE ALSO
   .Xr df 1 ,
   .Xr fts 3 ,
 --- 131,143 ----
   .Sh ENVIRONMENT
   .Bl -tag -width BLOCKSIZE
   .It Ev BLOCKSIZE
 ! Block counts will be displayed in units of this size block, unless the
   .Fl k
 ! , the
 ! .Fl m
 ! or
 ! .Fl h
 ! option is specified.
   .Sh SEE ALSO
   .Xr df 1 ,
   .Xr fts 3 ,
 diff -crN du.orig/du.c du/du.c
 *** du.orig/du.c	Thu Sep  5 00:35:41 2002
 --- du/du.c	Thu Sep  5 01:06:18 2002
 ***************
 *** 115,131 ****
   	int		ftsoptions;
   	int		listall;
   	int		depth;
 ! 	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, 
 rval;
   	char 		**save;
 
 ! 	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
 
   	save = argv;
   	ftsoptions = 0;
   	depth = INT_MAX;
   	SLIST_INIT(&ignores);
 
 ! 	while ((ch = getopt(argc, argv, "HI:LPasd:chkrx")) != -1)
   		switch (ch) {
   			case 'H':
   				Hflag = 1;
 --- 115,131 ----
   	int		ftsoptions;
   	int		listall;
   	int		depth;
 ! 	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, mflag, 
 kflag, ch, notused, rval;
   	char 		**save;
 
 ! 	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = mflag = 
 kflag = 0;
 
   	save = argv;
   	ftsoptions = 0;
   	depth = INT_MAX;
   	SLIST_INIT(&ignores);
 
 ! 	while ((ch = getopt(argc, argv, "HI:LPasd:chkmrx")) != -1)
   		switch (ch) {
   			case 'H':
   				Hflag = 1;
 ***************
 *** 161,173 ****
   			case 'c':
   				cflag = 1;
   				break;
 ! 			case 'h':
 ! 				putenv("BLOCKSIZE=512");
   				hflag = 1;
   				valp = vals_base2;
   				break;
   			case 'k':
 ! 				putenv("BLOCKSIZE=1024");
   				break;
   			case 'r':		 /* Compatibility. */
   				break;
 --- 161,175 ----
   			case 'c':
   				cflag = 1;
   				break;
 ! 			case 'h':
   				hflag = 1;
   				valp = vals_base2;
   				break;
   			case 'k':
 ! 			        kflag = 1;
 ! 				break;
 ! 		        case 'm':                /* Compatibility with GNU */
 ! 			        mflag = 1;
   				break;
   			case 'r':		 /* Compatibility. */
   				break;
 ***************
 *** 228,234 ****
   		argv[1] = NULL;
   	}
 
 ! 	(void) getbsize(&notused, &blocksize);
   	blocksize /= 512;
 
   	rval = 0;
 --- 230,243 ----
   		argv[1] = NULL;
   	}
 
 ! 	if (hflag)
 ! 	        blocksize = 512;
 ! 	else if (kflag)
 ! 	        blocksize = 1024;
 ! 	else if (mflag)
 ! 	        blocksize = 1048576;
 ! 	else
 ! 	        (void)getbsize(&notused, &blocksize);
   	blocksize /= 512;
 
   	rval = 0;
 ***************
 *** 390,396 ****
   usage()
   {
   	(void)fprintf(stderr,
 ! 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k] [-x] [-I 
 mask] [file ...]\n");
   	exit(EX_USAGE);
   }
 
 --- 399,405 ----
   usage()
   {
   	(void)fprintf(stderr,
 ! 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-x] 
 [-I mask] [file ...]\n");
   	exit(EX_USAGE);
   }
 
 
 
 _________________________________________________________________
 Affichez, modifiez et partagez gratuitement vos photos en ligne: 
 http://photos.msn.com/support/worldwide.aspx
 
State-Changed-From-To: open->closed 
State-Changed-By: maxim 
State-Changed-When: Sun Jul 18 07:59:29 GMT 2004 
State-Changed-Why:  
-m flag for du(1) was implemented in -CURRENT in a result of work 
on bin/66976.  Thanks to the sumbission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42430 
>Unformatted:
