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: stable/10/usr.bin/du/du.c 321097 2017-07-17 21:18:44Z ngie $");
461590Srgrimes
471590Srgrimes#include <sys/param.h>
4878158Sroam#include <sys/queue.h>
491590Srgrimes#include <sys/stat.h>
501590Srgrimes#include <err.h>
511590Srgrimes#include <errno.h>
5278158Sroam#include <fnmatch.h>
531590Srgrimes#include <fts.h>
54129678Spjd#include <libutil.h>
55132201Stjr#include <locale.h>
56139813Spjd#include <stdint.h>
571590Srgrimes#include <stdio.h>
581590Srgrimes#include <stdlib.h>
591590Srgrimes#include <string.h>
6056597Smharo#include <sysexits.h>
6123693Speter#include <unistd.h>
621590Srgrimes
63227164Sedstatic SLIST_HEAD(ignhead, ignentry) ignores;
6478158Sroamstruct ignentry {
6578158Sroam	char			*mask;
6678158Sroam	SLIST_ENTRY(ignentry)	next;
6778158Sroam};
6878158Sroam
69128772Skientzlestatic int	linkchk(FTSENT *);
7092920Simpstatic void	usage(void);
71184656Smlaierstatic void	prthumanval(int64_t);
72184656Smlaierstatic void	ignoreadd(const char *);
73184656Smlaierstatic void	ignoreclean(void);
74184656Smlaierstatic int	ignorep(FTSENT *);
75191677Simpstatic void	siginfo(int __unused);
761590Srgrimes
77184656Smlaierstatic int	nodumpflag = 0;
78184733Smlaierstatic int	Aflag;
79184733Smlaierstatic long	blocksize, cblocksize;
80191677Simpstatic volatile sig_atomic_t info;
81158339Smaxim
821590Srgrimesint
83100822Sdwmalonemain(int argc, char *argv[])
841590Srgrimes{
8532097Sjkh	FTS		*fts;
8632097Sjkh	FTSENT		*p;
87184733Smlaier	off_t		savednumber, curblocks;
88209362Sbrian	off_t		threshold, threshold_sign;
8932097Sjkh	int		ftsoptions;
9032097Sjkh	int		depth;
91228669Sjilles	int		Hflag, Lflag, aflag, sflag, dflag, cflag;
92176561Skeramida	int		hflag, lflag, ch, notused, rval;
9332097Sjkh	char 		**save;
9487216Smarkm	static char	dot[] = ".";
951590Srgrimes
96132201Stjr	setlocale(LC_ALL, "");
97132201Stjr
98228669Sjilles	Hflag = Lflag = aflag = sflag = dflag = cflag = hflag =
99184733Smlaier	    lflag = Aflag = 0;
100128772Skientzle
1011590Srgrimes	save = argv;
102228669Sjilles	ftsoptions = FTS_PHYSICAL;
103184654Smlaier	savednumber = 0;
104209362Sbrian	threshold = 0;
105209362Sbrian	threshold_sign = 1;
106184733Smlaier	cblocksize = DEV_BSIZE;
107184733Smlaier	blocksize = 0;
10819120Sscrappy	depth = INT_MAX;
10978158Sroam	SLIST_INIT(&ignores);
110128772Skientzle
111238602Sdes	while ((ch = getopt(argc, argv, "AB:HI:LPasd:cghklmnrt:x")) != -1)
1121590Srgrimes		switch (ch) {
113184733Smlaier		case 'A':
114184733Smlaier			Aflag = 1;
115184733Smlaier			break;
116184733Smlaier		case 'B':
117184733Smlaier			errno = 0;
118184733Smlaier			cblocksize = atoi(optarg);
119184733Smlaier			if (errno == ERANGE || cblocksize <= 0) {
120184733Smlaier				warnx("invalid argument to option B: %s",
121184733Smlaier				    optarg);
122184733Smlaier				usage();
123184733Smlaier			}
124184733Smlaier			break;
125184654Smlaier		case 'H':
126184654Smlaier			Hflag = 1;
127228669Sjilles			Lflag = 0;
128184654Smlaier			break;
129184654Smlaier		case 'I':
130184654Smlaier			ignoreadd(optarg);
131184654Smlaier			break;
132184654Smlaier		case 'L':
133184654Smlaier			Lflag = 1;
134228669Sjilles			Hflag = 0;
135184654Smlaier			break;
136184654Smlaier		case 'P':
137228669Sjilles			Hflag = Lflag = 0;
138184654Smlaier			break;
139184654Smlaier		case 'a':
140184654Smlaier			aflag = 1;
141184654Smlaier			break;
142184654Smlaier		case 's':
143184654Smlaier			sflag = 1;
144184654Smlaier			break;
145184654Smlaier		case 'd':
146184654Smlaier			dflag = 1;
147184654Smlaier			errno = 0;
148184654Smlaier			depth = atoi(optarg);
149184654Smlaier			if (errno == ERANGE || depth < 0) {
150184654Smlaier				warnx("invalid argument to option d: %s",
151184654Smlaier				    optarg);
152184654Smlaier				usage();
153184654Smlaier			}
154184654Smlaier			break;
155184654Smlaier		case 'c':
156184654Smlaier			cflag = 1;
157184654Smlaier			break;
158238602Sdes		case 'g':
159238602Sdes			hflag = 0;
160238602Sdes			blocksize = 1073741824;
161238602Sdes			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
2141590Srgrimes	if (Hflag)
2151590Srgrimes		ftsoptions |= FTS_COMFOLLOW;
216228669Sjilles	if (Lflag) {
217228669Sjilles		ftsoptions &= ~FTS_PHYSICAL;
2181590Srgrimes		ftsoptions |= FTS_LOGICAL;
219228669Sjilles	}
2201590Srgrimes
221184733Smlaier	if (!Aflag && (cblocksize % DEV_BSIZE) != 0)
222184733Smlaier		cblocksize = howmany(cblocksize, DEV_BSIZE) * DEV_BSIZE;
223184733Smlaier
224227335Sed	if (aflag + dflag + sflag > 1)
225227335Sed		usage();
226227335Sed	if (sflag)
22732097Sjkh		depth = 0;
2281590Srgrimes
2291590Srgrimes	if (!*argv) {
2301590Srgrimes		argv = save;
23187216Smarkm		argv[0] = dot;
2321590Srgrimes		argv[1] = NULL;
2331590Srgrimes	}
2341590Srgrimes
235184733Smlaier	if (blocksize == 0)
236184733Smlaier		(void)getbsize(&notused, &blocksize);
2371590Srgrimes
238184733Smlaier	if (!Aflag) {
239184733Smlaier		cblocksize /= DEV_BSIZE;
240184733Smlaier		blocksize /= DEV_BSIZE;
241184733Smlaier	}
242184733Smlaier
243209362Sbrian	if (threshold != 0)
244209362Sbrian		threshold = howmany(threshold / DEV_BSIZE * cblocksize,
245209362Sbrian		    blocksize);
246209362Sbrian
24732097Sjkh	rval = 0;
248128772Skientzle
249191677Simp	(void)signal(SIGINFO, siginfo);
250191677Simp
2511590Srgrimes	if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
25232097Sjkh		err(1, "fts_open");
2531590Srgrimes
25432097Sjkh	while ((p = fts_read(fts)) != NULL) {
2551590Srgrimes		switch (p->fts_info) {
256184654Smlaier		case FTS_D:			/* Ignore. */
257184654Smlaier			if (ignorep(p))
258184654Smlaier				fts_set(fts, p, FTS_SKIP);
259184654Smlaier			break;
260184654Smlaier		case FTS_DP:
261184654Smlaier			if (ignorep(p))
2621590Srgrimes				break;
26378158Sroam
264184733Smlaier			curblocks = Aflag ?
265184733Smlaier			    howmany(p->fts_statp->st_size, cblocksize) :
266184733Smlaier			    howmany(p->fts_statp->st_blocks, cblocksize);
267184654Smlaier			p->fts_parent->fts_bignum += p->fts_bignum +=
268184733Smlaier			    curblocks;
269128772Skientzle
270209362Sbrian			if (p->fts_level <= depth && threshold <=
271209362Sbrian			    threshold_sign * howmany(p->fts_bignum *
272209362Sbrian			    cblocksize, blocksize)) {
273184654Smlaier				if (hflag) {
274184733Smlaier					prthumanval(p->fts_bignum);
275184654Smlaier					(void)printf("\t%s\n", p->fts_path);
276184654Smlaier				} else {
277184654Smlaier					(void)printf("%jd\t%s\n",
278184742Smlaier					    (intmax_t)howmany(p->fts_bignum *
279184742Smlaier					    cblocksize, blocksize),
280184742Smlaier					    p->fts_path);
28158601Scharnier				}
282184654Smlaier			}
283191677Simp			if (info) {
284191677Simp				info = 0;
285191677Simp				(void)printf("\t%s\n", p->fts_path);
286191677Simp			}
287184654Smlaier			break;
288184654Smlaier		case FTS_DC:			/* Ignore. */
289184654Smlaier			break;
290184654Smlaier		case FTS_DNR:			/* Warn, continue. */
291184654Smlaier		case FTS_ERR:
292184654Smlaier		case FTS_NS:
293184654Smlaier			warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
294184654Smlaier			rval = 1;
295184654Smlaier			break;
296184654Smlaier		default:
297184654Smlaier			if (ignorep(p))
29832097Sjkh				break;
299184654Smlaier
300184654Smlaier			if (lflag == 0 && p->fts_statp->st_nlink > 1 &&
301184654Smlaier			    linkchk(p))
30232097Sjkh				break;
30378158Sroam
304184733Smlaier			curblocks = Aflag ?
305184733Smlaier			    howmany(p->fts_statp->st_size, cblocksize) :
306184733Smlaier			    howmany(p->fts_statp->st_blocks, cblocksize);
307184733Smlaier
308227335Sed			if (aflag || p->fts_level == 0) {
309184654Smlaier				if (hflag) {
310184733Smlaier					prthumanval(curblocks);
311184654Smlaier					(void)printf("\t%s\n", p->fts_path);
312184654Smlaier				} else {
313184654Smlaier					(void)printf("%jd\t%s\n",
314184742Smlaier					    (intmax_t)howmany(curblocks *
315184742Smlaier					    cblocksize, blocksize),
316184742Smlaier					    p->fts_path);
31758601Scharnier				}
318184654Smlaier			}
31932097Sjkh
320184733Smlaier			p->fts_parent->fts_bignum += curblocks;
3211590Srgrimes		}
322139813Spjd		savednumber = p->fts_parent->fts_bignum;
32332097Sjkh	}
32432097Sjkh
3251590Srgrimes	if (errno)
3261590Srgrimes		err(1, "fts_read");
32732097Sjkh
32858601Scharnier	if (cflag) {
32956597Smharo		if (hflag) {
330184733Smlaier			prthumanval(savednumber);
331184654Smlaier			(void)printf("\ttotal\n");
33256597Smharo		} else {
333184654Smlaier			(void)printf("%jd\ttotal\n", (intmax_t)howmany(
334184733Smlaier			    savednumber * cblocksize, blocksize));
33556597Smharo		}
33658601Scharnier	}
33732097Sjkh
33878158Sroam	ignoreclean();
33928891Swosch	exit(rval);
3401590Srgrimes}
3411590Srgrimes
342128772Skientzlestatic int
343128772Skientzlelinkchk(FTSENT *p)
344128772Skientzle{
345128772Skientzle	struct links_entry {
346128806Skientzle		struct links_entry *next;
347128806Skientzle		struct links_entry *previous;
348128806Skientzle		int	 links;
349128806Skientzle		dev_t	 dev;
350128806Skientzle		ino_t	 ino;
351128772Skientzle	};
352128806Skientzle	static const size_t links_hash_initial_size = 8192;
353128806Skientzle	static struct links_entry **buckets;
354128806Skientzle	static struct links_entry *free_list;
355128806Skientzle	static size_t number_buckets;
356128806Skientzle	static unsigned long number_entries;
357128806Skientzle	static char stop_allocating;
358128806Skientzle	struct links_entry *le, **new_buckets;
359128806Skientzle	struct stat *st;
360128806Skientzle	size_t i, new_size;
361144840Sstefanf	int hash;
36232097Sjkh
363128772Skientzle	st = p->fts_statp;
36432097Sjkh
365128772Skientzle	/* If necessary, initialize the hash table. */
366128772Skientzle	if (buckets == NULL) {
367128772Skientzle		number_buckets = links_hash_initial_size;
368128772Skientzle		buckets = malloc(number_buckets * sizeof(buckets[0]));
369128772Skientzle		if (buckets == NULL)
370128834Skientzle			errx(1, "No memory for hardlink detection");
371128772Skientzle		for (i = 0; i < number_buckets; i++)
372128772Skientzle			buckets[i] = NULL;
373128772Skientzle	}
3741590Srgrimes
375128772Skientzle	/* If the hash table is getting too full, enlarge it. */
376128772Skientzle	if (number_entries > number_buckets * 10 && !stop_allocating) {
377128772Skientzle		new_size = number_buckets * 2;
378128772Skientzle		new_buckets = malloc(new_size * sizeof(struct links_entry *));
379128772Skientzle
380128772Skientzle		/* Try releasing the free list to see if that helps. */
381128772Skientzle		if (new_buckets == NULL && free_list != NULL) {
382128772Skientzle			while (free_list != NULL) {
383128772Skientzle				le = free_list;
384128772Skientzle				free_list = le->next;
385128772Skientzle				free(le);
386128772Skientzle			}
387184654Smlaier			new_buckets = malloc(new_size *
388184654Smlaier			    sizeof(new_buckets[0]));
389128772Skientzle		}
390128772Skientzle
391128772Skientzle		if (new_buckets == NULL) {
392128772Skientzle			stop_allocating = 1;
393128834Skientzle			warnx("No more memory for tracking hard links");
394128772Skientzle		} else {
395128772Skientzle			memset(new_buckets, 0,
396128772Skientzle			    new_size * sizeof(struct links_entry *));
397128772Skientzle			for (i = 0; i < number_buckets; i++) {
398128772Skientzle				while (buckets[i] != NULL) {
399128772Skientzle					/* Remove entry from old bucket. */
400128772Skientzle					le = buckets[i];
401128772Skientzle					buckets[i] = le->next;
402128772Skientzle
403128772Skientzle					/* Add entry to new bucket. */
404128772Skientzle					hash = (le->dev ^ le->ino) % new_size;
405128772Skientzle
406128772Skientzle					if (new_buckets[hash] != NULL)
407128772Skientzle						new_buckets[hash]->previous =
408128772Skientzle						    le;
409128772Skientzle					le->next = new_buckets[hash];
410128772Skientzle					le->previous = NULL;
411128772Skientzle					new_buckets[hash] = le;
412128772Skientzle				}
413128772Skientzle			}
414128772Skientzle			free(buckets);
415128772Skientzle			buckets = new_buckets;
416128772Skientzle			number_buckets = new_size;
417128772Skientzle		}
418128772Skientzle	}
419128772Skientzle
420128772Skientzle	/* Try to locate this entry in the hash table. */
421128772Skientzle	hash = ( st->st_dev ^ st->st_ino ) % number_buckets;
422128772Skientzle	for (le = buckets[hash]; le != NULL; le = le->next) {
423128772Skientzle		if (le->dev == st->st_dev && le->ino == st->st_ino) {
424128772Skientzle			/*
425128772Skientzle			 * Save memory by releasing an entry when we've seen
426128772Skientzle			 * all of it's links.
427128772Skientzle			 */
428128772Skientzle			if (--le->links <= 0) {
429128772Skientzle				if (le->previous != NULL)
430128772Skientzle					le->previous->next = le->next;
431128772Skientzle				if (le->next != NULL)
432128772Skientzle					le->next->previous = le->previous;
433128772Skientzle				if (buckets[hash] == le)
434128772Skientzle					buckets[hash] = le->next;
435128772Skientzle				number_entries--;
436128772Skientzle				/* Recycle this node through the free list */
437128772Skientzle				if (stop_allocating) {
438128772Skientzle					free(le);
439128772Skientzle				} else {
440128772Skientzle					le->next = free_list;
441128772Skientzle					free_list = le;
442128772Skientzle				}
443128772Skientzle			}
444128772Skientzle			return (1);
445128772Skientzle		}
446128772Skientzle	}
447128772Skientzle
448128772Skientzle	if (stop_allocating)
449128772Skientzle		return (0);
450128772Skientzle
451128772Skientzle	/* Add this entry to the links cache. */
452128772Skientzle	if (free_list != NULL) {
453128772Skientzle		/* Pull a node from the free list if we can. */
454128772Skientzle		le = free_list;
455128772Skientzle		free_list = le->next;
456128772Skientzle	} else
457128772Skientzle		/* Malloc one if we have to. */
458128772Skientzle		le = malloc(sizeof(struct links_entry));
459128772Skientzle	if (le == NULL) {
460128772Skientzle		stop_allocating = 1;
461128834Skientzle		warnx("No more memory for tracking hard links");
462128772Skientzle		return (0);
463128772Skientzle	}
464128772Skientzle	le->dev = st->st_dev;
465128772Skientzle	le->ino = st->st_ino;
466128772Skientzle	le->links = st->st_nlink - 1;
467128772Skientzle	number_entries++;
468128772Skientzle	le->next = buckets[hash];
469128772Skientzle	le->previous = NULL;
470128772Skientzle	if (buckets[hash] != NULL)
471128772Skientzle		buckets[hash]->previous = le;
472128772Skientzle	buckets[hash] = le;
4731590Srgrimes	return (0);
4741590Srgrimes}
4751590Srgrimes
476184656Smlaierstatic void
477129678Spjdprthumanval(int64_t bytes)
47856597Smharo{
479129678Spjd	char buf[5];
48056597Smharo
481184733Smlaier	bytes *= cblocksize;
482184733Smlaier	if (!Aflag)
483184733Smlaier		bytes *= DEV_BSIZE;
48456597Smharo
485129678Spjd	humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
486129678Spjd	    HN_B | HN_NOSPACE | HN_DECIMAL);
48756597Smharo
488129678Spjd	(void)printf("%4s", buf);
48956597Smharo}
49056597Smharo
49127099Scharnierstatic void
492100822Sdwmaloneusage(void)
4931590Srgrimes{
4941590Srgrimes	(void)fprintf(stderr,
495238817Spluknet		"usage: du [-Aclnx] [-H | -L | -P] [-g | -h | -k | -m] "
496228356Sgjb		"[-a | -s | -d depth] [-B blocksize] [-I mask] "
497228356Sgjb		"[-t threshold] [file ...]\n");
49856597Smharo	exit(EX_USAGE);
4991590Srgrimes}
50078158Sroam
501184656Smlaierstatic void
502100822Sdwmaloneignoreadd(const char *mask)
50378158Sroam{
50478158Sroam	struct ignentry *ign;
50578158Sroam
50678158Sroam	ign = calloc(1, sizeof(*ign));
50778158Sroam	if (ign == NULL)
50878158Sroam		errx(1, "cannot allocate memory");
50978158Sroam	ign->mask = strdup(mask);
51078158Sroam	if (ign->mask == NULL)
51178158Sroam		errx(1, "cannot allocate memory");
51278158Sroam	SLIST_INSERT_HEAD(&ignores, ign, next);
51378158Sroam}
51478158Sroam
515184656Smlaierstatic void
516100822Sdwmaloneignoreclean(void)
51778158Sroam{
51878158Sroam	struct ignentry *ign;
519321097Sngie
52078158Sroam	while (!SLIST_EMPTY(&ignores)) {
52178158Sroam		ign = SLIST_FIRST(&ignores);
52278158Sroam		SLIST_REMOVE_HEAD(&ignores, next);
52378158Sroam		free(ign->mask);
52478158Sroam		free(ign);
52578158Sroam	}
52678158Sroam}
52778158Sroam
528184656Smlaierstatic int
529100822Sdwmaloneignorep(FTSENT *ent)
53078158Sroam{
53178158Sroam	struct ignentry *ign;
53278158Sroam
533158339Smaxim	if (nodumpflag && (ent->fts_statp->st_flags & UF_NODUMP))
534158339Smaxim		return 1;
53578158Sroam	SLIST_FOREACH(ign, &ignores, next)
53678158Sroam		if (fnmatch(ign->mask, ent->fts_name, 0) != FNM_NOMATCH)
53778158Sroam			return 1;
53878158Sroam	return 0;
53978158Sroam}
540191677Simp
541191677Simpstatic void
542191677Simpsiginfo(int sig __unused)
543191677Simp{
544191677Simp
545191677Simp	info = 1;
546191677Simp}
547