511047c33ad73b083905fd4d3974c97330df0bdf
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)du.c 8.3 (Berkeley) %G%";
int linkchk
__P((FTSENT
*));
int ftsoptions
, listdirs
, listfiles
;
int Hflag
, Lflag
, Pflag
, aflag
, ch
, notused
, rval
, sflag
;
Hflag
= Lflag
= Pflag
= aflag
= sflag
= 0;
ftsoptions
= FTS_PHYSICAL
;
while ((ch
= getopt(argc
, argv
, "HLPasx")) != EOF
)
* Because of the way that fts(3) works, logical walks will not count
* the blocks actually used by symbolic links. We rationalize this by
* noting that users computing logical sizes are likely to do logical
* copies, so not counting the links is correct. The real reason is
* that we'd have to re-implement the kernel's symbolic link traversing
* algorithm to get this right. If, for example, you have relative
* symbolic links referencing other relative symbolic links, it gets
* very nasty, very fast. The bottom line is that it's documented in
* the man page, so it's a feature.
ftsoptions
|= FTS_COMFOLLOW
;
ftsoptions
&= ~FTS_PHYSICAL
;
ftsoptions
|= FTS_LOGICAL
;
listdirs
= listfiles
= 1;
listdirs
= listfiles
= 0;
(void)getbsize(¬used
, &blocksize
);
if ((fts
= fts_open(argv
, ftsoptions
, NULL
)) == NULL
)
for (rval
= 0; (p
= fts_read(fts
)) != NULL
;)
case FTS_D
: /* Ignore. */
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
),
case FTS_DC
: /* Ignore. */
case FTS_DNR
: /* Warn, continue. */
warnx("%s: %s", p
->fts_path
, strerror(p
->fts_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
;
static int maxfiles
, nfiles
;
ino
= p
->fts_statp
->st_ino
;
dev
= p
->fts_statp
->st_dev
;
if ((start
= files
) != NULL
)
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
)
files
[nfiles
].inode
= ino
;
"usage: du [-H | -L | -P] [-a | -s] [-x] [file ...]\n");