FreeCalypso > hg > freecalypso-reveng
changeset 39:9bc7f0e03fa8
iterate_extra_chunks() function written, mpffs-ls converted to use it
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jul 2013 06:49:50 +0000 |
parents | e9c6d6615f32 |
children | 7ceab8bfacb3 |
files | mpffs/common.c mpffs/ls.c |
diffstat | 2 files changed, 47 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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); }