* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)du.c 5.10 (Berkeley) %G%";
register int kvalue
, listdirs
, listfiles
;
ftsoptions
= FTS_PHYSICAL
;
while ((ch
= getopt(argc
, argv
, "aksx")) != EOF
)
listfiles
= listdirs
= 0;
"usage: du [-aksx] [name ...]\n");
if (!(fts
= fts_open(argv
, ftsoptions
, (int (*)())NULL
))) {
(void)fprintf(stderr
, "du: %s.\n", strerror(errno
));
while (p
= fts_read(fts
))
p
->fts_parent
->fts_number
+=
p
->fts_number
+= p
->fts_statb
.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", kvalue
?
howmany(p
->fts_number
, 2) :
p
->fts_number
, p
->fts_path
);
"du: %s: %s.\n", p
->fts_path
, strerror(errno
));
if (p
->fts_statb
.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", kvalue
?
howmany(p
->fts_statb
.st_blocks
, 2) :
p
->fts_statb
.st_blocks
, p
->fts_path
);
p
->fts_parent
->fts_number
+= p
->fts_statb
.st_blocks
;
static int maxfiles
, nfiles
;
ino
= p
->fts_statb
.st_ino
;
dev
= p
->fts_statb
.st_dev
;
for (fp
= start
+ nfiles
- 1; fp
>= start
; --fp
)
if (ino
== fp
->inode
&& dev
== fp
->dev
)
if (nfiles
== maxfiles
&& !(files
= (ID
*)realloc((char *)files
,
(u_int
)(sizeof(ID
) * (maxfiles
+= 128))))) {
(void)fprintf(stderr
, "du: %s\n", strerror(errno
));
files
[nfiles
].inode
= ino
;