annotate mpffs/xtr.c @ 36:390be89892c4

mpffs-xtr ported over
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 30 Jun 2013 17:24:21 +0000
parents
children 7ceab8bfacb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module contains the main function and other code specific to mpffs-xtr
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/file.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <ctype.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <stdlib.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <unistd.h>
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "types.h"
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "struct.h"
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern char *imgfile;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 extern struct objinfo root;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 extern int verbose;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 extern u8 *find_end_of_chunk();
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 char workpath[512];
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 name_safe_for_extract(oi)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 struct objinfo *oi;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 char *s;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 s = (char *)oi->dataptr;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (!isalnum(*s) && *s != '_')
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return(0);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 for (s++; *s; s++)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 if (!isalnum(*s) && *s != '_' && *s != '.')
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 return(0);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 return(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 void
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 dump_head_chunk(fd, ch)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 struct objinfo *ch;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 u8 *endname, *endchunk;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 endname = (u8 *) index((char *)ch->dataptr, '\0') + 1;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 endchunk = find_end_of_chunk(ch);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 if (endchunk <= endname)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 return;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 write(fd, endname, endchunk - endname);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 void
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 dump_extra_chunk(fd, ch)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 struct objinfo *ch;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 u8 *endchunk;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 endchunk = find_end_of_chunk(ch);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 write(fd, ch->dataptr, endchunk - ch->dataptr);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 extract_file(head)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 struct objinfo *head;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 int fd;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 int ent;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 struct objinfo ch;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 fd = open(workpath + 1, O_WRONLY|O_CREAT|O_TRUNC, 0666);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 if (fd < 0) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 perror(workpath + 1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 dump_head_chunk(fd, head);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 for (ent = head->descend; ent != 0xFFFF; ent = ch.descend) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 ch.entryno = ent;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 get_index_entry(&ch);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 if (ch.type != 0xF4) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 fprintf(stderr,
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 "file continuation object at index %x: type %02X != expected F4\n",
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 ent, ch.type);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 validate_chunk(&ch);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 dump_extra_chunk(fd, &ch);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 if (ch.sibling != 0xFFFF)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 printf("warning: file continuation object (index %x) has a non-nil sibling pointer\n",
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 ent);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 close(fd);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 dump_dir(firstent, path_prefix)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 int ent;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 struct objinfo obj;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 for (ent = firstent; ent != 0xFFFF; ent = obj.sibling) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 obj.entryno = ent;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 get_index_entry(&obj);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 if (!obj.type) /* skip deleted objects w/o further validation */
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 validate_chunk(&obj);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 validate_obj_name(&obj);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 if (path_prefix + strlen(obj.dataptr) + 2 > sizeof workpath) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 fprintf(stderr,
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 "handling object at index %x, name \"%s\": path buffer overflow\n",
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 obj.entryno, (char *)obj.dataptr);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 sprintf(workpath + path_prefix, "/%s", (char *)obj.dataptr);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 switch (obj.type) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 case 0xF2:
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 /* directory */
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (verbose)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 printf("dir: %s\n", workpath);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 if (!name_safe_for_extract(&obj)) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 fprintf(stderr,
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 "warning: directory name contains unsafe characters; subtree skipped\n");
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 if (mkdir(workpath + 1, 0777) < 0) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 perror(workpath + 1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 dump_dir(obj.descend, strlen(workpath));
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 case 0xF1:
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 /* regular file */
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 if (verbose)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 printf("file: %s\n", workpath);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 if (!name_safe_for_extract(&obj)) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 fprintf(stderr,
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 "warning: file name contains unsafe characters; file skipped\n");
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 extract_file(&obj);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 case 0xE1:
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 /* special .journal file */
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 if (verbose)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 printf("skipping E1 file: %s\n", workpath);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 default:
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 fprintf(stderr,
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 "warning: %s (index entry #%x): unexpected type %02X; skipping\n",
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 workpath, obj.entryno, obj.type);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 continue;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 usage()
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 fprintf(stderr, "usage: mpffs-xtr [options] ffs-image destdir\n");
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 main(argc, argv)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 char **argv;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 extern int optind;
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 parse_cmdline_options(argc, argv);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 if (argc - optind != 2)
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 usage();
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 imgfile = argv[optind];
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 preliminaries();
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 if (chdir(argv[optind+1]) < 0) {
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 perror(argv[optind+1]);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 exit(1);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 }
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 dump_dir(root.descend, 0);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 exit(0);
390be89892c4 mpffs-xtr ported over
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 }