diff ffstools/tiffs-rd/tree.c @ 233:ae9ff2d1e3da

tiffs IVA: basic ls integrated
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 10:54:42 +0000
parents
children 024042383a26
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/tiffs-rd/tree.c	Sun Jan 26 10:54:42 2014 +0000
@@ -0,0 +1,68 @@
+/*
+ * This C module implements operations on the tree level.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "types.h"
+#include "struct.h"
+#include "globals.h"
+#include "pathname.h"
+
+static void
+visible_walk_dir(pathbuf_start, pathbuf_ptr, dirino, depth, callback)
+	char *pathbuf_start, *pathbuf_ptr;
+	void (*callback)();
+{
+	int ndepth = depth + 1;
+	int child;
+	struct inode_info *inf;
+
+	if (depth > MAX_DIR_NEST) {
+		fprintf(stderr,
+			"error: max dir nesting exceeded at inode #%x\n",
+			dirino);
+		return;
+	}
+	for (child = inode_info[dirino]->descend; child; child = inf->sibling) {
+		if (!validate_inode(child)) {
+			fprintf(stderr,
+			"error: walk of visible tree hit invalid inode #%x\n",
+				child);
+			return;
+		}
+		inf = inode_info[child];
+		switch (inf->type) {
+		case 0x00:
+			/* walking the *visible* tree: skip deleted objects */
+			continue;
+		case 0xF4:
+			fprintf(stderr,
+	"warning: directory #%x has child #%x of type segment (F4), skipping\n",
+				dirino, child);
+			continue;
+		}
+		if (!validate_obj_name(child, 0)) {
+			fprintf(stderr,
+		"visible tree walk error: no valid name for inode #%x\n",
+				child);
+			continue;
+		}
+		sprintf(pathbuf_ptr, "/%s", inf->dataptr);
+		callback(pathbuf_start, child, ndepth);
+		if (inf->type == 0xF2)
+			visible_walk_dir(pathbuf_start,
+					 index(pathbuf_ptr, '\0'), child,
+					 ndepth, callback);
+	}
+}
+
+traverse_visible_tree(callback)
+	void (*callback)();
+{
+	char pathbuf[PATHNAME_BUF_SIZE];
+
+	visible_walk_dir(pathbuf, pathbuf, root_inode, 0, callback);
+}