1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* Chris Newcomb.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 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
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-12-06 22:58:23 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1989, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
2000-01-25 17:46:59 +00:00
|
|
|
#if 0
|
1998-12-06 22:58:23 +00:00
|
|
|
static const char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95";
|
2000-01-25 17:46:59 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1997-12-29 20:56:21 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/param.h>
|
2001-06-13 06:38:58 +00:00
|
|
|
#include <sys/queue.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2001-06-13 06:38:58 +00:00
|
|
|
#include <fnmatch.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <fts.h>
|
2004-05-24 22:22:29 +00:00
|
|
|
#include <libutil.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-01-25 17:46:59 +00:00
|
|
|
#include <sysexits.h>
|
1997-03-11 13:43:33 +00:00
|
|
|
#include <unistd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-06-13 06:38:58 +00:00
|
|
|
SLIST_HEAD(ignhead, ignentry) ignores;
|
|
|
|
struct ignentry {
|
|
|
|
char *mask;
|
|
|
|
SLIST_ENTRY(ignentry) next;
|
|
|
|
};
|
|
|
|
|
2004-04-30 18:17:51 +00:00
|
|
|
static int linkchk(FTSENT *);
|
2002-03-22 01:22:50 +00:00
|
|
|
static void usage(void);
|
2004-05-24 22:22:29 +00:00
|
|
|
void prthumanval(int64_t);
|
2002-03-22 01:22:50 +00:00
|
|
|
void ignoreadd(const char *);
|
|
|
|
void ignoreclean(void);
|
|
|
|
int ignorep(FTSENT *);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
int
|
2002-07-28 15:50:38 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1997-12-29 20:56:21 +00:00
|
|
|
FTS *fts;
|
|
|
|
FTSENT *p;
|
1998-07-29 17:50:06 +00:00
|
|
|
long blocksize, savednumber = 0;
|
1997-12-29 20:56:21 +00:00
|
|
|
int ftsoptions;
|
|
|
|
int listall;
|
|
|
|
int depth;
|
2002-12-30 18:13:07 +00:00
|
|
|
int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
|
1997-12-29 20:56:21 +00:00
|
|
|
char **save;
|
2001-12-02 13:48:40 +00:00
|
|
|
static char dot[] = ".";
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-01-25 17:46:59 +00:00
|
|
|
Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
|
2004-04-30 18:17:51 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
save = argv;
|
1997-12-29 20:56:21 +00:00
|
|
|
ftsoptions = 0;
|
1996-10-23 06:53:57 +00:00
|
|
|
depth = INT_MAX;
|
2001-06-13 06:38:58 +00:00
|
|
|
SLIST_INIT(&ignores);
|
2004-04-30 18:17:51 +00:00
|
|
|
|
2001-06-13 06:38:58 +00:00
|
|
|
while ((ch = getopt(argc, argv, "HI:LPasd:chkrx")) != -1)
|
1994-05-27 12:33:43 +00:00
|
|
|
switch (ch) {
|
1997-12-29 20:56:21 +00:00
|
|
|
case 'H':
|
|
|
|
Hflag = 1;
|
|
|
|
break;
|
2001-06-13 06:38:58 +00:00
|
|
|
case 'I':
|
|
|
|
ignoreadd(optarg);
|
|
|
|
break;
|
1997-12-29 20:56:21 +00:00
|
|
|
case 'L':
|
|
|
|
if (Pflag)
|
|
|
|
usage();
|
|
|
|
Lflag = 1;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
if (Lflag)
|
|
|
|
usage();
|
|
|
|
Pflag = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
errno = 0;
|
|
|
|
depth = atoi(optarg);
|
|
|
|
if (errno == ERANGE || depth < 0) {
|
2000-03-26 14:21:57 +00:00
|
|
|
warnx("invalid argument to option d: %s", optarg);
|
1997-12-29 20:56:21 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
cflag = 1;
|
|
|
|
break;
|
2000-01-25 17:46:59 +00:00
|
|
|
case 'h':
|
|
|
|
putenv("BLOCKSIZE=512");
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
|
|
|
case 'k':
|
2003-03-30 21:25:16 +00:00
|
|
|
hflag = 0;
|
|
|
|
putenv("BLOCKSIZE=1024");
|
2000-01-25 17:46:59 +00:00
|
|
|
break;
|
|
|
|
case 'r': /* Compatibility. */
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
ftsoptions |= FTS_XDEV;
|
|
|
|
break;
|
1997-12-29 20:56:21 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
1996-10-23 06:53:57 +00:00
|
|
|
usage();
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* 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.
|
|
|
|
*/
|
1997-12-29 20:56:21 +00:00
|
|
|
|
|
|
|
if (Hflag + Lflag + Pflag > 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (Hflag + Lflag + Pflag == 0)
|
|
|
|
Pflag = 1; /* -P (physical) is default */
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (Hflag)
|
|
|
|
ftsoptions |= FTS_COMFOLLOW;
|
1997-12-29 20:56:21 +00:00
|
|
|
|
|
|
|
if (Lflag)
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions |= FTS_LOGICAL;
|
1997-12-29 20:56:21 +00:00
|
|
|
|
|
|
|
if (Pflag)
|
|
|
|
ftsoptions |= FTS_PHYSICAL;
|
|
|
|
|
|
|
|
listall = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (aflag) {
|
1996-10-23 06:53:57 +00:00
|
|
|
if (sflag || dflag)
|
1994-05-27 12:33:43 +00:00
|
|
|
usage();
|
1997-12-29 20:56:21 +00:00
|
|
|
listall = 1;
|
1996-10-23 06:53:57 +00:00
|
|
|
} else if (sflag) {
|
|
|
|
if (dflag)
|
|
|
|
usage();
|
1997-12-29 20:56:21 +00:00
|
|
|
depth = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!*argv) {
|
|
|
|
argv = save;
|
2001-12-02 13:48:40 +00:00
|
|
|
argv[0] = dot;
|
1994-05-27 12:33:43 +00:00
|
|
|
argv[1] = NULL;
|
|
|
|
}
|
|
|
|
|
1997-12-29 20:56:21 +00:00
|
|
|
(void) getbsize(¬used, &blocksize);
|
1994-05-27 12:33:43 +00:00
|
|
|
blocksize /= 512;
|
|
|
|
|
1997-12-29 20:56:21 +00:00
|
|
|
rval = 0;
|
2004-04-30 18:17:51 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
|
1997-12-29 20:56:21 +00:00
|
|
|
err(1, "fts_open");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1997-12-29 20:56:21 +00:00
|
|
|
while ((p = fts_read(fts)) != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
switch (p->fts_info) {
|
1997-12-29 20:56:21 +00:00
|
|
|
case FTS_D: /* Ignore. */
|
2001-06-13 06:38:58 +00:00
|
|
|
if (ignorep(p))
|
|
|
|
fts_set(fts, p, FTS_SKIP);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1997-12-29 20:56:21 +00:00
|
|
|
case FTS_DP:
|
2001-06-13 06:38:58 +00:00
|
|
|
if (ignorep(p))
|
|
|
|
break;
|
|
|
|
|
1997-12-29 20:56:21 +00:00
|
|
|
p->fts_parent->fts_number +=
|
|
|
|
p->fts_number += p->fts_statp->st_blocks;
|
2004-04-30 18:17:51 +00:00
|
|
|
|
2000-03-26 14:21:57 +00:00
|
|
|
if (p->fts_level <= depth) {
|
2000-01-25 17:46:59 +00:00
|
|
|
if (hflag) {
|
2000-03-24 06:25:32 +00:00
|
|
|
(void) prthumanval(howmany(p->fts_number, blocksize));
|
2000-01-25 17:46:59 +00:00
|
|
|
(void) printf("\t%s\n", p->fts_path);
|
|
|
|
} else {
|
1997-12-29 20:56:21 +00:00
|
|
|
(void) printf("%ld\t%s\n",
|
|
|
|
howmany(p->fts_number, blocksize),
|
|
|
|
p->fts_path);
|
2000-01-25 17:46:59 +00:00
|
|
|
}
|
2000-03-26 14:21:57 +00:00
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
break;
|
|
|
|
case FTS_DC: /* Ignore. */
|
|
|
|
break;
|
|
|
|
case FTS_DNR: /* Warn, continue. */
|
|
|
|
case FTS_ERR:
|
|
|
|
case FTS_NS:
|
|
|
|
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2001-06-13 06:38:58 +00:00
|
|
|
if (ignorep(p))
|
|
|
|
break;
|
|
|
|
|
1997-12-29 20:56:21 +00:00
|
|
|
if (p->fts_statp->st_nlink > 1 && linkchk(p))
|
|
|
|
break;
|
2004-04-30 18:17:51 +00:00
|
|
|
|
2000-03-26 14:21:57 +00:00
|
|
|
if (listall || p->fts_level == 0) {
|
2000-01-25 17:46:59 +00:00
|
|
|
if (hflag) {
|
|
|
|
(void) prthumanval(howmany(p->fts_statp->st_blocks,
|
|
|
|
blocksize));
|
|
|
|
(void) printf("\t%s\n", p->fts_path);
|
|
|
|
} else {
|
|
|
|
(void) printf("%qd\t%s\n",
|
2002-02-08 07:49:13 +00:00
|
|
|
(long long)howmany(p->fts_statp->st_blocks, blocksize),
|
2000-01-25 17:46:59 +00:00
|
|
|
p->fts_path);
|
|
|
|
}
|
2000-03-26 14:21:57 +00:00
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
|
|
|
|
p->fts_parent->fts_number += p->fts_statp->st_blocks;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-11 15:53:08 +00:00
|
|
|
savednumber = p->fts_parent->fts_number;
|
1997-12-29 20:56:21 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (errno)
|
|
|
|
err(1, "fts_read");
|
1997-12-29 20:56:21 +00:00
|
|
|
|
2000-03-26 14:21:57 +00:00
|
|
|
if (cflag) {
|
2000-01-25 17:46:59 +00:00
|
|
|
if (hflag) {
|
|
|
|
(void) prthumanval(howmany(savednumber, blocksize));
|
|
|
|
(void) printf("\ttotal\n");
|
|
|
|
} else {
|
|
|
|
(void) printf("%ld\ttotal\n", howmany(savednumber, blocksize));
|
|
|
|
}
|
2000-03-26 14:21:57 +00:00
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
|
2001-06-13 06:38:58 +00:00
|
|
|
ignoreclean();
|
1997-08-29 11:40:00 +00:00
|
|
|
exit(rval);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-04-30 18:17:51 +00:00
|
|
|
static int
|
|
|
|
linkchk(FTSENT *p)
|
|
|
|
{
|
|
|
|
struct links_entry {
|
2004-05-01 21:47:31 +00:00
|
|
|
struct links_entry *next;
|
|
|
|
struct links_entry *previous;
|
|
|
|
int links;
|
|
|
|
dev_t dev;
|
|
|
|
ino_t ino;
|
2004-04-30 18:17:51 +00:00
|
|
|
};
|
2004-05-01 21:47:31 +00:00
|
|
|
static const size_t links_hash_initial_size = 8192;
|
|
|
|
static struct links_entry **buckets;
|
|
|
|
static struct links_entry *free_list;
|
|
|
|
static size_t number_buckets;
|
|
|
|
static unsigned long number_entries;
|
|
|
|
static char stop_allocating;
|
|
|
|
struct links_entry *le, **new_buckets;
|
|
|
|
struct stat *st;
|
|
|
|
size_t i, new_size;
|
2004-05-02 17:54:57 +00:00
|
|
|
int count, hash;
|
2004-04-30 18:17:51 +00:00
|
|
|
|
|
|
|
st = p->fts_statp;
|
|
|
|
|
|
|
|
/* If necessary, initialize the hash table. */
|
|
|
|
if (buckets == NULL) {
|
|
|
|
number_buckets = links_hash_initial_size;
|
|
|
|
buckets = malloc(number_buckets * sizeof(buckets[0]));
|
|
|
|
if (buckets == NULL)
|
2004-05-02 17:54:57 +00:00
|
|
|
errx(1, "No memory for hardlink detection");
|
2004-04-30 18:17:51 +00:00
|
|
|
for (i = 0; i < number_buckets; i++)
|
|
|
|
buckets[i] = NULL;
|
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
|
2004-04-30 18:17:51 +00:00
|
|
|
/* If the hash table is getting too full, enlarge it. */
|
|
|
|
if (number_entries > number_buckets * 10 && !stop_allocating) {
|
|
|
|
new_size = number_buckets * 2;
|
|
|
|
new_buckets = malloc(new_size * sizeof(struct links_entry *));
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
/* Try releasing the free list to see if that helps. */
|
|
|
|
if (new_buckets == NULL && free_list != NULL) {
|
|
|
|
while (free_list != NULL) {
|
|
|
|
le = free_list;
|
|
|
|
free_list = le->next;
|
|
|
|
free(le);
|
|
|
|
}
|
|
|
|
new_buckets = malloc(new_size * sizeof(new_buckets[0]));
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-04-30 18:17:51 +00:00
|
|
|
if (new_buckets == NULL) {
|
|
|
|
stop_allocating = 1;
|
2004-05-02 17:54:57 +00:00
|
|
|
warnx("No more memory for tracking hard links");
|
2004-04-30 18:17:51 +00:00
|
|
|
} else {
|
|
|
|
memset(new_buckets, 0,
|
|
|
|
new_size * sizeof(struct links_entry *));
|
|
|
|
for (i = 0; i < number_buckets; i++) {
|
|
|
|
while (buckets[i] != NULL) {
|
|
|
|
/* Remove entry from old bucket. */
|
|
|
|
le = buckets[i];
|
|
|
|
buckets[i] = le->next;
|
|
|
|
|
|
|
|
/* Add entry to new bucket. */
|
|
|
|
hash = (le->dev ^ le->ino) % new_size;
|
|
|
|
|
|
|
|
if (new_buckets[hash] != NULL)
|
|
|
|
new_buckets[hash]->previous =
|
|
|
|
le;
|
|
|
|
le->next = new_buckets[hash];
|
|
|
|
le->previous = NULL;
|
|
|
|
new_buckets[hash] = le;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(buckets);
|
|
|
|
buckets = new_buckets;
|
|
|
|
number_buckets = new_size;
|
|
|
|
}
|
|
|
|
}
|
1997-12-29 20:56:21 +00:00
|
|
|
|
2004-04-30 18:17:51 +00:00
|
|
|
/* Try to locate this entry in the hash table. */
|
|
|
|
hash = ( st->st_dev ^ st->st_ino ) % number_buckets;
|
|
|
|
for (le = buckets[hash]; le != NULL; le = le->next) {
|
|
|
|
if (le->dev == st->st_dev && le->ino == st->st_ino) {
|
|
|
|
/*
|
|
|
|
* Save memory by releasing an entry when we've seen
|
|
|
|
* all of it's links.
|
|
|
|
*/
|
|
|
|
if (--le->links <= 0) {
|
|
|
|
if (le->previous != NULL)
|
|
|
|
le->previous->next = le->next;
|
|
|
|
if (le->next != NULL)
|
|
|
|
le->next->previous = le->previous;
|
|
|
|
if (buckets[hash] == le)
|
|
|
|
buckets[hash] = le->next;
|
|
|
|
number_entries--;
|
|
|
|
/* Recycle this node through the free list */
|
|
|
|
if (stop_allocating) {
|
|
|
|
free(le);
|
|
|
|
} else {
|
|
|
|
le->next = free_list;
|
|
|
|
free_list = le;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop_allocating)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Add this entry to the links cache. */
|
|
|
|
if (free_list != NULL) {
|
|
|
|
/* Pull a node from the free list if we can. */
|
|
|
|
le = free_list;
|
|
|
|
free_list = le->next;
|
|
|
|
} else
|
|
|
|
/* Malloc one if we have to. */
|
|
|
|
le = malloc(sizeof(struct links_entry));
|
|
|
|
if (le == NULL) {
|
|
|
|
stop_allocating = 1;
|
2004-05-02 17:54:57 +00:00
|
|
|
warnx("No more memory for tracking hard links");
|
2004-04-30 18:17:51 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
le->dev = st->st_dev;
|
|
|
|
le->ino = st->st_ino;
|
|
|
|
le->links = st->st_nlink - 1;
|
|
|
|
number_entries++;
|
|
|
|
le->next = buckets[hash];
|
|
|
|
le->previous = NULL;
|
|
|
|
if (buckets[hash] != NULL)
|
|
|
|
buckets[hash]->previous = le;
|
|
|
|
buckets[hash] = le;
|
1994-05-27 12:33:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-01-25 17:46:59 +00:00
|
|
|
void
|
2004-05-24 22:22:29 +00:00
|
|
|
prthumanval(int64_t bytes)
|
2000-01-25 17:46:59 +00:00
|
|
|
{
|
2004-05-24 22:22:29 +00:00
|
|
|
char buf[5];
|
|
|
|
|
|
|
|
bytes *= DEV_BSIZE;
|
2000-01-25 17:46:59 +00:00
|
|
|
|
2004-05-24 22:22:29 +00:00
|
|
|
humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
|
|
|
|
HN_B | HN_NOSPACE | HN_DECIMAL);
|
2000-01-25 17:46:59 +00:00
|
|
|
|
2004-05-24 22:22:29 +00:00
|
|
|
(void)printf("%4s", buf);
|
2000-01-25 17:46:59 +00:00
|
|
|
}
|
|
|
|
|
1997-06-30 06:50:07 +00:00
|
|
|
static void
|
2002-07-28 15:50:38 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
(void)fprintf(stderr,
|
2001-06-13 06:38:58 +00:00
|
|
|
"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k] [-x] [-I mask] [file ...]\n");
|
2000-01-25 17:46:59 +00:00
|
|
|
exit(EX_USAGE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-06-13 06:38:58 +00:00
|
|
|
|
|
|
|
void
|
2002-07-28 15:50:38 +00:00
|
|
|
ignoreadd(const char *mask)
|
2001-06-13 06:38:58 +00:00
|
|
|
{
|
|
|
|
struct ignentry *ign;
|
|
|
|
|
|
|
|
ign = calloc(1, sizeof(*ign));
|
|
|
|
if (ign == NULL)
|
|
|
|
errx(1, "cannot allocate memory");
|
|
|
|
ign->mask = strdup(mask);
|
|
|
|
if (ign->mask == NULL)
|
|
|
|
errx(1, "cannot allocate memory");
|
|
|
|
SLIST_INSERT_HEAD(&ignores, ign, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-28 15:50:38 +00:00
|
|
|
ignoreclean(void)
|
2001-06-13 06:38:58 +00:00
|
|
|
{
|
|
|
|
struct ignentry *ign;
|
|
|
|
|
|
|
|
while (!SLIST_EMPTY(&ignores)) {
|
|
|
|
ign = SLIST_FIRST(&ignores);
|
|
|
|
SLIST_REMOVE_HEAD(&ignores, next);
|
|
|
|
free(ign->mask);
|
|
|
|
free(ign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-28 15:50:38 +00:00
|
|
|
ignorep(FTSENT *ent)
|
2001-06-13 06:38:58 +00:00
|
|
|
{
|
|
|
|
struct ignentry *ign;
|
|
|
|
|
|
|
|
SLIST_FOREACH(ign, &ignores, next)
|
|
|
|
if (fnmatch(ign->mask, ent->fts_name, 0) != FNM_NOMATCH)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|