diff ffstools/tiffs-rd/object.c @ 234:024042383a26

tiffs IVA: ls reports file sizes
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 11:47:13 +0000
parents ae9ff2d1e3da
children 317936902be4
line wrap: on
line diff
--- a/ffstools/tiffs-rd/object.c	Sun Jan 26 10:54:42 2014 +0000
+++ b/ffstools/tiffs-rd/object.c	Sun Jan 26 11:47:13 2014 +0000
@@ -2,6 +2,7 @@
  * This C module implements object-level analysis.
  */
 
+#include <sys/types.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -56,3 +57,94 @@
 	inf->byte_after_name = p + 1;
 	return(1);
 }
+
+u8 *
+find_end_of_chunk(inf)
+	struct inode_info *inf;
+{
+	u8 *p;
+	int i;
+
+	p = inf->dataptr + inf->len;
+	for (i = 1; i <= 16; i++) {
+		if (!p[-i])
+			return(p - i);
+		if (p[-i] != 0xFF)
+			break;
+	}
+	fprintf(stderr,
+		"error: chunk @%x (inode #%x): no valid termination found\n",
+		inf->offset, inf->ino);
+	return(p);	/* bogon, allows the rest to continue */
+}
+
+size_head_chunk(inf, chi)
+	struct inode_info *inf;
+	struct chunkinfo *chi;
+{
+	chi->start = inf->byte_after_name;
+	chi->end = find_end_of_chunk(inf);
+	if (chi->start >= chi->end) {
+		chi->len = 0;
+		return(0);
+	} else {
+		chi->len = chi->end - chi->start;
+		return(1);
+	}
+}
+
+size_extra_chunk(inf, chi)
+	struct inode_info *inf;
+	struct chunkinfo *chi;
+{
+	chi->start = inf->dataptr;
+	chi->end = find_end_of_chunk(inf);
+	chi->len = chi->end - chi->start;
+}
+
+void
+iterate_seg_file(seghead, callback, callback_data, deleted)
+	void (*callback)();
+	u_long callback_data;
+{
+	int ino;
+	struct inode_info *inf;
+
+	for (ino = inode_info[seghead]->descend; ino; ino = inf->descend) {
+loop:		if (!validate_inode(ino)) {
+			fprintf(stderr,
+			"error: following seg file hit invalid inode #%x\n",
+				ino);
+			return;
+		}
+		inf = inode_info[ino];
+		switch (inf->type) {
+		case 0xF4:
+			callback(inf, callback_data);
+			continue;
+		case 0x00:
+			if (deleted) {
+				if (inf->len)
+					callback(inf, callback_data);
+				else
+					fprintf(stderr,
+	"error: presumed deleted segment inode #%x has been reclaimed\n",
+						ino);
+				continue;
+			}
+			if (!inf->sibling) {
+				fprintf(stderr,
+	"error: segment object at inode #%x: marked deleted, but no sibling\n",
+					ino);
+				return;
+			}
+			ino = inf->sibling;
+			goto loop;
+		default:
+			fprintf(stderr,
+	"error: inode #%x: unexpected type %02X when expecting segment (F4)\n",
+				ino, inf->type);
+			return;
+		}
+	}
+}