- isamb->file[i].head.first_block = ISAMB_CACHE_ENTRY_SIZE/b_size+1;
- isamb->file[i].head.last_block = isamb->file[i].head.first_block;
- isamb->file[i].head.block_size = b_size;
- isamb->file[i].head.block_max = b_size - ISAMB_DATA_OFFSET;
- isamb->file[i].head.free_list = 0;
+ /* got header assume "isamb"major minor len can fit in 16 bytes */
+ zint zint_tmp;
+ int major, minor, len, pos = 0;
+ int left;
+ const char *src = 0;
+ if (memcmp(hbuf, "isamb", 5))
+ {
+ logf(LOG_WARN, "bad isamb header for file %s", fname);
+ return 0;
+ }
+ if (sscanf(hbuf+5, "%d %d %d", &major, &minor, &len) != 3)
+ {
+ logf(LOG_WARN, "bad isamb header for file %s", fname);
+ return 0;
+ }
+ if (major != ISAMB_MAJOR_VERSION)
+ {
+ logf(LOG_WARN, "bad major version for file %s %d, must be %d",
+ fname, major, ISAMB_MAJOR_VERSION);
+ return 0;
+ }
+ for (left = len - b_size; left > 0; left = left - b_size)
+ {
+ pos++;
+ if (!bf_read (isamb->file[i].bf, pos, 0, 0, hbuf + pos*b_size))
+ {
+ logf(LOG_WARN, "truncated isamb header for "
+ "file=%s len=%d pos=%d",
+ fname, len, pos);
+ return 0;
+ }
+ }
+ src = hbuf + 16;
+ decode_ptr(&src, &isamb->file[i].head.first_block);
+ decode_ptr(&src, &isamb->file[i].head.last_block);
+ decode_ptr(&src, &zint_tmp);
+ isamb->file[i].head.block_size = zint_tmp;
+ decode_ptr(&src, &zint_tmp);
+ isamb->file[i].head.block_max = zint_tmp;
+ decode_ptr(&src, &isamb->file[i].head.free_list);