du.c revision 227164
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1989, 1993, 1994
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * This code is derived from software contributed to Berkeley by
61590Srgrimes * Chris Newcomb.
71590Srgrimes *
81590Srgrimes * Redistribution and use in source and binary forms, with or without
91590Srgrimes * modification, are permitted provided that the following conditions
101590Srgrimes * are met:
111590Srgrimes * 1. Redistributions of source code must retain the above copyright
121590Srgrimes *    notice, this list of conditions and the following disclaimer.
131590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141590Srgrimes *    notice, this list of conditions and the following disclaimer in the
151590Srgrimes *    documentation and/or other materials provided with the distribution.
161590Srgrimes * 4. Neither the name of the University nor the names of its contributors
171590Srgrimes *    may be used to endorse or promote products derived from this software
181590Srgrimes *    without specific prior written permission.
191590Srgrimes *
201590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301590Srgrimes * SUCH DAMAGE.
311590Srgrimes */
321590Srgrimes
331590Srgrimes#ifndef lint
3441568Sarchiestatic const char copyright[] =
351590Srgrimes"@(#) Copyright (c) 1989, 1993, 1994\n\
361590Srgrimes	The Regents of the University of California.  All rights reserved.\n";
371590Srgrimes#endif /* not lint */
381590Srgrimes
391590Srgrimes#ifndef lint
4056597Smharo#if 0
4141568Sarchiestatic const char sccsid[] = "@(#)du.c	8.5 (Berkeley) 5/4/95";
4256597Smharo#endif
431590Srgrimes#endif /* not lint */
4499112Sobrien#include <sys/cdefs.h>
4599112Sobrien__FBSDID("$FreeBSD: head/usr.bin/du/du.c 227164 2011-11-06 08:15:17Z ed $");
461590Srgrimes
471590Srgrimes#include <sys/param.h>
4878158Sroam#include <sys/queue.h>
491590Srgrimes#include <sys/stat.h>
501590Srgrimes
511590Srgrimes#include <err.h>
521590Srgrimes#include <errno.h>
5378158Sroam#include <fnmatch.h>
541590Srgrimes#include <fts.h>
55129678Spjd#include <libutil.h>
56132201Stjr#include <locale.h>
57139813Spjd#include <stdint.h>
581590Srgrimes#include <stdio.h>
591590Srgrimes#include <stdlib.h>
601590Srgrimes#include <string.h>
6156597Smharo#include <sysexits.h>
6223693Speter#include <unistd.h>
631590Srgrimes
64227164Sedstatic SLIST_HEAD(ignhead, ignentry) ignores;
6578158Sroamstruct ignentry {
6678158Sroam	char			*mask;
6778158Sroam	SLIST_ENTRY(ignentry)	next;
6878158Sroam};
6978158Sroam
70128772Skientzlestatic int	linkchk(FTSENT *);
7192920Simpstatic void	usage(void);
72184656Smlaierstatic void	prthumanval(int64_t);
73184656Smlaierstatic void	ignoreadd(const char *);
74184656Smlaierstatic void	ignoreclean(void);
75184656Smlaierstatic int	ignorep(FTSENT *);
76191677Simpstatic void	siginfo(int __unused);
771590Srgrimes
78184656Smlaierstatic int	nodumpflag = 0;
79184733Smlaierstatic int	Aflag;
80184733Smlaierstatic long	blocksize, cblocksize;
81191677Simpstatic volatile sig_atomic_t info;
82158339Smaxim
831590Srgrimesint
84100822Sdwmalonemain(int argc, char *argv[])
851590Srgrimes{
8632097Sjkh	FTS		*fts;
8732097Sjkh	FTSENT		*p;
88184733Smlaier	off_t		savednumber, curblocks;
89209362Sbrian	off_t		threshold, threshold_sign;
9032097Sjkh	int		ftsoptions;
9132097Sjkh	int		listall;
9232097Sjkh	int		depth;
93176561Skeramida	int		Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag;
94176561Skeramida	int		hflag, lflag, ch, notused, rval;
9532097Sjkh	char 		**save;
9687216Smarkm	static char	dot[] = ".";
971590Srgrimes
98132201Stjr	setlocale(LC_ALL, "");
99132201Stjr
100176561Skeramida	Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
101184733Smlaier	    lflag = Aflag = 0;
102128772Skientzle
1031590Srgrimes	save = argv;
10432097Sjkh	ftsoptions = 0;
105184654Smlaier	savednumber = 0;
106209362Sbrian	threshold = 0;
107209362Sbrian	threshold_sign = 1;
108184733Smlaier	cblocksize = DEV_BSIZE;
109184733Smlaier	blocksize = 0;
11019120Sscrappy	depth = INT_MAX;
11178158Sroam	SLIST_INIT(&ignores);
112128772Skientzle
113209362Sbrian	while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrt:x")) != -1)
1141590Srgrimes		switch (ch) {
115184733Smlaier		case 'A':
116184733Smlaier			Aflag = 1;
117184733Smlaier			break;
118184733Smlaier		case 'B':
119184733Smlaier			errno = 0;
120184733Smlaier			cblocksize = atoi(optarg);
121184733Smlaier			if (errno == ERANGE || cblocksize <= 0) {
122184733Smlaier				warnx("invalid argument to option B: %s",
123184733Smlaier				    optarg);
124184733Smlaier				usage();
125184733Smlaier			}
126184733Smlaier			break;
127184654Smlaier		case 'H':
128184654Smlaier			Hflag = 1;
129184654Smlaier			break;
130184654Smlaier		case 'I':
131184654Smlaier			ignoreadd(optarg);
132184654Smlaier			break;
133184654Smlaier		case 'L':
134184654Smlaier			if (Pflag)
13519120Sscrappy				usage();
136184654Smlaier			Lflag = 1;
137184654Smlaier			break;
138184654Smlaier		case 'P':
139184654Smlaier			if (Lflag)
140184654Smlaier				usage();
141184654Smlaier			Pflag = 1;
142184654Smlaier			break;
143184654Smlaier		case 'a':
144184654Smlaier			aflag = 1;
145184654Smlaier			break;
146184654Smlaier		case 's':
147184654Smlaier			sflag = 1;
148184654Smlaier			break;
149184654Smlaier		case 'd':
150184654Smlaier			dflag = 1;
151184654Smlaier			errno = 0;
152184654Smlaier			depth = atoi(optarg);
153184654Smlaier			if (errno == ERANGE || depth < 0) {
154184654Smlaier				warnx("invalid argument to option d: %s",
155184654Smlaier				    optarg);
156184654Smlaier				usage();
157184654Smlaier			}
158184654Smlaier			break;
159184654Smlaier		case 'c':
160184654Smlaier			cflag = 1;
161184654Smlaier			break;
162184654Smlaier		case 'h':
163184654Smlaier			hflag = 1;
164184654Smlaier			break;
165184654Smlaier		case 'k':
166184654Smlaier			hflag = 0;
167184733Smlaier			blocksize = 1024;
168184654Smlaier			break;
169184654Smlaier		case 'l':
170184654Smlaier			lflag = 1;
171184654Smlaier			break;
172184654Smlaier		case 'm':
173184654Smlaier			hflag = 0;
174184733Smlaier			blocksize = 1048576;
175184654Smlaier			break;
176184654Smlaier		case 'n':
177184654Smlaier			nodumpflag = 1;
178184654Smlaier			break;
179184654Smlaier		case 'r':		 /* Compatibility. */
180184654Smlaier			break;
181209362Sbrian		case 't' :
182209362Sbrian			if (expand_number(optarg, &threshold) != 0 ||
183209362Sbrian			    threshold == 0) {
184209362Sbrian				warnx("invalid threshold: %s", optarg);
185209362Sbrian				usage();
186209362Sbrian			} else if (threshold < 0)
187209362Sbrian				threshold_sign = -1;
188209362Sbrian			break;
189184654Smlaier		case 'x':
190184654Smlaier			ftsoptions |= FTS_XDEV;
191184654Smlaier			break;
192184654Smlaier		case '?':
193184654Smlaier		default:
194184654Smlaier			usage();
195184654Smlaier			/* NOTREACHED */
1961590Srgrimes		}
19732097Sjkh
1981590Srgrimes	argc -= optind;
1991590Srgrimes	argv += optind;
2001590Srgrimes
2011590Srgrimes	/*
2021590Srgrimes	 * XXX
2031590Srgrimes	 * Because of the way that fts(3) works, logical walks will not count
2041590Srgrimes	 * the blocks actually used by symbolic links.  We rationalize this by
2051590Srgrimes	 * noting that users computing logical sizes are likely to do logical
2061590Srgrimes	 * copies, so not counting the links is correct.  The real reason is
2071590Srgrimes	 * that we'd have to re-implement the kernel's symbolic link traversing
2081590Srgrimes	 * algorithm to get this right.  If, for example, you have relative
2091590Srgrimes	 * symbolic links referencing other relative symbolic links, it gets
2101590Srgrimes	 * very nasty, very fast.  The bottom line is that it's documented in
2111590Srgrimes	 * the man page, so it's a feature.
2121590Srgrimes	 */
21332097Sjkh
21432097Sjkh	if (Hflag + Lflag + Pflag > 1)
21532097Sjkh		usage();
21632097Sjkh
21732097Sjkh	if (Hflag + Lflag + Pflag == 0)
21832097Sjkh		Pflag = 1;			/* -P (physical) is default */
21932097Sjkh
2201590Srgrimes	if (Hflag)
2211590Srgrimes		ftsoptions |= FTS_COMFOLLOW;
22232097Sjkh
22332097Sjkh	if (Lflag)
2241590Srgrimes		ftsoptions |= FTS_LOGICAL;
2251590Srgrimes
22632097Sjkh	if (Pflag)
22732097Sjkh		ftsoptions |= FTS_PHYSICAL;
22832097Sjkh
229184733Smlaier	if (!Aflag && (cblocksize % DEV_BSIZE) != 0)
230184733Smlaier		cblocksize = howmany(cblocksize, DEV_BSIZE) * DEV_BSIZE;
231184733Smlaier
23232097Sjkh	listall = 0;
23332097Sjkh
2341590Srgrimes	if (aflag) {
23519120Sscrappy		if (sflag || dflag)
2361590Srgrimes			usage();
23732097Sjkh		listall = 1;
23819120Sscrappy	} else if (sflag) {
23919120Sscrappy		if (dflag)
24019120Sscrappy			usage();
24132097Sjkh		depth = 0;
2421590Srgrimes	}
2431590Srgrimes
2441590Srgrimes	if (!*argv) {
2451590Srgrimes		argv = save;
24687216Smarkm		argv[0] = dot;
2471590Srgrimes		argv[1] = NULL;
2481590Srgrimes	}
2491590Srgrimes
250184733Smlaier	if (blocksize == 0)
251184733Smlaier		(void)getbsize(&notused, &blocksize);
2521590Srgrimes
253184733Smlaier	if (!Aflag) {
254184733Smlaier		cblocksize /= DEV_BSIZE;
255184733Smlaier		blocksize /= DEV_BSIZE;
256184733Smlaier	}
257184733Smlaier
258209362Sbrian	if (threshold != 0)
259209362Sbrian		threshold = howmany(threshold / DEV_BSIZE * cblocksize,
260209362Sbrian		    blocksize);
261209362Sbrian
26232097Sjkh	rval = 0;
263128772Skientzle
264191677Simp	(void)signal(SIGINFO, siginfo);
265191677Simp
2661590Srgrimes	if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
26732097Sjkh		err(1, "fts_open");
2681590Srgrimes
26932097Sjkh	while ((p = fts_read(fts)) != NULL) {
2701590Srgrimes		switch (p->fts_info) {
271184654Smlaier		case FTS_D:			/* Ignore. */
272184654Smlaier			if (ignorep(p))
273184654Smlaier				fts_set(fts, p, FTS_SKIP);
274184654Smlaier			break;
275184654Smlaier		case FTS_DP:
276184654Smlaier			if (ignorep(p))
2771590Srgrimes				break;
27878158Sroam
279184733Smlaier			curblocks = Aflag ?
280184733Smlaier			    howmany(p->fts_statp->st_size, cblocksize) :
281184733Smlaier			    howmany(p->fts_statp->st_blocks, cblocksize);
282184654Smlaier			p->fts_parent->fts_bignum += p->fts_bignum +=
283184733Smlaier			    curblocks;
284128772Skientzle
285209362Sbrian			if (p->fts_level <= depth && threshold <=
286209362Sbrian			    threshold_sign * howmany(p->fts_bignum *
287209362Sbrian			    cblocksize, blocksize)) {
288184654Smlaier				if (hflag) {
289184733Smlaier					prthumanval(p->fts_bignum);
290184654Smlaier					(void)printf("\t%s\n", p->fts_path);
291184654Smlaier				} else {
292184654Smlaier					(void)printf("%jd\t%s\n",
293184742Smlaier					    (intmax_t)howmany(p->fts_bignum *
294184742Smlaier					    cblocksize, blocksize),
295184742Smlaier					    p->fts_path);
29658601Scharnier				}
297184654Smlaier			}
298191677Simp			if (info) {
299191677Simp				info = 0;
300191677Simp				(void)printf("\t%s\n", p->fts_path);
301191677Simp			}
302184654Smlaier			break;
303184654Smlaier		case FTS_DC:			/* Ignore. */
304184654Smlaier			break;
305184654Smlaier		case FTS_DNR:			/* Warn, continue. */
306184654Smlaier		case FTS_ERR:
307184654Smlaier		case FTS_NS:
308184654Smlaier			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
309184654Smlaier			rval = 1;
310184654Smlaier			break;
311184654Smlaier		default:
312184654Smlaier			if (ignorep(p))
31332097Sjkh				break;
314184654Smlaier
315184654Smlaier			if (lflag == 0 && p->fts_statp->st_nlink > 1 &&
316184654Smlaier			    linkchk(p))
31732097Sjkh				break;
31878158Sroam
319184733Smlaier			curblocks = Aflag ?
320184733Smlaier			    howmany(p->fts_statp->st_size, cblocksize) :
321184733Smlaier			    howmany(p->fts_statp->st_blocks, cblocksize);
322184733Smlaier
323184654Smlaier			if (listall || p->fts_level == 0) {
324184654Smlaier				if (hflag) {
325184733Smlaier					prthumanval(curblocks);
326184654Smlaier					(void)printf("\t%s\n", p->fts_path);
327184654Smlaier				} else {
328184654Smlaier					(void)printf("%jd\t%s\n",
329184742Smlaier					    (intmax_t)howmany(curblocks *
330184742Smlaier					    cblocksize, blocksize),
331184742Smlaier					    p->fts_path);
33258601Scharnier				}
333184654Smlaier			}
33432097Sjkh
335184733Smlaier			p->fts_parent->fts_bignum += curblocks;
3361590Srgrimes		}
337139813Spjd		savednumber = p->fts_parent->fts_bignum;
33832097Sjkh	}
33932097Sjkh
3401590Srgrimes	if (errno)
3411590Srgrimes		err(1, "fts_read");
34232097Sjkh
34358601Scharnier	if (cflag) {
34456597Smharo		if (hflag) {
345184733Smlaier			prthumanval(savednumber);
346184654Smlaier			(void)printf("\ttotal\n");
34756597Smharo		} else {
348184654Smlaier			(void)printf("%jd\ttotal\n", (intmax_t)howmany(
349184733Smlaier			    savednumber * cblocksize, blocksize));
35056597Smharo		}
35158601Scharnier	}
35232097Sjkh
35378158Sroam	ignoreclean();
35428891Swosch	exit(rval);
3551590Srgrimes}
3561590Srgrimes
357128772Skientzlestatic int
358128772Skientzlelinkchk(FTSENT *p)
359128772Skientzle{
360128772Skientzle	struct links_entry {
361128806Skientzle		struct links_entry *next;
362128806Skientzle		struct links_entry *previous;
363128806Skientzle		int	 links;
364128806Skientzle		dev_t	 dev;
365128806Skientzle		ino_t	 ino;
366128772Skientzle	};
367128806Skientzle	static const size_t links_hash_initial_size = 8192;
368128806Skientzle	static struct links_entry **buckets;
369128806Skientzle	static struct links_entry *free_list;
370128806Skientzle	static size_t number_buckets;
371128806Skientzle	static unsigned long number_entries;
372128806Skientzle	static char stop_allocating;
373128806Skientzle	struct links_entry *le, **new_buckets;
374128806Skientzle	struct stat *st;
375128806Skientzle	size_t i, new_size;
376144840Sstefanf	int hash;
37732097Sjkh
378128772Skientzle	st = p->fts_statp;
37932097Sjkh
380128772Skientzle	/* If necessary, initialize the hash table. */
381128772Skientzle	if (buckets == NULL) {
382128772Skientzle		number_buckets = links_hash_initial_size;
383128772Skientzle		buckets = malloc(number_buckets * sizeof(buckets[0]));
384128772Skientzle		if (buckets == NULL)
385128834Skientzle			errx(1, "No memory for hardlink detection");
386128772Skientzle		for (i = 0; i < number_buckets; i++)
387128772Skientzle			buckets[i] = NULL;
388128772Skientzle	}
3891590Srgrimes
390128772Skientzle	/* If the hash table is getting too full, enlarge it. */
391128772Skientzle	if (number_entries > number_buckets * 10 && !stop_allocating) {
392128772Skientzle		new_size = number_buckets * 2;
393128772Skientzle		new_buckets = malloc(new_size * sizeof(struct links_entry *));
394128772Skientzle
395128772Skientzle		/* Try releasing the free list to see if that helps. */
396128772Skientzle		if (new_buckets == NULL && free_list != NULL) {
397128772Skientzle			while (free_list != NULL) {
398128772Skientzle				le = free_list;
399128772Skientzle				free_list = le->next;
400128772Skientzle				free(le);
401128772Skientzle			}
402184654Smlaier			new_buckets = malloc(new_size *
403184654Smlaier			    sizeof(new_buckets[0]));
404128772Skientzle		}
405128772Skientzle
406128772Skientzle		if (new_buckets == NULL) {
407128772Skientzle			stop_allocating = 1;
408128834Skientzle			warnx("No more memory for tracking hard links");
409128772Skientzle		} else {
410128772Skientzle			memset(new_buckets, 0,
411128772Skientzle			    new_size * sizeof(struct links_entry *));
412128772Skientzle			for (i = 0; i < number_buckets; i++) {
413128772Skientzle				while (buckets[i] != NULL) {
414128772Skientzle					/* Remove entry from old bucket. */
415128772Skientzle					le = buckets[i];
416128772Skientzle					buckets[i] = le->next;
417128772Skientzle
418128772Skientzle					/* Add entry to new bucket. */
419128772Skientzle					hash = (le->dev ^ le->ino) % new_size;
420128772Skientzle
421128772Skientzle					if (new_buckets[hash] != NULL)
422128772Skientzle						new_buckets[hash]->previous =
423128772Skientzle						    le;
424128772Skientzle					le->next = new_buckets[hash];
425128772Skientzle					le->previous = NULL;
426128772Skientzle					new_buckets[hash] = le;
427128772Skientzle				}
428128772Skientzle			}
429128772Skientzle			free(buckets);
430128772Skientzle			buckets = new_buckets;
431128772Skientzle			number_buckets = new_size;
432128772Skientzle		}
433128772Skientzle	}
434128772Skientzle
435128772Skientzle	/* Try to locate this entry in the hash table. */
436128772Skientzle	hash = ( st->st_dev ^ st->st_ino ) % number_buckets;
437128772Skientzle	for (le = buckets[hash]; le != NULL; le = le->next) {
438128772Skientzle		if (le->dev == st->st_dev && le->ino == st->st_ino) {
439128772Skientzle			/*
440128772Skientzle			 * Save memory by releasing an entry when we've seen
441128772Skientzle			 * all of it's links.
442128772Skientzle			 */
443128772Skientzle			if (--le->links <= 0) {
444128772Skientzle				if (le->previous != NULL)
445128772Skientzle					le->previous->next = le->next;
446128772Skientzle				if (le->next != NULL)
447128772Skientzle					le->next->previous = le->previous;
448128772Skientzle				if (buckets[hash] == le)
449128772Skientzle					buckets[hash] = le->next;
450128772Skientzle				number_entries--;
451128772Skientzle				/* Recycle this node through the free list */
452128772Skientzle				if (stop_allocating) {
453128772Skientzle					free(le);
454128772Skientzle				} else {
455128772Skientzle					le->next = free_list;
456128772Skientzle					free_list = le;
457128772Skientzle				}
458128772Skientzle			}
459128772Skientzle			return (1);
460128772Skientzle		}
461128772Skientzle	}
462128772Skientzle
463128772Skientzle	if (stop_allocating)
464128772Skientzle		return (0);
465128772Skientzle
466128772Skientzle	/* Add this entry to the links cache. */
467128772Skientzle	if (free_list != NULL) {
468128772Skientzle		/* Pull a node from the free list if we can. */
469128772Skientzle		le = free_list;
470128772Skientzle		free_list = le->next;
471128772Skientzle	} else
472128772Skientzle		/* Malloc one if we have to. */
473128772Skientzle		le = malloc(sizeof(struct links_entry));
474128772Skientzle	if (le == NULL) {
475128772Skientzle		stop_allocating = 1;
476128834Skientzle		warnx("No more memory for tracking hard links");
477128772Skientzle		return (0);
478128772Skientzle	}
479128772Skientzle	le->dev = st->st_dev;
480128772Skientzle	le->ino = st->st_ino;
481128772Skientzle	le->links = st->st_nlink - 1;
482128772Skientzle	number_entries++;
483128772Skientzle	le->next = buckets[hash];
484128772Skientzle	le->previous = NULL;
485128772Skientzle	if (buckets[hash] != NULL)
486128772Skientzle		buckets[hash]->previous = le;
487128772Skientzle	buckets[hash] = le;
4881590Srgrimes	return (0);
4891590Srgrimes}
4901590Srgrimes
491184656Smlaierstatic void
492129678Spjdprthumanval(int64_t bytes)
49356597Smharo{
494129678Spjd	char buf[5];
49556597Smharo
496184733Smlaier	bytes *= cblocksize;
497184733Smlaier	if (!Aflag)
498184733Smlaier		bytes *= DEV_BSIZE;
49956597Smharo
500129678Spjd	humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
501129678Spjd	    HN_B | HN_NOSPACE | HN_DECIMAL);
50256597Smharo
503129678Spjd	(void)printf("%4s", buf);
50456597Smharo}
50556597Smharo
50627099Scharnierstatic void
507100822Sdwmaloneusage(void)
5081590Srgrimes{
5091590Srgrimes	(void)fprintf(stderr,
510184733Smlaier		"usage: du [-A] [-H | -L | -P] [-a | -s | -d depth] [-c] "
511184733Smlaier		"[-l] [-h | -k | -m | -B bsize] [-n] [-x] [-I mask] "
512184733Smlaier		"[file ...]\n");
51356597Smharo	exit(EX_USAGE);
5141590Srgrimes}
51578158Sroam
516184656Smlaierstatic void
517100822Sdwmaloneignoreadd(const char *mask)
51878158Sroam{
51978158Sroam	struct ignentry *ign;
52078158Sroam
52178158Sroam	ign = calloc(1, sizeof(*ign));
52278158Sroam	if (ign == NULL)
52378158Sroam		errx(1, "cannot allocate memory");
52478158Sroam	ign->mask = strdup(mask);
52578158Sroam	if (ign->mask == NULL)
52678158Sroam		errx(1, "cannot allocate memory");
52778158Sroam	SLIST_INSERT_HEAD(&ignores, ign, next);
52878158Sroam}
52978158Sroam
530184656Smlaierstatic void
531100822Sdwmaloneignoreclean(void)
53278158Sroam{
53378158Sroam	struct ignentry *ign;
53478158Sroam
53578158Sroam	while (!SLIST_EMPTY(&ignores)) {
53678158Sroam		ign = SLIST_FIRST(&ignores);
53778158Sroam		SLIST_REMOVE_HEAD(&ignores, next);
53878158Sroam		free(ign->mask);
53978158Sroam		free(ign);
54078158Sroam	}
54178158Sroam}
54278158Sroam
543184656Smlaierstatic int
544100822Sdwmaloneignorep(FTSENT *ent)
54578158Sroam{
54678158Sroam	struct ignentry *ign;
54778158Sroam
548158339Smaxim	if (nodumpflag && (ent->fts_statp->st_flags & UF_NODUMP))
549158339Smaxim		return 1;
55078158Sroam	SLIST_FOREACH(ign, &ignores, next)
55178158Sroam		if (fnmatch(ign->mask, ent->fts_name, 0) != FNM_NOMATCH)
55278158Sroam			return 1;
55378158Sroam	return 0;
55478158Sroam}
555191677Simp
556191677Simpstatic void
557191677Simpsiginfo(int sig __unused)
558191677Simp{
559191677Simp
560191677Simp	info = 1;
561191677Simp}
562