comparison 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
comparison
equal deleted inserted replaced
29:e96d6862cec0 30:9c3c5a572b57
1 /*
2 * This module contains the main function and other code specific to mpffs-ls
3 */
4
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include "types.h"
13 #include "struct.h"
14
15 extern char *imgfile;
16 extern struct objinfo root;
17 extern int verbose;
18
19 char workpath[512];
20
21 u_long
22 get_file_size(head)
23 struct objinfo *head;
24 {
25 return(0); /* stub, remains to be implemented */
26 }
27
28 dump_dir(firstent, path_prefix)
29 {
30 int ent;
31 struct objinfo obj;
32 u_long size;
33
34 for (ent = firstent; ent != 0xFFFF; ent = obj.sibling) {
35 obj.entryno = ent;
36 get_index_entry(&obj);
37 if (!obj.type) /* skip deleted objects w/o further validation */
38 continue;
39 validate_chunk(&obj);
40 validate_obj_name(&obj);
41 if (path_prefix + strlen(obj.dataptr) + 2 > sizeof workpath) {
42 fprintf(stderr,
43 "handling object at index %x, name \"%s\": path buffer overflow\n",
44 obj.entryno, (char *)obj.dataptr);
45 exit(1);
46 }
47 sprintf(workpath + path_prefix, "/%s", (char *)obj.dataptr);
48 switch (obj.type) {
49 case 0xF2:
50 /* directory */
51 printf("d %s\n", workpath);
52 dump_dir(obj.descend, strlen(workpath));
53 continue;
54 case 0xF1:
55 /* regular file */
56 size = get_file_size(&obj);
57 printf("- %7lu %s\n", size, workpath);
58 continue;
59 case 0xE1:
60 /* special .journal file */
61 printf("j %s\n", workpath);
62 continue;
63 default:
64 printf("%s (index entry #%x): unexpected type %02X; skipping\n",
65 workpath, obj.entryno, obj.type);
66 continue;
67 }
68 }
69 }
70
71 usage()
72 {
73 fprintf(stderr, "usage: mpffs-ls [options] ffs-image\n");
74 exit(1);
75 }
76
77 main(argc, argv)
78 char **argv;
79 {
80 extern int optind;
81
82 parse_cmdline_options(argc, argv);
83 if (argc - optind != 1)
84 usage();
85 imgfile = argv[optind];
86 preliminaries();
87 dump_dir(root.descend, 0);
88 exit(0);
89 }