changeset 51:e516128db432

pirollback: resurrect file descendant chains
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 24 Jul 2013 21:52:09 +0000
parents 40b1ae2ab2d7
children 103d996ed2d5
files pirollback/rollback.c
diffstat 1 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pirollback/rollback.c	Wed Jul 24 19:50:24 2013 +0000
+++ b/pirollback/rollback.c	Wed Jul 24 21:52:09 2013 +0000
@@ -16,6 +16,7 @@
 extern int last_inode;
 extern int journal_start_ino;
 
+static void
 report_inode(ino)
 {
 	struct inode_info *inf = inode + ino;
@@ -42,6 +43,7 @@
 	printf("reverting #%04X %c %s\n", ino, typechar, pathname);
 }
 
+static void
 unlink_inode(oldino, newino, is_sibling)
 {
 	struct inode_info *inf = inode + oldino;
@@ -62,6 +64,33 @@
 	*flashp = 0xFFFF;
 }
 
+static void
+resurrect_descend_chain(headino, ino)
+{
+	struct inode_info *inf;
+	u8 *typebyte;
+
+	for (; ino; ino = inf->descend) {
+		inf = inode + ino;
+		if (inf->type != 0xF4) {
+			fprintf(stderr,
+			"error: #%x, descendant of #%x, is not of type F4\n",
+				ino, headino);
+			exit(1);
+		}
+		typebyte = &inf->flash->type;
+		if (*typebyte) {
+			fprintf(stderr,
+			"inode #%x to be resurrected: not in deleted state\n",
+				ino);
+			exit(1);
+		}
+		/* undo the zeroing */
+		*typebyte = 0xF4;
+	}
+}
+
+static void
 resurrect_old_ver(oldino, newino)
 {
 	struct inode_info *old = inode + oldino;
@@ -84,6 +113,19 @@
 	}
 	/* undo the zeroing */
 	*typebyte = old->type;
+	/*
+	 * Is there a descendant chain (file continuation chunks)
+	 * to resurrect as well?
+	 */
+	if (!old->descend)
+		return;
+	if (old->type != 0xF1) {
+		fprintf(stderr,
+	"resurrecting inode #%x: unexpected descendant with type != F1\n",
+			oldino);
+		exit(1);
+	}
+	resurrect_descend_chain(oldino, old->descend);
 }
 
 roll_back_inode(ino)