FreeCalypso > hg > freecalypso-sw
comparison ffstools/tiffs-rd/xtr.c @ 248:10afa4d39a7b
tiffs xtr implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 27 Jan 2014 07:20:53 +0000 |
parents | |
children | 66a6f1652909 |
comparison
equal
deleted
inserted
replaced
247:190121a34b3b | 248:10afa4d39a7b |
---|---|
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 extract_file(pathname + 1, ino); | |
64 return; | |
65 case 0xE2: | |
66 case 0xF2: | |
67 if (mkdir(pathname + 1, 0777) < 0) { | |
68 perror(pathname + 1); | |
69 exit(1); | |
70 } | |
71 return; | |
72 case 0xE3: | |
73 case 0xF3: | |
74 fprintf(stderr, | |
75 "symlink at %s ignored: symlink extraction not implemented yet\n", | |
76 pathname); | |
77 return; | |
78 default: | |
79 fprintf(stderr, | |
80 "BUG: bad inode byte %02X reached xtr_tree_callback()\n", | |
81 inf->type); | |
82 exit(1); | |
83 } | |
84 } | |
85 | |
86 cmd_xtr(argc, argv) | |
87 char **argv; | |
88 { | |
89 if (argc != 2) { | |
90 fprintf(stderr, "usage: xtr dest-dir\n"); | |
91 exit(1); | |
92 } | |
93 read_ffs_image(); | |
94 find_inode_block(); | |
95 alloc_inode_table(); | |
96 find_root_inode(); | |
97 if (chdir(argv[1]) < 0) { | |
98 perror(argv[1]); | |
99 exit(1); | |
100 } | |
101 traverse_visible_tree(xtr_tree_callback); | |
102 exit(0); | |
103 } |