FreeCalypso > hg > freecalypso-reveng
view mpffs/ls.c @ 33:660b0ea739f3
mpffs-dbgls implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 30 Jun 2013 07:47:49 +0000 |
parents | 0bf037ba4149 |
children | 9bc7f0e03fa8 |
line wrap: on
line source
/* * This module contains the main function and other code specific to mpffs-ls */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include <unistd.h> #include "types.h" #include "struct.h" extern char *imgfile; extern struct objinfo root; extern int verbose; char workpath[512]; 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); } return(accum); } dump_dir(firstent, path_prefix) { int ent; struct objinfo obj; u_long size; for (ent = firstent; ent != 0xFFFF; ent = obj.sibling) { obj.entryno = ent; get_index_entry(&obj); if (!obj.type) /* skip deleted objects w/o further validation */ continue; validate_chunk(&obj); validate_obj_name(&obj); if (path_prefix + strlen(obj.dataptr) + 2 > sizeof workpath) { fprintf(stderr, "handling object at index %x, name \"%s\": path buffer overflow\n", obj.entryno, (char *)obj.dataptr); exit(1); } sprintf(workpath + path_prefix, "/%s", (char *)obj.dataptr); switch (obj.type) { case 0xF2: /* directory */ printf("d %s\n", workpath); dump_dir(obj.descend, strlen(workpath)); continue; case 0xF1: /* regular file */ size = get_file_size(&obj); printf("- %7lu %s\n", size, workpath); continue; case 0xE1: /* special .journal file */ printf("j %7lu %s\n", (u_long) obj.len, workpath); continue; default: printf("%s (index entry #%x): unexpected type %02X; skipping\n", workpath, obj.entryno, obj.type); continue; } } } usage() { fprintf(stderr, "usage: mpffs-ls [options] ffs-image\n"); exit(1); } main(argc, argv) char **argv; { extern int optind; parse_cmdline_options(argc, argv); if (argc - optind != 1) usage(); imgfile = argv[optind]; preliminaries(); dump_dir(root.descend, 0); exit(0); }