Bug 42430

Summary: Add -m option to du(1) for compatibility to GNU [PATCH]
Product: Base System Reporter: Fork <bouloumag>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.6.2-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Fork 2002-09-04 23:20:02 UTC
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.

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
Comment 1 Fork 2002-09-05 06:35:34 UTC
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
Comment 2 Maxim Konovalov freebsd_committer freebsd_triage 2004-07-18 08:59:29 UTC
State Changed
From-To: open->closed

-m flag for du(1) was implemented in -CURRENT in a result of work 
on bin/66976.  Thanks to the sumbission!