changeset 40:7ceab8bfacb3

mpffs-cat and mpffs-xtr converted to use the new extra chunk handling
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 01 Jul 2013 07:04:01 +0000
parents 9bc7f0e03fa8
children 86a494a5f2b0
files mpffs/cat.c mpffs/xtr.c
diffstat 2 files changed, 16 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mpffs/cat.c	Mon Jul 01 06:49:50 2013 +0000
+++ b/mpffs/cat.c	Mon Jul 01 07:04:01 2013 +0000
@@ -46,9 +46,19 @@
 	}
 }
 
+void
+extra_chunk_callback(obj, opaque)
+	struct objinfo *obj;
+	u_long opaque;
+{
+	struct chunkinfo chi;
+
+	size_extra_chunk(obj, &chi);
+	cat_chunk(&chi);
+}
+
 cat_file(headidx)
 {
-	int ent;
 	struct objinfo obj;
 	struct chunkinfo chi;
 
@@ -62,19 +72,7 @@
 	validate_chunk(&obj);
 	size_head_chunk(&obj, &chi);
 	cat_chunk(&chi);
-	for (ent = obj.descend; ent != 0xFFFF; ent = obj.descend) {
-		obj.entryno = ent;
-		get_index_entry(&obj);
-		if (obj.type != 0xF4) {
-			fprintf(stderr,
-	"file continuation object at index %x: type %02X != expected F4\n",
-				ent, obj.type);
-			exit(1);
-		}
-		validate_chunk(&obj);
-		size_extra_chunk(&obj, &chi);
-		cat_chunk(&chi);
-	}
+	iterate_extra_chunks(obj.descend, extra_chunk_callback, (u_long) 0);
 	if (cat_v)
 		putchar('\n');
 }
--- a/mpffs/xtr.c	Mon Jul 01 06:49:50 2013 +0000
+++ b/mpffs/xtr.c	Mon Jul 01 07:04:01 2013 +0000
@@ -49,9 +49,11 @@
 }
 
 void
-dump_extra_chunk(fd, ch)
+dump_extra_chunk(ch, opaque)
 	struct objinfo *ch;
+	u_long opaque;
 {
+	int fd = (int) opaque;
 	u8 *endchunk;
 
 	endchunk = find_end_of_chunk(ch);
@@ -62,8 +64,6 @@
 	struct objinfo *head;
 {
 	int fd;
-	int ent;
-	struct objinfo ch;
 
 	fd = open(workpath + 1, O_WRONLY|O_CREAT|O_TRUNC, 0666);
 	if (fd < 0) {
@@ -71,21 +71,7 @@
 		exit(1);
 	}
 	dump_head_chunk(fd, head);
-	for (ent = head->descend; ent != 0xFFFF; ent = ch.descend) {
-		ch.entryno = ent;
-		get_index_entry(&ch);
-		if (ch.type != 0xF4) {
-			fprintf(stderr,
-	"file continuation object at index %x: type %02X != expected F4\n",
-				ent, ch.type);
-			exit(1);
-		}
-		validate_chunk(&ch);
-		dump_extra_chunk(fd, &ch);
-		if (ch.sibling != 0xFFFF)
-			printf("warning: file continuation object (index %x) has a non-nil sibling pointer\n",
-				ent);
-	}
+	iterate_extra_chunks(head->descend, dump_extra_chunk, (u_long) fd);
 	close(fd);
 }