Maybe the manpage text could be better, but i'll leave that to jmc@

ok benno@

David Goerger([email protected]) on 2020.01.26 11:59:33 -0500:
> This diff teaches du(1) the -m flag, report disk usage in megabytes. 
> This brings us in line with implementations in the other BSDs, Linux, 
> and Illumos.
> 
> Other base utilities where this flag might be useful include df(1)
> and quot(8), although it doesn't appear to be universally adopted
> among the other implementations. That said I can definitely cook
> up a diff if others would find the flag useful elsewhere. In
> particular I think the flag would be useful in quot(8), but that
> tool has an unfortunate legacy, discouraged option "-h" which
> conflicts with -k/-m/-h semantics elsewhere in base, such that
> adding "-m" to quot(8) might only invite confusion.
> 
> Many thanks to florian@ for a first-pass review on bsd.network, and
> for encouraging me to check out what the other BSDs and utilities in
> base do, so that we maintain consistency across the ecosystem.
> 
> This is my first patch submission---any pointers for improvement would 
> be greatly appreciated! Thanks!
> 
> (diff below and also attached as "du-megabytes.diff" in case my mail
> client mangles formatting; hopefully I got this right!)
> 
> ---
> 
> Index: du.1
> ===================================================================
> RCS file: /cvs/src/usr.bin/du/du.1,v
> retrieving revision 1.35
> diff -u -p -r1.35 du.1
> --- du.1      2 Sep 2019 21:18:41 -0000       1.35
> +++ du.1      25 Jan 2020 20:52:11 -0000
> @@ -38,7 +38,7 @@
>  .Nd display disk usage statistics
>  .Sh SYNOPSIS
>  .Nm du
> -.Op Fl achkrsx
> +.Op Fl achkmrsx
>  .Op Fl H | L | P
>  .Op Fl d Ar depth
>  .Op Ar
> @@ -86,6 +86,10 @@ By default, all sizes are reported in 51
>  The
>  .Fl k
>  option causes the numbers to be reported in kilobyte counts.
> +.It Fl m
> +Similar to
> +.Fl k ,
> +but report disk usage in megabytes.
>  .It Fl L
>  All symbolic links are followed.
>  .It Fl P
> Index: du.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/du/du.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 du.c
> --- du.c      24 Aug 2016 03:13:45 -0000      1.32
> +++ du.c      25 Jan 2020 20:52:31 -0000
> @@ -61,7 +61,7 @@ main(int argc, char *argv[])
>       long blocksize;
>       int64_t totalblocks;
>       int ftsoptions, listfiles, maxdepth;
> -     int Hflag, Lflag, cflag, hflag, kflag;
> +     int Hflag, Lflag, cflag, hflag, kflag, mflag;
>       int ch, notused, rval;
>       char **save;
>       const char *errstr;
> @@ -70,11 +70,11 @@ main(int argc, char *argv[])
>               err(1, "pledge");
> 
>       save = argv;
> -     Hflag = Lflag = cflag = hflag = kflag = listfiles = 0;
> +     Hflag = Lflag = cflag = hflag = kflag = listfiles = mflag = 0;
>       totalblocks = 0;
>       ftsoptions = FTS_PHYSICAL;
>       maxdepth = -1;
> -     while ((ch = getopt(argc, argv, "HLPacd:hkrsx")) != -1)
> +     while ((ch = getopt(argc, argv, "HLPacd:hkmrsx")) != -1)
>               switch (ch) {
>               case 'H':
>                       Hflag = 1;
> @@ -103,10 +103,17 @@ main(int argc, char *argv[])
>               case 'h':
>                       hflag = 1;
>                       kflag = 0;
> +                     mflag = 0;
>                       break;
>               case 'k':
>                       kflag = 1;
>                       hflag = 0;
> +                     mflag = 0;
> +                     break;
> +             case 'm':
> +                     kflag = 0;
> +                     hflag = 0;
> +                     mflag = 1;
>                       break;
>               case 's':
>                       maxdepth = 0;
> @@ -155,6 +162,8 @@ main(int argc, char *argv[])
>               blocksize = 512;
>       else if (kflag)
>               blocksize = 1024;
> +     else if (mflag)
> +             blocksize = 1048576;
>       else
>               (void)getbsize(&notused, &blocksize);
>       blocksize /= 512;
> @@ -320,6 +329,6 @@ usage(void)
>  {
> 
>       (void)fprintf(stderr,
> -         "usage: du [-achkrsx] [-H | -L | -P] [-d depth] [file ...]\n");
> +         "usage: du [-achkmrsx] [-H | -L | -P] [-d depth] [file ...]\n");
>       exit(1);
>  }

