summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
authorDale Ghent <daleg@omniti.com>2017-03-14 04:45:10 +0000
committerDan McDonald <danmcd@omniti.com>2017-03-15 15:31:16 -0400
commit8aaea06ac924e217626f879f326b781e9780f7d7 (patch)
tree075e0d12d49f89f2db1ba56bbdc713f0995b2b2b /usr/src
parent411be58a6e030a3b606f1afcc7f2e2459ffda844 (diff)
downloadillumos-joyent-8aaea06ac924e217626f879f326b781e9780f7d7.tar.gz
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> Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/du/du.c25
-rw-r--r--usr/src/man/man1/du.143
2 files changed, 35 insertions, 33 deletions
diff --git a/usr/src/cmd/du/du.c b/usr/src/cmd/du/du.c
index 4307eadf8a..3911135b50 100644
--- a/usr/src/cmd/du/du.c
+++ b/usr/src/cmd/du/du.c
@@ -19,6 +19,7 @@
* 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.
*/
@@ -26,11 +27,9 @@
/* 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>
@@ -55,6 +54,7 @@ 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 */
@@ -70,7 +70,7 @@ static size_t name_len = PATH_MAX + 1; /* # of chars for name */
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"
@@ -117,7 +117,7 @@ main(int argc, char **argv)
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':
@@ -162,6 +162,10 @@ main(int argc, char **argv)
dflg++;
continue;
+ case 'A':
+ Aflg++;
+ continue;
+
case 'H':
Hflg++;
/* -H and -L are mutually exclusive */
@@ -177,7 +181,7 @@ main(int argc, char **argv)
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);
}
@@ -379,7 +383,8 @@ descend(char *curname, int curfd, int *retcode, dev_t device)
}
}
}
- 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
@@ -595,11 +600,15 @@ number_to_scaled_string(
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);
diff --git a/usr/src/man/man1/du.1 b/usr/src/man/man1/du.1
index 05820b1bb6..079ec4a86d 100644
--- a/usr/src/man/man1/du.1
+++ b/usr/src/man/man1/du.1
@@ -1,6 +1,7 @@
'\" te
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
.\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
+.\" Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved.
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
@@ -8,24 +9,23 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH DU 1 "Feb 6, 2007"
+.TH DU 1 "March 14, 2017"
.SH NAME
du \- summarize disk usage
.SH SYNOPSIS
.LP
.nf
-\fB/usr/bin/du\fR [\fB-dorx\fR] [\fB-a\fR | \fB-s\fR] [\fB-h\fR | \fB-k\fR | \fB-m\fR] [\fB-H\fR | \fB-L\fR]
+\fB/usr/bin/du\fR [\fB-Adorx\fR] [\fB-a\fR | \fB-s\fR] [\fB-h\fR | \fB-k\fR | \fB-m\fR] [\fB-H\fR | \fB-L\fR]
[\fIfile\fR ...]
.fi
.LP
.nf
-\fB/usr/xpg4/bin/du\fR [\fB-dorx\fR] [\fB-a\fR | \fB-s\fR] [\fB-h\fR | \fB-k\fR | \fB-m\fR] [\fB-H\fR | \fB-L\fR]
+\fB/usr/xpg4/bin/du\fR [\fB-Adorx\fR] [\fB-a\fR | \fB-s\fR] [\fB-h\fR | \fB-k\fR | \fB-m\fR] [\fB-H\fR | \fB-L\fR]
[\fIfile\fR ...]
.fi
.SH DESCRIPTION
-.sp
.LP
The \fBdu\fR utility writes to standard output the size of the file space
allocated to, and the size of the file space allocated to each subdirectory of,
@@ -34,19 +34,16 @@ space allocated to a file of type directory is defined as the sum total of
space allocated to all files in the file hierarchy rooted in the directory plus
the space allocated to the directory itself. This sum will include the space
allocated to any extended attributes encountered.
-.sp
.LP
Files with multiple links will be counted and written for only one entry. The
directory entry that is selected in the report is unspecified. By default, file
sizes are written in 512-byte units, rounded up to the next 512-byte unit.
.SS "/usr/xpg4/bin/du"
-.sp
.LP
When \fBdu\fR cannot obtain file attributes or read directories (see
\fBstat\fR(2)), it will report an error condition and the final exit status
will be affected.
.SH OPTIONS
-.sp
.LP
The following options are supported for \fB/usr/bin/du\fR and
\fB/usr/xpg4/bin/du\fR:
@@ -65,6 +62,17 @@ will always be listed.
.sp
.ne 2
.na
+\fB\fB-A\fR\fR
+.ad
+.RS 6n
+Tally file size using the apparent size of the file instead of the disk blocks
+it occupies. This option is useful when operating on file systems which employ
+compression or in the presence of sparse files.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fB-d\fR\fR
.ad
.RS 6n
@@ -179,7 +187,6 @@ Specifying more than one of the options in the mutually exclusive set of
options \fB-h\fR, \fB-k\fR, and \fB-m\fR is not considered an error. The last
option specified determines the output format.
.SH OPERANDS
-.sp
.LP
The following operand is supported:
.sp
@@ -191,25 +198,20 @@ The following operand is supported:
The path name of a file whose size is to be written. If no \fIfile\fR is
specified, the current directory is used.
.RE
-
.SH OUTPUT
-.sp
.LP
The output from \fBdu\fR consists of the amount of the space allocated to a
file and the name of the file.
.SH USAGE
-.sp
.LP
See \fBlargefile\fR(5) for the description of the behavior of \fBdu\fR when
encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
.SH ENVIRONMENT VARIABLES
-.sp
.LP
See \fBenviron\fR(5) for descriptions of the following environment variables
that affect the execution of \fBdu\fR: \fBLANG\fR, \fBLC_ALL\fR,
\fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
.SH EXIT STATUS
-.sp
.LP
The following exit values are returned:
.sp
@@ -220,7 +222,6 @@ The following exit values are returned:
.RS 6n
Successful completion.
.RE
-
.sp
.ne 2
.na
@@ -229,15 +230,11 @@ Successful completion.
.RS 6n
An error occurred.
.RE
-
.SH ATTRIBUTES
-.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.SS "/usr/bin/du"
-.sp
-.sp
.TS
box;
c | c
@@ -250,9 +247,7 @@ Interface Stability Stable
.TE
.SS "/usr/xpg4/bin/du"
-.sp
-.sp
.TS
box;
c | c
@@ -265,20 +260,18 @@ Interface Stability Standard
.TE
.SH SEE ALSO
-.sp
.LP
\fBls\fR(1), \fBstat\fR(2), \fBattributes\fR(5), \fBenviron\fR(5),
\fBfsattr\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5)
-.sp
.LP
\fISystem Administration Guide: Basic Administration\fR
.SH NOTES
-.sp
.LP
A file with two or more links is counted only once. If, however, there are
links between files in different directories where the directories are on
separate branches of the file system hierarchy, \fBdu\fR will count the excess
files more than once.
-.sp
.LP
-Files containing holes will result in an incorrect block count.
+Files containing holes will result in an incorrect block count. In this case,
+one may use the \fB-A\fR option to report file sizes by their apparent size
+instead.