changeset 45:18472a2ccf55

pirollback: pathname reconstruction implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 06 Jul 2013 22:06:38 +0000
parents 074237879eca
children 78ac405716db
files .hgignore pirollback/Makefile pirollback/inopath.c pirollback/pathname.c pirollback/pathname.h
diffstat 5 files changed, 97 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Jul 06 21:31:55 2013 +0000
+++ b/.hgignore	Sat Jul 06 22:06:38 2013 +0000
@@ -14,3 +14,4 @@
 ^mysteryffs/scan1$
 
 ^pirollback/analyze$
+^pirollback/inopath$
--- a/pirollback/Makefile	Sat Jul 06 21:31:55 2013 +0000
+++ b/pirollback/Makefile	Sat Jul 06 22:06:38 2013 +0000
@@ -1,13 +1,17 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	analyze
+PROGS=	analyze inopath
 
 ANALYZE_OBJS=	analyze.o checknames.o init.o treewalk.o
+INOPATH_OBJS=	checknames.o init.o inopath.o pathname.o treewalk.o
 
 all:	${PROGS}
 
 analyze:	${ANALYZE_OBJS}
 	${CC} -o $@ ${ANALYZE_OBJS}
 
+inopath:	${INOPATH_OBJS}
+	${CC} -o $@ ${INOPATH_OBJS}
+
 clean:
 	rm -f *.o *.out *errs ${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pirollback/inopath.c	Sat Jul 06 22:06:38 2013 +0000
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "pathname.h"
+
+extern char *imgfile;
+extern int last_inode;
+
+main(argc, argv)
+	char **argv;
+{
+	int ino;
+	char *strtoul_endp;
+	char pathname[PATHNAME_BUF_SIZE];
+
+	if (argc != 3) {
+usage:		fprintf(stderr, "usage: %s ffs-image inode\n", argv[0]);
+		exit(1);
+	}
+	imgfile = argv[1];
+	ino = strtoul(argv[2], &strtoul_endp, 16);
+	if (!argv[2][0] || *strtoul_endp)
+		goto usage;
+	read_img_file();
+	read_inodes();
+	if (ino < 1 || ino > last_inode) {
+		fprintf(stderr, "%s: bad inode number specified\n", argv[0]);
+		exit(1);
+	}
+	walk_tree();
+	check_object_names();
+	if (pathname_of_inode(ino, pathname) < 0) {
+		fprintf(stderr, "unable to get the pathname\n");
+		exit(1);
+	}
+	printf("%s\n", pathname);
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pirollback/pathname.c	Sat Jul 06 22:06:38 2013 +0000
@@ -0,0 +1,53 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "types.h"
+#include "struct.h"
+#include "pathname.h"
+
+extern struct inode_info inode[];
+
+pathname_of_inode(ino, pnbuf)
+	char *pnbuf;
+{
+	int level, revpath[MAX_DIR_NEST];
+	struct inode_info *inf;
+	char *op;
+
+	for (level = 0; ino != 1; ino = inode[ino].parent) {
+		if (!inode[ino].parent)
+			return(-1);
+		if (level >= MAX_DIR_NEST)
+			return(-1);
+		revpath[level++] = ino;
+	}
+	op = pnbuf;
+	*op++ = '/';
+	while (level) {
+		level--;
+		inf = inode + revpath[level];
+		switch (inf->type) {
+		case 0xE1:
+		case 0xF1:
+			/* good only for the last component */
+			if (!level)
+				break;
+			else
+				return(-1);
+		case 0xF2:
+			/* good for all components */
+			break;
+		default:
+			/* bad */
+			return(-1);
+		}
+		strcpy(op, inf->dataptr);
+		op += strlen(inf->dataptr);
+		if (inf->type == 0xF2)
+			*op++ = '/';
+	}
+	*op = '\0';
+	return(0);
+}
--- a/pirollback/pathname.h	Sat Jul 06 21:31:55 2013 +0000
+++ b/pirollback/pathname.h	Sat Jul 06 22:06:38 2013 +0000
@@ -1,2 +1,3 @@
 #define	MAX_FN_COMPONENT	20
 #define	MAX_DIR_NEST		6
+#define	PATHNAME_BUF_SIZE	((MAX_FN_COMPONENT+1) * MAX_DIR_NEST + 2)