> Index: du.1
> ===================================================================
> RCS file: /cvs/src/usr.bin/du/du.1,v
> retrieving revision 1.35
> diff -u -p -r1.35 du.1
> --- du.1      2 Sep 2019 21:18:41 -0000       1.35
> +++ du.1      25 Jan 2020 20:52:11 -0000
> @@ -38,7 +38,7 @@
>  .Nd display disk usage statistics
>  .Sh SYNOPSIS
>  .Nm du
> -.Op Fl achkrsx
> +.Op Fl achkmrsx
>  .Op Fl H | L | P
>  .Op Fl d Ar depth
>  .Op Ar
> @@ -86,6 +86,10 @@ By default, all sizes are reported in 51
>  The
>  .Fl k
>  option causes the numbers to be reported in kilobyte counts.
> +.It Fl m
> +Similar to
> +.Fl k ,
> +but report disk usage in megabytes.
>  .It Fl L
>  All symbolic links are followed.
>  .It Fl P
> Index: du.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/du/du.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 du.c
> --- du.c      24 Aug 2016 03:13:45 -0000      1.32
> +++ du.c      25 Jan 2020 20:52:31 -0000
> @@ -61,7 +61,7 @@ main(int argc, char *argv[])
>       long blocksize;
>       int64_t totalblocks;
>       int ftsoptions, listfiles, maxdepth;
> -     int Hflag, Lflag, cflag, hflag, kflag;
> +     int Hflag, Lflag, cflag, hflag, kflag, mflag;
>       int ch, notused, rval;
>       char **save;
>       const char *errstr;
> @@ -70,11 +70,11 @@ main(int argc, char *argv[])
>               err(1, "pledge");
>  
>       save = argv;
> -     Hflag = Lflag = cflag = hflag = kflag = listfiles = 0;
> +     Hflag = Lflag = cflag = hflag = kflag = listfiles = mflag = 0;
>       totalblocks = 0;
>       ftsoptions = FTS_PHYSICAL;
>       maxdepth = -1;
> -     while ((ch = getopt(argc, argv, "HLPacd:hkrsx")) != -1)
> +     while ((ch = getopt(argc, argv, "HLPacd:hkmrsx")) != -1)
>               switch (ch) {
>               case 'H':
>                       Hflag = 1;
> @@ -103,10 +103,17 @@ main(int argc, char *argv[])
>               case 'h':
>                       hflag = 1;
>                       kflag = 0;
> +                     mflag = 0;
>                       break;
>               case 'k':
>                       kflag = 1;
>                       hflag = 0;
> +                     mflag = 0;
> +                     break;
> +             case 'm':
> +                     kflag = 0;
> +                     hflag = 0;
> +                     mflag = 1;
>                       break;
>               case 's':
>                       maxdepth = 0;
> @@ -155,6 +162,8 @@ main(int argc, char *argv[])
>               blocksize = 512;
>       else if (kflag)
>               blocksize = 1024;
> +     else if (mflag)
> +             blocksize = 1048576;
>       else
>               (void)getbsize(&notused, &blocksize);
>       blocksize /= 512;
> @@ -320,6 +329,6 @@ usage(void)
>  {
>  
>       (void)fprintf(stderr,
> -         "usage: du [-achkrsx] [-H | -L | -P] [-d depth] [file ...]\n");
> +         "usage: du [-achkmrsx] [-H | -L | -P] [-d depth] [file ...]\n");
>       exit(1);
>  }

Reply via email to