changeset 47:3b6296382e24

pirollback: dumpjournal utility written, works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 07 Jul 2013 06:52:04 +0000
parents 78ac405716db
children 79a0897dee7b
files .hgignore pirollback/Makefile pirollback/dumpjournal.c
diffstat 3 files changed, 71 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Jul 07 06:14:40 2013 +0000
+++ b/.hgignore	Sun Jul 07 06:52:04 2013 +0000
@@ -14,4 +14,5 @@
 ^mysteryffs/scan1$
 
 ^pirollback/analyze$
+^pirollback/dumpjournal$
 ^pirollback/inopath$
--- a/pirollback/Makefile	Sun Jul 07 06:14:40 2013 +0000
+++ b/pirollback/Makefile	Sun Jul 07 06:52:04 2013 +0000
@@ -1,8 +1,10 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	analyze inopath
+PROGS=	analyze dumpjournal inopath
 
 ANALYZE_OBJS=	analyze.o checknames.o init.o journal.o treewalk.o
+DUMPJ_OBJS=	checknames.o dumpjournal.o init.o journal.o pathname.o \
+		treewalk.o
 INOPATH_OBJS=	checknames.o init.o inopath.o pathname.o treewalk.o
 
 all:	${PROGS}
@@ -10,6 +12,9 @@
 analyze:	${ANALYZE_OBJS}
 	${CC} -o $@ ${ANALYZE_OBJS}
 
+dumpjournal:	${DUMPJ_OBJS}
+	${CC} -o $@ ${DUMPJ_OBJS}
+
 inopath:	${INOPATH_OBJS}
 	${CC} -o $@ ${INOPATH_OBJS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pirollback/dumpjournal.c	Sun Jul 07 06:52:04 2013 +0000
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "types.h"
+#include "struct.h"
+#include "pathname.h"
+
+extern char *imgfile;
+extern struct inode_info inode[];
+extern int last_inode;
+extern int journal_start_ino;
+
+dump_inode(ino)
+{
+	struct inode_info *inf;
+	char pathname[PATHNAME_BUF_SIZE];
+	int typechar, delchar;
+
+	inf = inode + ino;
+	switch (inf->type) {
+	case 0xE1:
+		typechar = 'j';
+		break;
+	case 0xF1:
+		typechar = 'f';
+		break;
+	case 0xF2:
+		typechar = 'd';
+		break;
+	case 0xF4:
+		typechar = '.';
+		break;
+	default:
+		fprintf(stderr, "dumping inode #%x: unexpected type %02X\n",
+			ino, inf->type);
+		exit(1);
+	}
+	delchar = inf->flash->type ? ' ' : '~';
+	if (pathname_of_inode(ino, pathname) < 0)
+		strcpy(pathname, "-nopath-");
+	printf("#%04X: %c%c %s\n", ino, typechar, delchar, pathname);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	int ino;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s ffs-image\n", argv[0]);
+		exit(1);
+	}
+	imgfile = argv[1];
+	read_img_file();
+	read_inodes();
+	walk_tree();
+	check_object_names();
+	parse_journal();
+	check_object_names();	/* rerun for "undeleted" objects */
+	for (ino = journal_start_ino; ino <= last_inode; ino++)
+		dump_inode(ino);
+	exit(0);
+}