file_cmds-287.11.1.tar.gz
[apple/file_cmds.git] / du / du.c
1 /*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Newcomb.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37 #include <sys/cdefs.h>
38 #ifndef lint
39 __used static const char copyright[] =
40 "@(#) Copyright (c) 1989, 1993, 1994\n\
41 The Regents of the University of California. All rights reserved.\n";
42 #endif /* not lint */
43
44 #ifndef lint
45 #if 0
46 static const char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95";
47 #endif
48 #endif /* not lint */
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD: src/usr.bin/du/du.c,v 1.38 2005/04/09 14:31:40 stefanf Exp $");
51
52 #include <sys/mount.h>
53 #include <sys/param.h>
54 #include <sys/queue.h>
55 #include <sys/stat.h>
56 #include <sys/attr.h>
57
58 #include <err.h>
59 #include <errno.h>
60 #include <fnmatch.h>
61 #include <fts.h>
62 #include <locale.h>
63 #include <math.h>
64 #include <stdint.h>
65 #include <stdio.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #include <sysexits.h>
69 #include <unistd.h>
70
71 #ifdef __APPLE__
72 #include <get_compat.h>
73 #include <sys/sysctl.h>
74 #else
75 #define COMPAT_MODE(func, mode) (1)
76 #endif
77
78 #define KILO_SZ(n) (n)
79 #define MEGA_SZ(n) ((n) * (n))
80 #define GIGA_SZ(n) ((n) * (n) * (n))
81 #define TERA_SZ(n) ((n) * (n) * (n) * (n))
82 #define PETA_SZ(n) ((n) * (n) * (n) * (n) * (n))
83
84 #define KILO_2_SZ (KILO_SZ(1024ULL))
85 #define MEGA_2_SZ (MEGA_SZ(1024ULL))
86 #define GIGA_2_SZ (GIGA_SZ(1024ULL))
87 #define TERA_2_SZ (TERA_SZ(1024ULL))
88 #define PETA_2_SZ (PETA_SZ(1024ULL))
89
90 #define KILO_SI_SZ (KILO_SZ(1000ULL))
91 #define MEGA_SI_SZ (MEGA_SZ(1000ULL))
92 #define GIGA_SI_SZ (GIGA_SZ(1000ULL))
93 #define TERA_SI_SZ (TERA_SZ(1000ULL))
94 #define PETA_SI_SZ (PETA_SZ(1000ULL))
95
96 #define TWO_TB (2LL * 1024LL * 1024LL * 1024LL * 1024LL)
97
98 unsigned long long vals_si [] = {1, KILO_SI_SZ, MEGA_SI_SZ, GIGA_SI_SZ, TERA_SI_SZ, PETA_SI_SZ};
99 unsigned long long vals_base2[] = {1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TERA_2_SZ, PETA_2_SZ};
100 unsigned long long *valp;
101
102 typedef enum { NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX } unit_t;
103
104 int unitp [] = { NONE, KILO, MEGA, GIGA, TERA, PETA };
105
106 SLIST_HEAD(ignhead, ignentry) ignores;
107 struct ignentry {
108 char *mask;
109 SLIST_ENTRY(ignentry) next;
110 };
111
112 static int linkchk(FTSENT *);
113 static int dirlinkchk(FTSENT *);
114 static void usage(void);
115 void prthumanval(double);
116 unit_t unit_adjust(double *);
117 void ignoreadd(const char *);
118 void ignoreclean(void);
119 int ignorep(FTSENT *);
120
121 int
122 main(int argc, char *argv[])
123 {
124 FTS *fts;
125 FTSENT *p;
126 off_t savednumber = 0;
127 long blocksize;
128 int ftsoptions;
129 int listall;
130 int depth;
131 int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
132 char **save;
133 static char dot[] = ".";
134 off_t *ftsnum, *ftsparnum;
135
136 setlocale(LC_ALL, "");
137
138 Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
139
140 save = argv;
141 ftsoptions = FTS_NOCHDIR;
142 depth = INT_MAX;
143 SLIST_INIT(&ignores);
144
145 while ((ch = getopt(argc, argv, "HI:LPasd:cghkmrx")) != -1)
146 switch (ch) {
147 case 'H':
148 Lflag = Pflag = 0;
149 Hflag = 1;
150 break;
151 case 'I':
152 ignoreadd(optarg);
153 break;
154 case 'L':
155 Hflag = Pflag = 0;
156 Lflag = 1;
157 break;
158 case 'P':
159 Hflag = Lflag = 0;
160 Pflag = 1;
161 break;
162 case 'a':
163 aflag = 1;
164 break;
165 case 's':
166 sflag = 1;
167 break;
168 case 'd':
169 dflag = 1;
170 errno = 0;
171 depth = atoi(optarg);
172 if (errno == ERANGE || depth < 0) {
173 warnx("invalid argument to option d: %s", optarg);
174 usage();
175 }
176 break;
177 case 'c':
178 cflag = 1;
179 break;
180 case 'h':
181 putenv("BLOCKSIZE=512");
182 hflag = 1;
183 valp = vals_base2;
184 break;
185 case 'k':
186 hflag = 0;
187 putenv("BLOCKSIZE=1024");
188 break;
189 case 'm':
190 hflag = 0;
191 putenv("BLOCKSIZE=1048576");
192 break;
193 case 'g':
194 hflag = 0;
195 putenv("BLOCKSIZE=1g");
196 break;
197 case 'r': /* Compatibility. */
198 break;
199 case 'x':
200 ftsoptions |= FTS_XDEV;
201 break;
202 case '?':
203 default:
204 usage();
205 }
206
207 // argc -= optind;
208 argv += optind;
209
210 /*
211 * XXX
212 * Because of the way that fts(3) works, logical walks will not count
213 * the blocks actually used by symbolic links. We rationalize this by
214 * noting that users computing logical sizes are likely to do logical
215 * copies, so not counting the links is correct. The real reason is
216 * that we'd have to re-implement the kernel's symbolic link traversing
217 * algorithm to get this right. If, for example, you have relative
218 * symbolic links referencing other relative symbolic links, it gets
219 * very nasty, very fast. The bottom line is that it's documented in
220 * the man page, so it's a feature.
221 */
222
223 if (Hflag + Lflag + Pflag > 1)
224 usage();
225
226 if (Hflag + Lflag + Pflag == 0)
227 Pflag = 1; /* -P (physical) is default */
228
229 if (Hflag)
230 ftsoptions |= FTS_COMFOLLOW;
231
232 if (Lflag)
233 ftsoptions |= FTS_LOGICAL;
234
235 if (Pflag)
236 ftsoptions |= FTS_PHYSICAL;
237
238 listall = 0;
239
240 if (aflag) {
241 if (sflag || dflag)
242 usage();
243 listall = 1;
244 } else if (sflag) {
245 if (dflag)
246 usage();
247 depth = 0;
248 }
249
250 if (!*argv) {
251 argv = save;
252 argv[0] = dot;
253 argv[1] = NULL;
254 }
255
256 (void) getbsize(&notused, &blocksize);
257 blocksize /= 512;
258
259 #ifdef __APPLE__
260 // "du" should not have any side effect on disk usage,
261 // so prevent materializing dataless directories upon traversal
262 rval = 1;
263 (void) sysctlbyname("vfs.nspace.prevent_materialization", NULL, NULL, &rval, sizeof(rval));
264 #endif /* __APPLE__ */
265
266 rval = 0;
267
268 if ((fts = fts_open(argv, ftsoptions, NULL)) == NULL)
269 err(1, "fts_open");
270
271 while ((p = fts_read(fts)) != NULL) {
272 switch (p->fts_info) {
273 case FTS_D:
274 if (ignorep(p) || dirlinkchk(p))
275 fts_set(fts, p, FTS_SKIP);
276 break;
277 case FTS_DP:
278 if (ignorep(p))
279 break;
280
281 ftsparnum = (off_t *)&p->fts_parent->fts_number;
282 ftsnum = (off_t *)&p->fts_number;
283 if (p->fts_statp->st_size < TWO_TB) {
284 ftsparnum[0] += ftsnum[0] += p->fts_statp->st_blocks;
285 } else {
286 ftsparnum[0] += ftsnum[0] += howmany(p->fts_statp->st_size, 512LL);
287 }
288
289 if (p->fts_level <= depth) {
290 if (hflag) {
291 (void) prthumanval(howmany(*ftsnum, blocksize));
292 (void) printf("\t%s\n", p->fts_path);
293 } else {
294 (void) printf("%jd\t%s\n",
295 (intmax_t)howmany(*ftsnum, blocksize),
296 p->fts_path);
297 }
298 }
299 break;
300 case FTS_DC: /* Ignore. */
301 if (COMPAT_MODE("bin/du", "unix2003")) {
302 errx(1, "Can't follow symlink cycle from %s to %s", p->fts_path, p->fts_cycle->fts_path);
303 }
304 break;
305 case FTS_DNR: /* Warn, continue. */
306 case FTS_ERR:
307 case FTS_NS:
308 warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
309 rval = 1;
310 break;
311 case FTS_SLNONE:
312 if (COMPAT_MODE("bin/du", "unix2003")) {
313 struct stat sb;
314 int rc = stat(p->fts_path, &sb);
315 if (rc < 0 && errno == ELOOP) {
316 errx(1, "Too many symlinks at %s", p->fts_path);
317 }
318 }
319 default:
320 if (ignorep(p))
321 break;
322
323 if (p->fts_statp->st_nlink > 1 && linkchk(p))
324 break;
325
326 if (listall || p->fts_level == 0) {
327 if (hflag) {
328 if (p->fts_statp->st_size < TWO_TB) {
329 (void) prthumanval(howmany(p->fts_statp->st_blocks,
330 blocksize));
331 } else {
332 (void) prthumanval(howmany(howmany(p->fts_statp->st_size, 512LL),
333 blocksize));
334 }
335 (void) printf("\t%s\n", p->fts_path);
336 } else {
337 if (p->fts_statp->st_size < TWO_TB) {
338 (void) printf("%jd\t%s\n",
339 (intmax_t)howmany(p->fts_statp->st_blocks, blocksize),
340 p->fts_path);
341 } else {
342 (void) printf("%jd\t%s\n",
343 (intmax_t)howmany(howmany(p->fts_statp->st_size, 512LL), blocksize),
344 p->fts_path);
345 }
346 }
347 }
348
349 ftsparnum = (off_t *)&p->fts_parent->fts_number;
350 if (p->fts_statp->st_size < TWO_TB) {
351 ftsparnum[0] += p->fts_statp->st_blocks;
352 } else {
353 ftsparnum[0] += p->fts_statp->st_size / 512LL;
354 }
355 }
356 savednumber = ((off_t *)&p->fts_parent->fts_number)[0];
357 }
358
359 if (errno)
360 err(1, "fts_read");
361
362 if (cflag) {
363 if (hflag) {
364 (void) prthumanval(howmany(savednumber, blocksize));
365 (void) printf("\ttotal\n");
366 } else {
367 (void) printf("%jd\ttotal\n", (intmax_t)howmany(savednumber, blocksize));
368 }
369 }
370
371 ignoreclean();
372 exit(rval);
373 }
374
375 static int
376 linkchk(FTSENT *p)
377 {
378 struct links_entry {
379 struct links_entry *next;
380 struct links_entry *previous;
381 int links;
382 dev_t dev;
383 ino_t ino;
384 };
385 static const size_t links_hash_initial_size = 8192;
386 static struct links_entry **buckets;
387 static struct links_entry *free_list;
388 static size_t number_buckets;
389 static unsigned long number_entries;
390 static char stop_allocating;
391 struct links_entry *le, **new_buckets;
392 struct stat *st;
393 size_t i, new_size;
394 int hash;
395
396 st = p->fts_statp;
397
398 /* If necessary, initialize the hash table. */
399 if (buckets == NULL) {
400 number_buckets = links_hash_initial_size;
401 buckets = malloc(number_buckets * sizeof(buckets[0]));
402 if (buckets == NULL)
403 errx(1, "No memory for hardlink detection");
404 for (i = 0; i < number_buckets; i++)
405 buckets[i] = NULL;
406 }
407
408 /* If the hash table is getting too full, enlarge it. */
409 if (number_entries > number_buckets * 10 && !stop_allocating) {
410 new_size = number_buckets * 2;
411 new_buckets = malloc(new_size * sizeof(struct links_entry *));
412
413 /* Try releasing the free list to see if that helps. */
414 if (new_buckets == NULL && free_list != NULL) {
415 while (free_list != NULL) {
416 le = free_list;
417 free_list = le->next;
418 free(le);
419 }
420 new_buckets = malloc(new_size * sizeof(new_buckets[0]));
421 }
422
423 if (new_buckets == NULL) {
424 stop_allocating = 1;
425 warnx("No more memory for tracking hard links");
426 } else {
427 memset(new_buckets, 0,
428 new_size * sizeof(struct links_entry *));
429 for (i = 0; i < number_buckets; i++) {
430 while (buckets[i] != NULL) {
431 /* Remove entry from old bucket. */
432 le = buckets[i];
433 buckets[i] = le->next;
434
435 /* Add entry to new bucket. */
436 hash = (le->dev ^ le->ino) % new_size;
437
438 if (new_buckets[hash] != NULL)
439 new_buckets[hash]->previous =
440 le;
441 le->next = new_buckets[hash];
442 le->previous = NULL;
443 new_buckets[hash] = le;
444 }
445 }
446 free(buckets);
447 buckets = new_buckets;
448 number_buckets = new_size;
449 }
450 }
451
452 /* Try to locate this entry in the hash table. */
453 hash = ( st->st_dev ^ st->st_ino ) % number_buckets;
454 for (le = buckets[hash]; le != NULL; le = le->next) {
455 if (le->dev == st->st_dev && le->ino == st->st_ino) {
456 /*
457 * Save memory by releasing an entry when we've seen
458 * all of it's links.
459 */
460 if (--le->links <= 0) {
461 if (le->previous != NULL)
462 le->previous->next = le->next;
463 if (le->next != NULL)
464 le->next->previous = le->previous;
465 if (buckets[hash] == le)
466 buckets[hash] = le->next;
467 number_entries--;
468 /* Recycle this node through the free list */
469 if (stop_allocating) {
470 free(le);
471 } else {
472 le->next = free_list;
473 free_list = le;
474 }
475 }
476 return (1);
477 }
478 }
479
480 if (stop_allocating)
481 return (0);
482
483 /* Add this entry to the links cache. */
484 if (free_list != NULL) {
485 /* Pull a node from the free list if we can. */
486 le = free_list;
487 free_list = le->next;
488 } else
489 /* Malloc one if we have to. */
490 le = malloc(sizeof(struct links_entry));
491 if (le == NULL) {
492 stop_allocating = 1;
493 warnx("No more memory for tracking hard links");
494 return (0);
495 }
496 le->dev = st->st_dev;
497 le->ino = st->st_ino;
498 le->links = st->st_nlink - 1;
499 number_entries++;
500 le->next = buckets[hash];
501 le->previous = NULL;
502 if (buckets[hash] != NULL)
503 buckets[hash]->previous = le;
504 buckets[hash] = le;
505 return (0);
506 }
507
508 static int
509 dirlinkchk(FTSENT *p)
510 {
511 struct links_entry {
512 struct links_entry *next;
513 struct links_entry *previous;
514 int links;
515 dev_t dev;
516 ino_t ino;
517 };
518 static const size_t links_hash_initial_size = 8192;
519 static struct links_entry **buckets;
520 static struct links_entry *free_list;
521 static size_t number_buckets;
522 static unsigned long number_entries;
523 static char stop_allocating;
524 struct links_entry *le, **new_buckets;
525 struct stat *st;
526 size_t i, new_size;
527 int hash;
528 struct attrbuf {
529 int size;
530 int linkcount;
531 } buf;
532 struct attrlist attrList;
533
534 memset(&attrList, 0, sizeof(attrList));
535 attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
536 attrList.dirattr = ATTR_DIR_LINKCOUNT;
537 if (-1 == getattrlist(p->fts_path, &attrList, &buf, sizeof(buf), 0))
538 return 0;
539 if (buf.linkcount == 1)
540 return 0;
541 st = p->fts_statp;
542
543 /* If necessary, initialize the hash table. */
544 if (buckets == NULL) {
545 number_buckets = links_hash_initial_size;
546 buckets = malloc(number_buckets * sizeof(buckets[0]));
547 if (buckets == NULL)
548 errx(1, "No memory for directory hardlink detection");
549 for (i = 0; i < number_buckets; i++)
550 buckets[i] = NULL;
551 }
552
553 /* If the hash table is getting too full, enlarge it. */
554 if (number_entries > number_buckets * 10 && !stop_allocating) {
555 new_size = number_buckets * 2;
556 new_buckets = malloc(new_size * sizeof(struct links_entry *));
557
558 /* Try releasing the free list to see if that helps. */
559 if (new_buckets == NULL && free_list != NULL) {
560 while (free_list != NULL) {
561 le = free_list;
562 free_list = le->next;
563 free(le);
564 }
565 new_buckets = malloc(new_size * sizeof(new_buckets[0]));
566 }
567
568 if (new_buckets == NULL) {
569 stop_allocating = 1;
570 warnx("No more memory for tracking directory hard links");
571 } else {
572 memset(new_buckets, 0,
573 new_size * sizeof(struct links_entry *));
574 for (i = 0; i < number_buckets; i++) {
575 while (buckets[i] != NULL) {
576 /* Remove entry from old bucket. */
577 le = buckets[i];
578 buckets[i] = le->next;
579
580 /* Add entry to new bucket. */
581 hash = (le->dev ^ le->ino) % new_size;
582
583 if (new_buckets[hash] != NULL)
584 new_buckets[hash]->previous =
585 le;
586 le->next = new_buckets[hash];
587 le->previous = NULL;
588 new_buckets[hash] = le;
589 }
590 }
591 free(buckets);
592 buckets = new_buckets;
593 number_buckets = new_size;
594 }
595 }
596
597 /* Try to locate this entry in the hash table. */
598 hash = ( st->st_dev ^ st->st_ino ) % number_buckets;
599 for (le = buckets[hash]; le != NULL; le = le->next) {
600 if (le->dev == st->st_dev && le->ino == st->st_ino) {
601 /*
602 * Save memory by releasing an entry when we've seen
603 * all of it's links.
604 */
605 if (--le->links <= 0) {
606 if (le->previous != NULL)
607 le->previous->next = le->next;
608 if (le->next != NULL)
609 le->next->previous = le->previous;
610 if (buckets[hash] == le)
611 buckets[hash] = le->next;
612 number_entries--;
613 /* Recycle this node through the free list */
614 if (stop_allocating) {
615 free(le);
616 } else {
617 le->next = free_list;
618 free_list = le;
619 }
620 }
621 return (1);
622 }
623 }
624
625 if (stop_allocating)
626 return (0);
627 /* Add this entry to the links cache. */
628 if (free_list != NULL) {
629 /* Pull a node from the free list if we can. */
630 le = free_list;
631 free_list = le->next;
632 } else
633 /* Malloc one if we have to. */
634 le = malloc(sizeof(struct links_entry));
635 if (le == NULL) {
636 stop_allocating = 1;
637 warnx("No more memory for tracking hard links");
638 return (0);
639 }
640 le->dev = st->st_dev;
641 le->ino = st->st_ino;
642 le->links = buf.linkcount - 1;
643 number_entries++;
644 le->next = buckets[hash];
645 le->previous = NULL;
646 if (buckets[hash] != NULL)
647 buckets[hash]->previous = le;
648 buckets[hash] = le;
649 return (0);
650 }
651
652 /*
653 * Output in "human-readable" format. Uses 3 digits max and puts
654 * unit suffixes at the end. Makes output compact and easy to read,
655 * especially on huge disks.
656 *
657 */
658 unit_t
659 unit_adjust(double *val)
660 {
661 double abval;
662 unit_t unit;
663 unsigned int unit_sz;
664
665 abval = fabs(*val);
666
667 unit_sz = abval ? ilogb(abval) / 10 : 0;
668
669 if (unit_sz >= UNIT_MAX) {
670 unit = NONE;
671 } else {
672 unit = unitp[unit_sz];
673 *val /= (double)valp[unit_sz];
674 }
675
676 return (unit);
677 }
678
679 void
680 prthumanval(double bytes)
681 {
682 unit_t unit;
683
684 bytes *= 512;
685 unit = unit_adjust(&bytes);
686
687 if (bytes == 0)
688 (void)printf(" 0B");
689 else if (bytes > 10)
690 (void)printf("%3.0f%c", bytes, "BKMGTPE"[unit]);
691 else
692 (void)printf("%3.1f%c", bytes, "BKMGTPE"[unit]);
693 }
694
695 static void
696 usage(void)
697 {
698 (void)fprintf(stderr,
699 "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] [-I mask] [file ...]\n");
700 exit(EX_USAGE);
701 }
702
703 void
704 ignoreadd(const char *mask)
705 {
706 struct ignentry *ign;
707
708 ign = calloc(1, sizeof(*ign));
709 if (ign == NULL)
710 errx(1, "cannot allocate memory");
711 ign->mask = strdup(mask);
712 if (ign->mask == NULL)
713 errx(1, "cannot allocate memory");
714 SLIST_INSERT_HEAD(&ignores, ign, next);
715 }
716
717 void
718 ignoreclean(void)
719 {
720 struct ignentry *ign;
721
722 while (!SLIST_EMPTY(&ignores)) {
723 ign = SLIST_FIRST(&ignores);
724 SLIST_REMOVE_HEAD(&ignores, next);
725 free(ign->mask);
726 free(ign);
727 }
728 }
729
730 int
731 ignorep(FTSENT *ent)
732 {
733 struct ignentry *ign;
734
735 #ifdef __APPLE__
736 if (S_ISDIR(ent->fts_statp->st_mode) && !strcmp("fd", ent->fts_name)) {
737 struct statfs sfsb;
738 int rc = statfs(ent->fts_accpath, &sfsb);
739 if (rc >= 0 && !strcmp("devfs", sfsb.f_fstypename)) {
740 /* Don't cd into /dev/fd/N since one of those is likely to be
741 the cwd as of the start of du which causes all manner of
742 unpleasant surprises */
743 return 1;
744 }
745 }
746 #endif /* __APPLE__ */
747 SLIST_FOREACH(ign, &ignores, next)
748 if (fnmatch(ign->mask, ent->fts_name, 0) != FNM_NOMATCH)
749 return 1;
750 return 0;
751 }