view pirollback/dumpjournal.c @ 47:3b6296382e24

pirollback: dumpjournal utility written, works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 07 Jul 2013 06:52:04 +0000
parents
children 79a0897dee7b
line wrap: on
line source

#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);
}