# HG changeset patch # User Michael Spacefalcon # Date 1372661390 0 # Node ID 9bc7f0e03fa8bc45cf459385d0d368c0d62352b0 # Parent e9c6d6615f323bf082202bcf05b84799c00e5c26 iterate_extra_chunks() function written, mpffs-ls converted to use it diff -r e9c6d6615f32 -r 9bc7f0e03fa8 mpffs/common.c --- a/mpffs/common.c Mon Jul 01 06:28:30 2013 +0000 +++ b/mpffs/common.c Mon Jul 01 06:49:50 2013 +0000 @@ -335,6 +335,39 @@ chi->len = chi->end - chi->start; } +iterate_extra_chunks(first_extra_chunk, callback, callback_data) + void (*callback)(); + u_long callback_data; +{ + int ent; + struct objinfo obj; + + for (ent = first_extra_chunk; ent != 0xFFFF; ent = obj.descend) { +loop: obj.entryno = ent; + get_index_entry(&obj); + switch (obj.type) { + case 0xF4: + validate_chunk(&obj); + callback(&obj, callback_data); + continue; + case 0x00: + if (obj.sibling == 0xFFFF) { + fprintf(stderr, +"file continuation object at index %x: marked deleted, but no sibling\n", + ent); + exit(1); + } + ent = obj.sibling; + goto loop; + default: + fprintf(stderr, + "file continuation object at index %x: unexpected type %02X\n", + ent, obj.type); + exit(1); + } + } +} + find_root_node() { struct objinfo obj; diff -r e9c6d6615f32 -r 9bc7f0e03fa8 mpffs/ls.c --- a/mpffs/ls.c Mon Jul 01 06:28:30 2013 +0000 +++ b/mpffs/ls.c Mon Jul 01 06:49:50 2013 +0000 @@ -18,34 +18,29 @@ char workpath[512]; +void +extra_chunk_callback(obj, opaque) + struct objinfo *obj; + u_long opaque; +{ + size_t *accump = (size_t *) opaque; + struct chunkinfo chi; + + size_extra_chunk(obj, &chi); + *accump += chi.len; +} + size_t get_file_size(head) struct objinfo *head; { - 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); - } + iterate_extra_chunks(head->descend, extra_chunk_callback, + (u_long) &accum); return(accum); }