FreeCalypso > hg > freecalypso-reveng
diff mpffs/ls.c @ 30:9c3c5a572b57
mpffs-ls works with the length code stubbed out
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 30 Jun 2013 06:28:58 +0000 |
parents | |
children | 3cca8070ef0f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpffs/ls.c Sun Jun 30 06:28:58 2013 +0000 @@ -0,0 +1,89 @@ +/* + * 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]; + +u_long +get_file_size(head) + struct objinfo *head; +{ + return(0); /* stub, remains to be implemented */ +} + +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 %s\n", 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); +}