zfscheck.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <err.h>
  2. #include <errno.h>
  3. #include <locale.h>
  4. #include <fts.h>
  5. /*
  6. * call 'stat' for each files through a file path hierarchy
  7. * see FTS(3)
  8. *
  9. * zfsCheck.c
  10. */
  11. int
  12. main(int argc, char *argv[])
  13. {
  14. FTS *fts;
  15. FTSENT *p;
  16. int rval = 0;
  17. char *const plist[] = {".", NULL};
  18. setlocale(LC_ALL, "");
  19. /*
  20. * fts:
  21. * No pattern, all files
  22. * process symbolic links, not their target
  23. * do not descend into other devices
  24. * do not reorder
  25. *
  26. */
  27. if ((fts = fts_open(plist, FTS_PHYSICAL | FTS_XDEV, NULL)) == NULL)
  28. err(1, "fts_open");
  29. while ((p = fts_read(fts)) != NULL) {
  30. switch (p->fts_info) {
  31. case FTS_DNR:
  32. /*
  33. * failed to step into a folder
  34. *
  35. */
  36. warnx("can't read %s.\n", p->fts_path);
  37. break;
  38. case FTS_ERR:
  39. case FTS_NS:
  40. /*
  41. * stat failure
  42. *
  43. */
  44. warnc(p->fts_errno, "%s", p->fts_path);
  45. rval = 1;
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. if (errno) {
  52. err(EPERM, "fts_read");
  53. }
  54. fts_close(fts);
  55. return rval;
  56. }