X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=isamb%2Fisamb.c;h=c9def6abd61ee754edbc969cafa30c0de1e0f578;hb=b037a54d0613cebff411506dd9f54262394642e6;hp=3437fc11c728676f1c6cce15d55bc8bcb9c7bc41;hpb=f026071ff0fbd2df52851b204b0dbcee8b45509d;p=idzebra-moved-to-github.git diff --git a/isamb/isamb.c b/isamb/isamb.c index 3437fc1..c9def6a 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2002, Index Data. * See the file LICENSE for details. * - * $Id: isamb.c,v 1.13 2002-04-30 19:31:09 adam Exp $ + * $Id: isamb.c,v 1.15 2002-05-14 21:12:56 adam Exp $ */ #include #include @@ -85,18 +85,21 @@ ISAMB isamb_open (BFiles bfs, const char *name, int writeflag, ISAMC_M method) for (i = 0; ino_cat; i++) { char fname[DST_BUF_SIZE]; - isamb->file[i].head.first_block = 1; - isamb->file[i].head.last_block = 1; - isamb->file[i].head.block_size = b_size; - isamb->file[i].head.block_max = b_size - ISAMB_DATA_OFFSET; - b_size = b_size * 4; isamb->file[i].head_dirty = 0; sprintf (fname, "%s%c", name, i+'A'); - isamb->file[i].bf = - bf_open (bfs, fname, isamb->file[i].head.block_size, writeflag); + isamb->file[i].bf = bf_open (bfs, fname, b_size, writeflag); - bf_read (isamb->file[i].bf, 0, 0, sizeof(struct ISAMB_head), - &isamb->file[i].head); + if (!bf_read (isamb->file[i].bf, 0, 0, sizeof(struct ISAMB_head), + &isamb->file[i].head)) + { + isamb->file[i].head.first_block = 1; + isamb->file[i].head.last_block = 1; + isamb->file[i].head.block_size = b_size; + isamb->file[i].head.block_max = b_size - ISAMB_DATA_OFFSET; + } + assert (isamb->file[i].head.block_size >= ISAMB_DATA_OFFSET); + isamb->file[i].head_dirty = 0; + b_size = b_size * 4; } return isamb; } @@ -125,7 +128,12 @@ struct ISAMB_block *open_block (ISAMB b, ISAMC_P pos) p->pos = pos; p->cat = pos & 3; p->buf = xmalloc (b->file[cat].head.block_size); - bf_read (b->file[cat].bf, pos/4, 0, 0, p->buf); + if (!bf_read (b->file[cat].bf, pos/4, 0, 0, p->buf)) + { + yaz_log (LOG_FATAL, "read failure for pos=%ld block=%ld", + (long) pos, (long) pos/4); + abort(); + } p->bytes = p->buf + ISAMB_DATA_OFFSET; p->leaf = p->buf[0]; p->size = p->buf[1] + 256 * p->buf[2] - ISAMB_DATA_OFFSET; @@ -378,7 +386,7 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, lookahead_item = 0; more = 0; } - if (max_item && + if (lookahead_item && max_item && (*b->method->compare_item)(max_item, lookahead_item) <= 0) { yaz_log (LOG_LOG, "max_item 1");