changeset 43:9f4469766c74

pirollback: tree walk implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 06 Jul 2013 20:52:09 +0000
parents 15c2ac2c5c73
children 074237879eca
files pirollback/Makefile pirollback/analyze.c pirollback/treewalk.c
diffstat 3 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pirollback/Makefile	Sat Jul 06 20:16:34 2013 +0000
+++ b/pirollback/Makefile	Sat Jul 06 20:52:09 2013 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2
 PROGS=	analyze
 
-ANALYZE_OBJS=	analyze.o init.o
+ANALYZE_OBJS=	analyze.o init.o treewalk.o
 
 all:	${PROGS}
 
--- a/pirollback/analyze.c	Sat Jul 06 20:16:34 2013 +0000
+++ b/pirollback/analyze.c	Sat Jul 06 20:52:09 2013 +0000
@@ -15,5 +15,7 @@
 	read_img_file();
 	read_inodes();
 	printf("Last inode is #%x\n", last_inode);
+	walk_tree();
+	printf("Tree walk succeeded\n");
 	exit(0);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pirollback/treewalk.c	Sat Jul 06 20:52:09 2013 +0000
@@ -0,0 +1,30 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "types.h"
+#include "struct.h"
+
+extern struct inode_info inode[];
+extern int last_inode;
+
+static void
+walk_level(curlev)
+{
+	int child;
+
+	for (child = inode[curlev].descend; child;
+	     child = inode[child].sibling) {
+		inode[child].parent = curlev;
+		walk_level(child);
+	}
+}
+
+walk_tree()
+{
+	if (inode[1].type != 0xF2 || *(inode[1].dataptr) != '/' ||
+	    inode[1].sibling) {
+		fprintf(stderr, "error: inode #1 is not the active root\n");
+		exit(1);
+	}
+	walk_level(1);
+}