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