* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)du.c 5.17 (Berkeley) 5/20/92";
void err
__P((const char *, ...));
char *getbsize
__P((char *, int *, long *));
int linkchk
__P((FTSENT
*));
register int listdirs
, listfiles
;
int aflag
, ch
, ftsoptions
, notused
, sflag
;
ftsoptions
= FTS_PHYSICAL
;
aflag
= kflag
= sflag
= 0;
while ((ch
= getopt(argc
, argv
, "aksx")) != EOF
)
listdirs
= listfiles
= 1;
listdirs
= listfiles
= 0;
(void)getbsize("du", ¬used
, &blocksize
);
if ((fts
= fts_open(argv
, ftsoptions
, NULL
)) == NULL
)
err("%s", strerror(errno
));
while (p
= fts_read(fts
))
p
->fts_parent
->fts_number
+=
p
->fts_number
+= p
->fts_statp
->st_blocks
;
* If listing each directory, or not listing files
* or directories and this is post-order of the
* root of a traversal, display the total.
if (listdirs
|| !listfiles
&& !p
->fts_level
)
(void)printf("%ld\t%s\n",
howmany(p
->fts_number
, blocksize
),
"du: %s: %s\n", p
->fts_path
, strerror(errno
));
if (p
->fts_level
== FTS_ROOTLEVEL
) {
(void)fts_set(fts
, p
, FTS_FOLLOW
);
if (p
->fts_statp
->st_nlink
> 1 && linkchk(p
))
* If listing each file, or a non-directory file was
* the root of a traversal, display the total.
if (listfiles
|| !p
->fts_level
)
(void)printf("%ld\t%s\n",
howmany(p
->fts_statp
->st_blocks
, blocksize
),
p
->fts_parent
->fts_number
+= p
->fts_statp
->st_blocks
;
err("%s", strerror(errno
));
static int maxfiles
, nfiles
;
ino
= p
->fts_statp
->st_ino
;
dev
= p
->fts_statp
->st_dev
;
for (fp
= start
+ nfiles
- 1; fp
>= start
; --fp
)
if (ino
== fp
->inode
&& dev
== fp
->dev
)
if (nfiles
== maxfiles
&& (files
= realloc((char *)files
,
(u_int
)(sizeof(ID
) * (maxfiles
+= 128)))) == NULL
)
err("%s", strerror(errno
));
files
[nfiles
].inode
= ino
;
(void)fprintf(stderr
, "usage: du [-a | -s] [-x] [file ...]\n");
err(const char *fmt
, ...)
(void)fprintf(stderr
, "du: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");