comparison ffstools/tiffs-rd/basics.c @ 230:ffaa033e7643

tiffs IVA: find_inode_block() integrated
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 26 Jan 2014 00:34:22 +0000
parents 24ed817dd25d
children 5ceacdbd4490
comparison
equal deleted inserted replaced
229:24ed817dd25d 230:ffaa033e7643
22 extern int total_blocks; 22 extern int total_blocks;
23 extern u32 total_ffs_size; 23 extern u32 total_ffs_size;
24 extern int index_blk_num, root_node_no; 24 extern int index_blk_num, root_node_no;
25 extern int verbose; 25 extern int verbose;
26 26
27 u_char *image; 27 u8 *image, *inode_block;
28 28
29 read_ffs_image() 29 read_ffs_image()
30 { 30 {
31 int fd; 31 int fd;
32 struct stat st; 32 struct stat st;
70 printf("age %02X%02X, type/status %02X\n", 70 printf("age %02X%02X, type/status %02X\n",
71 blkhdr[7], blkhdr[6], blkhdr[8]); 71 blkhdr[7], blkhdr[6], blkhdr[8]);
72 } 72 }
73 exit(0); 73 exit(0);
74 } 74 }
75
76 find_inode_block()
77 {
78 int i, abcnt;
79 u8 *ptr;
80
81 if (index_blk_num >= 0) {
82 if (index_blk_num >= total_blocks) {
83 fprintf(stderr,
84 "invalid block # given with the -a option\n");
85 exit(1);
86 }
87 ptr = image + index_blk_num * eraseblk_size;
88 if (bcmp(ptr, tiffs_header, sizeof tiffs_header)) {
89 fprintf(stderr,
90 "error: block specified with -a has no TIFFS header\n");
91 exit(1);
92 }
93 if (ptr[8] != 0xAB) {
94 fprintf(stderr,
95 "error: block specified with -a is not an AB block\n");
96 exit(1);
97 }
98 inode_block = ptr;
99 return(0);
100 }
101 abcnt = 0;
102 for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) {
103 if (bcmp(ptr, tiffs_header, sizeof tiffs_header)) {
104 fprintf(stderr,
105 "warning: no TIFFS signature in erase block #%d (offset %x)\n",
106 i, ptr - image);
107 continue;
108 }
109 switch (ptr[8]) {
110 case 0xAB:
111 if (verbose)
112 printf(
113 "Found AB index in erase block #%d (offset %x)\n",
114 i, ptr - image);
115 index_blk_num = i;
116 inode_block = ptr;
117 abcnt++;
118 continue;
119 case 0xBD:
120 case 0xBF:
121 continue;
122 }
123 fprintf(stderr,
124 "warning: unexpected block type/status %02X at offset %x\n",
125 ptr[8], ptr - image);
126 }
127 if (!inode_block) {
128 fprintf(stderr,
129 "error: could not find an active inode block in %s\n",
130 imgfile);
131 exit(1);
132 }
133 if (abcnt > 1) {
134 fprintf(stderr,
135 "error: found more than one AB block; use -a\n");
136 exit(1);
137 }
138 return(0);
139 }
140
141 cmd_fsinfo()
142 {
143 read_ffs_image();
144 find_inode_block();
145 printf("Active inode block (AB) is block #%d\n", index_blk_num);
146 exit(0);
147 }