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,22 +17,21 @@
* 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 */
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* du -- summarize disk usage
- * du [-dorx] [-a|-s] [-h|-k|-m] [-H|-L] [file...]
+ * du [-Adorx] [-a|-s] [-h|-k|-m] [-H|-L] [file...]
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/avl.h>
@@ -53,10 +52,11 @@
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,11 +68,11 @@
#define NUMBER_WIDTH 64
typedef char numbuf_t[NUMBER_WIDTH];
/*
- * Output formats. Solaris uses a tab as separator, XPG4 a space.
+ * 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,11 +115,11 @@
#ifdef XPG4
rflg++; /* "-r" is not an option but ON always */
#endif
- while ((c = getopt(argc, argv, "adhHkLmorsx")) != EOF)
+ while ((c = getopt(argc, argv, "aAdhHkLmorsx")) != EOF)
switch (c) {
case 'a':
aflg++;
continue;
@@ -160,10 +160,14 @@
case 'x':
dflg++;
continue;
+ case 'A':
+ Aflg++;
+ continue;
+
case 'H':
Hflg++;
/* -H and -L are mutually exclusive */
Lflg = 0;
cmdarg++;
@@ -175,11 +179,11 @@
Hflg = 0;
cmdarg = 0;
continue;
case '?':
(void) fprintf(stderr, gettext(
- "usage: du [-dorx] [-a|-s] [-h|-k|-m] [-H|-L] "
+ "usage: du [-Adorx] [-a|-s] [-h|-k|-m] [-H|-L] "
"[file...]\n"));
exit(2);
}
if (optind == argc) {
argv = ˙
@@ -377,11 +381,12 @@
}
exitdu(1);
}
}
}
- blocks = stb.st_blocks;
+ 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,15 +598,19 @@
}
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, DEV_BSIZE, scale),
+ 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);