--- extract_compressed_fs.c 2008-05-20 23:01:53.000000000 +0200 +++ extract_compressed_fs.c.new 2008-05-20 23:13:09.000000000 +0200 @@ -69,38 +69,30 @@ fprintf(stderr, "%u blocks of size %u. Preamble:\n%s\n", ntohl(head.num_blocks), ntohl(head.block_size), head.preamble); + fprintf(stderr, "Building index, please wait ...\n"); + loff_t all_offsets[ntohl(head.num_blocks)+1]; + unsigned long destlen = ntohl(head.block_size); + loff_t offset,blocksize; for (i = 0; i < ntohl(head.num_blocks); i++) { - int currpos; - unsigned long destlen = ntohl(head.block_size); - loff_t offset[2]; - unsigned int size; - - read(handle, &offset, 2*sizeof(loff_t)); - lseek(handle, -sizeof(loff_t), SEEK_CUR); - - currpos = lseek(handle, 0, SEEK_CUR); - if (lseek(handle, __be64_to_cpu(offset[0]), SEEK_SET) < 0) { - fprintf(stderr, "lseek to %Lu: %s\n", - __be64_to_cpu(offset[0]), strerror(errno)); - exit(1); - } - - size=__be64_to_cpu(offset[1])-__be64_to_cpu(offset[0]); - if (size > ntohl(head.block_size) + ntohl(head.block_size)/1000 - + 12 + 4) { - fprintf(stderr, - "Size %u for block %u (offset %Lu) too big\n", - size, i, __be64_to_cpu(offset[0])); - exit(1); - } - read(handle, buffer, size); - if (lseek(handle, currpos, SEEK_SET) < 0) { - perror("seeking"); - exit(1); + read(handle, &offset, sizeof(loff_t)); + all_offsets[i]=__be64_to_cpu(offset); + } + if (lseek(handle, all_offsets[0], SEEK_SET) < 0) { + fprintf(stderr, "lseek to %Lu: %s\n", + __be64_to_cpu(all_offsets[0]), strerror(errno)); + exit(1); + } + i=1; + while(i %lu\n", - i, size, destlen); + fprintf(stderr, "Block %5u length %6Lu => %lu\n", + i, blocksize , destlen); if (i == 3) { fprintf(stderr, "Block head:%02X%02X%02X%02X%02X%02X%02X%02X\n", @@ -124,7 +116,8 @@ buffer[3070]); } switch (uncompress(clear_buffer, &destlen, - buffer, size)) { + buffer, blocksize)) { + case Z_OK: break; @@ -150,6 +143,7 @@ exit(1); } write(STDOUT_FILENO, clear_buffer, ntohl(head.block_size)); + i++; } return 0; }