comparison pirollback/catino.c @ 49:18fa570685de

pirollback: catino implemented, works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 07 Jul 2013 07:44:03 +0000
parents
children
comparison
equal deleted inserted replaced
48:79a0897dee7b 49:18fa570685de
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <strings.h>
5 #include "types.h"
6 #include "struct.h"
7
8 extern char *imgfile;
9 extern struct inode_info inode[];
10 extern int last_inode;
11 extern int journal_start_ino;
12
13 u8 *
14 find_end_of_chunk(ino)
15 {
16 struct inode_info *ch = inode + ino;
17 u8 *p;
18 int i;
19
20 p = ch->dataptr + ch->len;
21 for (i = 1; i <= 16; i++) {
22 if (!p[-i])
23 return(p - i);
24 if (p[-1] != 0xFF)
25 break;
26 }
27 fprintf(stderr,
28 "chunk starting at %x (inode #%x): no valid termination found\n",
29 ch->offset, ino);
30 exit(1);
31 }
32
33 dump_cont_chain(start)
34 {
35 int ino;
36 struct inode_info *inf;
37 u8 *endp;
38
39 for (ino = start; ino; ino = inf->descend) {
40 inf = inode + ino;
41 if (inf->type != 0xF4) {
42 fprintf(stderr,
43 "continuation chunk #%x does not have type F4\n",
44 ino);
45 exit(1);
46 }
47 endp = find_end_of_chunk(ino);
48 write(1, inf->dataptr, endp - inf->dataptr);
49 }
50 }
51
52 do_cat(ino)
53 {
54 struct inode_info *inf = inode + ino;
55 u8 *endp;
56
57 if (inf->type != 0xF1) {
58 fprintf(stderr, "error: requested inode is not a file\n");
59 exit(1);
60 }
61 endp = find_end_of_chunk(ino);
62 if (endp > inf->byte_after_name)
63 write(1, inf->byte_after_name, endp - inf->byte_after_name);
64 dump_cont_chain(inf->descend);
65 }
66
67 main(argc, argv)
68 char **argv;
69 {
70 int ino;
71 char *strtoul_endp;
72
73 if (argc != 3) {
74 usage: fprintf(stderr, "usage: %s ffs-image inode\n", argv[0]);
75 exit(1);
76 }
77 imgfile = argv[1];
78 ino = strtoul(argv[2], &strtoul_endp, 16);
79 if (!argv[2][0] || *strtoul_endp)
80 goto usage;
81 read_img_file();
82 read_inodes();
83 walk_tree();
84 check_object_names();
85 parse_journal();
86 check_object_names(); /* rerun for "undeleted" objects */
87 if (ino < 1 || ino > last_inode) {
88 fprintf(stderr, "%s: bad inode number specified\n", argv[0]);
89 exit(1);
90 }
91 do_cat(ino);
92 exit(0);
93 }