diff mpffs/ls.c @ 31:3cca8070ef0f

mpffs-ls reports file sizes
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Jun 2013 06:59:59 +0000
parents 9c3c5a572b57
children 0bf037ba4149
line wrap: on
line diff
--- a/mpffs/ls.c	Sun Jun 30 06:28:58 2013 +0000
+++ b/mpffs/ls.c	Sun Jun 30 06:59:59 2013 +0000
@@ -18,11 +18,35 @@
 
 char workpath[512];
 
-u_long
+size_t
 get_file_size(head)
 	struct objinfo *head;
 {
-	return(0);	/* stub, remains to be implemented */
+	int ent;
+	struct objinfo ch;
+	struct chunkinfo chi;
+	size_t accum;
+
+	size_head_chunk(head, &chi);
+	accum = chi.len;
+	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);
+			break;
+		}
+		validate_chunk(&ch);
+		size_extra_chunk(&ch, &chi);
+		accum += chi.len;
+		if (ch.sibling != 0xFFFF)
+			fprintf(stderr,
+"warning: file continuation object (index %x) has a non-nil sibling pointer\n",
+				ent);
+	}
+	return(accum);
 }
 
 dump_dir(firstent, path_prefix)