FreeCalypso > hg > freecalypso-sw
annotate ffstools/tiffs-rd/xtr.c @ 982:461f7ee5f254
fc-olddump: brown paper bag
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Thu, 10 Dec 2015 05:35:42 +0000 |
parents | 66a6f1652909 |
children |
rev | line source |
---|---|
248
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This C module implements the xtr command. |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/file.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <unistd.h> |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include "types.h" |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include "struct.h" |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "globals.h" |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 #include "pathname.h" |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 static void |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 dump_head_chunk(fd, headino) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 struct inode_info *inf = inode_info[headino]; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 struct chunkinfo chi; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 if (size_head_chunk(inf, &chi)) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 write(fd, chi.start, chi.len); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 static void |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 dump_extra_chunk(inf, opaque) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 struct inode_info *inf; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 u_long opaque; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 int fd = (int)opaque; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 struct chunkinfo chi; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 size_extra_chunk(inf, &chi); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 write(fd, chi.start, chi.len); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 extract_file(relpath, headino) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 char *relpath; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 int fd; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 fd = open(relpath, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 if (fd < 0) { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 perror(relpath); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 exit(1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 dump_head_chunk(fd, headino); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 iterate_seg_file(headino, dump_extra_chunk, (u_long)fd, 0, 0); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 close(fd); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 void |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 xtr_tree_callback(pathname, ino, depth) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 char *pathname; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 struct inode_info *inf = inode_info[ino]; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 switch (inf->type) { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 case 0xE1: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 case 0xF1: |
249
66a6f1652909
tiffs xtr: skip /.journal
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
248
diff
changeset
|
63 /* skip /.journal; those who need it can cat it */ |
66a6f1652909
tiffs xtr: skip /.journal
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
248
diff
changeset
|
64 if (strcmp(pathname, "/.journal")) |
66a6f1652909
tiffs xtr: skip /.journal
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
248
diff
changeset
|
65 extract_file(pathname + 1, ino); |
248
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 return; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 case 0xE2: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 case 0xF2: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 if (mkdir(pathname + 1, 0777) < 0) { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 perror(pathname + 1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 exit(1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 return; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 case 0xE3: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 case 0xF3: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 fprintf(stderr, |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 "symlink at %s ignored: symlink extraction not implemented yet\n", |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 pathname); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 return; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 default: |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 fprintf(stderr, |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 "BUG: bad inode byte %02X reached xtr_tree_callback()\n", |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 inf->type); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 exit(1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 cmd_xtr(argc, argv) |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 char **argv; |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 if (argc != 2) { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 fprintf(stderr, "usage: xtr dest-dir\n"); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 exit(1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 read_ffs_image(); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 find_inode_block(); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 alloc_inode_table(); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 find_root_inode(); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 if (chdir(argv[1]) < 0) { |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 perror(argv[1]); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 exit(1); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 } |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 traverse_visible_tree(xtr_tree_callback); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 exit(0); |
10afa4d39a7b
tiffs xtr implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 } |