Print this page
7967 Want apparent size option for du(1)
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>

*** 17,38 **** * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ - #pragma ident "%Z%%M% %I% %E% SMI" - /* * du -- summarize disk usage ! * du [-dorx] [-a|-s] [-h|-k|-m] [-H|-L] [file...] */ #include <sys/types.h> #include <sys/stat.h> #include <sys/avl.h> --- 17,37 ---- * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* + * Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /* * du -- summarize disk usage ! * du [-Adorx] [-a|-s] [-h|-k|-m] [-H|-L] [file...] */ #include <sys/types.h> #include <sys/stat.h> #include <sys/avl.h>
*** 53,62 **** --- 52,62 ---- static int kflg = 0; static int mflg = 0; static int oflg = 0; static int dflg = 0; static int hflg = 0; + static int Aflg = 0; static int Hflg = 0; static int Lflg = 0; static int cmdarg = 0; /* Command line argument */ static char *dot = "."; static int level = 0; /* Level of recursion */
*** 68,78 **** #define NUMBER_WIDTH 64 typedef char numbuf_t[NUMBER_WIDTH]; /* ! * Output formats. Solaris uses a tab as separator, XPG4 a space. */ #ifdef XPG4 #define FORMAT1 "%s %s\n" #define FORMAT2 "%lld %s\n" #else --- 68,78 ---- #define NUMBER_WIDTH 64 typedef char numbuf_t[NUMBER_WIDTH]; /* ! * Output formats. illumos uses a tab as separator, XPG4 a space. */ #ifdef XPG4 #define FORMAT1 "%s %s\n" #define FORMAT2 "%lld %s\n" #else
*** 115,125 **** #ifdef XPG4 rflg++; /* "-r" is not an option but ON always */ #endif ! while ((c = getopt(argc, argv, "adhHkLmorsx")) != EOF) switch (c) { case 'a': aflg++; continue; --- 115,125 ---- #ifdef XPG4 rflg++; /* "-r" is not an option but ON always */ #endif ! while ((c = getopt(argc, argv, "aAdhHkLmorsx")) != EOF) switch (c) { case 'a': aflg++; continue;
*** 160,169 **** --- 160,173 ---- case 'x': dflg++; continue; + case 'A': + Aflg++; + continue; + case 'H': Hflg++; /* -H and -L are mutually exclusive */ Lflg = 0; cmdarg++;
*** 175,185 **** Hflg = 0; cmdarg = 0; continue; case '?': (void) fprintf(stderr, gettext( ! "usage: du [-dorx] [-a|-s] [-h|-k|-m] [-H|-L] " "[file...]\n")); exit(2); } if (optind == argc) { argv = &dot; --- 179,189 ---- Hflg = 0; cmdarg = 0; continue; case '?': (void) fprintf(stderr, gettext( ! "usage: du [-Adorx] [-a|-s] [-h|-k|-m] [-H|-L] " "[file...]\n")); exit(2); } if (optind == argc) { argv = &dot;
*** 377,387 **** } exitdu(1); } } } ! blocks = stb.st_blocks; /* * If there are extended attributes on the current file, add their * block usage onto the block count. Note: Since pathconf() always * follows symlinks, only test for extended attributes using pathconf() * if we are following symlinks or the current file is not a symlink. --- 381,392 ---- } exitdu(1); } } } ! blocks = Aflg ? stb.st_size : stb.st_blocks; ! /* * If there are extended attributes on the current file, add their * block usage onto the block count. Note: Since pathconf() always * follows symlinks, only test for extended attributes using pathconf() * if we are following symlinks or the current file is not a symlink.
*** 593,607 **** } static void printsize(blkcnt_t blocks, char *path) { if (hflg) { numbuf_t numbuf; unsigned long long scale = 1024L; (void) printf(FORMAT1, ! number_to_scaled_string(numbuf, blocks, DEV_BSIZE, scale), path); } else if (kflg) { (void) printf(FORMAT2, (long long)kb(blocks), path); } else if (mflg) { (void) printf(FORMAT2, (long long)mb(blocks), path); --- 598,616 ---- } static void printsize(blkcnt_t blocks, char *path) { + u_longlong_t bsize; + + bsize = Aflg ? 1 : DEV_BSIZE; + if (hflg) { numbuf_t numbuf; unsigned long long scale = 1024L; (void) printf(FORMAT1, ! number_to_scaled_string(numbuf, blocks, bsize, scale), path); } else if (kflg) { (void) printf(FORMAT2, (long long)kb(blocks), path); } else if (mflg) { (void) printf(FORMAT2, (long long)mb(blocks), path);