changeset 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
files mpffs/common.c mpffs/ls.c mpffs/struct.h
diffstat 3 files changed, 57 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mpffs/common.c	Sun Jun 30 06:28:58 2013 +0000
+++ b/mpffs/common.c	Sun Jun 30 06:59:59 2013 +0000
@@ -311,6 +311,30 @@
 	exit(1);
 }
 
+size_head_chunk(ch, chi)
+	struct objinfo *ch;
+	struct chunkinfo *chi;
+{
+	chi->start = (u8 *) index((char *)ch->dataptr, '\0') + 1;
+	chi->end = find_end_of_chunk(ch);
+	if (chi->start >= chi->end) {
+		chi->len = 0;
+		return(0);
+	} else {
+		chi->len = chi->end - chi->start;
+		return(1);
+	}
+}
+
+size_extra_chunk(ch, chi)
+	struct objinfo *ch;
+	struct chunkinfo *chi;
+{
+	chi->start = ch->dataptr;
+	chi->end = find_end_of_chunk(ch);
+	chi->len = chi->end - chi->start;
+}
+
 find_root_node()
 {
 	struct objinfo obj;
--- 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)
--- a/mpffs/struct.h	Sun Jun 30 06:28:58 2013 +0000
+++ b/mpffs/struct.h	Sun Jun 30 06:59:59 2013 +0000
@@ -21,3 +21,10 @@
 	u16	descend;
 	u16	sibling;
 };
+
+/* chunk location and size info */
+struct chunkinfo {
+	u8	*start;
+	u8	*end;
+	size_t	len;
+};