* 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.19 (Berkeley) %G%";
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
;
while ((ch
= getopt(argc
, argv
, "Hahsx")) != EOF
)
ftsoptions
|= FTS_COMFOLLOW
;
ftsoptions
&= ~FTS_PHYSICAL
;
ftsoptions
|= FTS_LOGICAL
;
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_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("%qd\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] [-Hhx] [file ...]\n");
err(const char *fmt
, ...)
(void)fprintf(stderr
, "du: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");