FreeCalypso > hg > freecalypso-sw
diff 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 |
line wrap: on
line diff
--- a/ffstools/tiffs-rd/basics.c Sat Jan 25 23:56:47 2014 +0000 +++ b/ffstools/tiffs-rd/basics.c Sun Jan 26 00:34:22 2014 +0000 @@ -24,7 +24,7 @@ extern int index_blk_num, root_node_no; extern int verbose; -u_char *image; +u8 *image, *inode_block; read_ffs_image() { @@ -72,3 +72,76 @@ } exit(0); } + +find_inode_block() +{ + int i, abcnt; + u8 *ptr; + + if (index_blk_num >= 0) { + if (index_blk_num >= total_blocks) { + fprintf(stderr, + "invalid block # given with the -a option\n"); + exit(1); + } + ptr = image + index_blk_num * eraseblk_size; + if (bcmp(ptr, tiffs_header, sizeof tiffs_header)) { + fprintf(stderr, + "error: block specified with -a has no TIFFS header\n"); + exit(1); + } + if (ptr[8] != 0xAB) { + fprintf(stderr, + "error: block specified with -a is not an AB block\n"); + exit(1); + } + inode_block = ptr; + return(0); + } + abcnt = 0; + for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) { + if (bcmp(ptr, tiffs_header, sizeof tiffs_header)) { + fprintf(stderr, + "warning: no TIFFS signature in erase block #%d (offset %x)\n", + i, ptr - image); + continue; + } + switch (ptr[8]) { + case 0xAB: + if (verbose) + printf( + "Found AB index in erase block #%d (offset %x)\n", + i, ptr - image); + index_blk_num = i; + inode_block = ptr; + abcnt++; + continue; + case 0xBD: + case 0xBF: + continue; + } + fprintf(stderr, + "warning: unexpected block type/status %02X at offset %x\n", + ptr[8], ptr - image); + } + if (!inode_block) { + fprintf(stderr, + "error: could not find an active inode block in %s\n", + imgfile); + exit(1); + } + if (abcnt > 1) { + fprintf(stderr, + "error: found more than one AB block; use -a\n"); + exit(1); + } + return(0); +} + +cmd_fsinfo() +{ + read_ffs_image(); + find_inode_block(); + printf("Active inode block (AB) is block #%d\n", index_blk_num); + exit(0); +}