Browse Source

zfs check

patron 10 months ago
parent
commit
eac6bf0a32
3 changed files with 95 additions and 0 deletions
  1. 25 0
      zfscheck/LICENSE
  2. 7 0
      zfscheck/Makefile
  3. 63 0
      zfscheck/zfscheck.c

+ 25 - 0
zfscheck/LICENSE

@@ -0,0 +1,25 @@
+BSD 2-Clause License
+
+Copyright (c) 2017, David Marec
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* 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.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.

+ 7 - 0
zfscheck/Makefile

@@ -0,0 +1,7 @@
+PROG=   zfscheck
+NO_OBJ=yes
+#MK_DEBUG_FILES= no
+#MK_ASSERT_DEBUG= no
+SRCS= zfscheck.c 
+MAN= 
+.include <bsd.prog.mk>

+ 63 - 0
zfscheck/zfscheck.c

@@ -0,0 +1,63 @@
+#include <err.h>
+#include <errno.h>
+#include <locale.h>
+#include <fts.h>
+
+/*
+ * call 'stat' for each files through a file path hierarchy
+ * see FTS(3)
+ * 
+ * zfsCheck.c
+ */
+
+int
+main(int argc, char *argv[])
+{
+
+	FTS            *fts;
+	FTSENT         *p;
+	int		rval = 0;
+	char           *const plist[] = {".", NULL};
+
+	setlocale(LC_ALL, "");
+	/*
+	 * fts:
+	 * No pattern, all files
+	 * process symbolic links, not their target
+	 * do not descend into other devices
+	 * do not reorder
+	 *
+	 */
+	if ((fts = fts_open(plist, FTS_PHYSICAL | FTS_XDEV, NULL)) == NULL)
+		err(1, "fts_open");
+
+	while ((p = fts_read(fts)) != NULL) {
+		switch (p->fts_info) {
+			case FTS_DNR:
+				/*
+				 * failed to step into a folder
+				 * 
+				 */
+				warnx("can't read %s.\n", p->fts_path);
+				break;
+			case FTS_ERR:
+			case FTS_NS:
+				/*
+				 * stat failure
+				 * 
+				 */
+				warnc(p->fts_errno, "%s", p->fts_path);
+				rval = 1;
+				break;
+			default:
+				break;
+		}
+	}
+
+	if (errno) {
+		err(EPERM, "fts_read");
+	}
+	fts_close(fts);
+
+	return rval;
+}