diff ffstools/tiffs-rd/cat.c @ 241:c95efd27fb2e

tiffs catino implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 27 Jan 2014 02:59:45 +0000
parents acedd4c88d2e
children
line wrap: on
line diff
--- a/ffstools/tiffs-rd/cat.c	Mon Jan 27 02:32:46 2014 +0000
+++ b/ffstools/tiffs-rd/cat.c	Mon Jan 27 02:59:45 2014 +0000
@@ -168,3 +168,66 @@
 	cat_finish();
 	exit(0);
 }
+
+cmd_catino(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	int c, headino;
+	struct inode_info *inf;
+	struct chunkinfo chi;
+
+	optind = 0;
+	while ((c = getopt(argc, argv, "hv")) != EOF)
+		switch (c) {
+		case 'h':
+			cat_mode = 2;
+			continue;
+		case 'v':
+			cat_mode = 1;
+			continue;
+		default:
+usage:			fprintf(stderr, "usage: catino [-v|-h] ino\n");
+			exit(1);
+		}
+	if (argc != optind + 1)
+		goto usage;
+	headino = strtoul(argv[optind], 0, 16);
+
+	read_ffs_image();
+	find_inode_block();
+	alloc_inode_table();
+	if (!validate_inode(headino)) {
+		fprintf(stderr, "catino: specified inode number is invalid\n");
+		exit(1);
+	}
+	inf = inode_info[headino];
+	switch (inf->type) {
+	case 0x00:
+	case 0xE1:
+	case 0xF1:
+	case 0xF3:
+		break;
+	case 0xF2:
+		fprintf(stderr, "error: the requested object is a directory\n");
+		exit(1);
+	default:
+		fprintf(stderr, "error: unexpected object type %02X\n",
+			inf->type);
+		exit(1);
+	}
+	if (!inf->len) {
+		fprintf(stderr, "error: requested inode has been reclaimed\n");
+		exit(1);
+	}
+	if (!validate_obj_name(headino, 0)) {
+		fprintf(stderr,
+"error: no valid name at the beginning of the requested seghead chunk\n");
+		exit(1);
+	}
+	size_head_chunk(inf, &chi);
+	cat_chunk(&chi);
+	iterate_seg_file(headino, segment_cat_callback, 0L, !inf->type, 0);
+	cat_finish();
+	exit(0);
+}