+ int r = 0;
+ if (p->isamb)
+ {
+ if (p->isam_p)
+ {
+ char item[256];
+ char *st = item;
+ char untilbuf[sizeof(zint) + 1];
+
+ ISAMB_PP isam_pp = isamb_pp_open(p->isamb, p->isam_p, 1);
+
+ memcpy(untilbuf, &sysno, sizeof(sysno));
+ untilbuf[sizeof(sysno)] = 0;
+ r = isamb_pp_forward(isam_pp, st, untilbuf);
+
+ isamb_pp_close(isam_pp);
+ if (!r)
+ return 0;
+
+ if (item[sizeof(sysno)] != itemsize)
+ {
+ yaz_log(YLOG_WARN, "unexpected entry size %d != %d",
+ item[sizeof(sysno)], itemsize);
+ return 0;
+ }
+ memcpy(buf, item + sizeof(sysno) + 1, itemsize);
+ }
+ }
+ else
+ {
+ zint pos = (sysno-1)*itemsize;
+ int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK);
+ int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */
+
+ if (sz1 > itemsize)
+ sz1 = itemsize; /* no more than itemsize bytes */
+
+ r = bf_read(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf);
+ if (r == 1 && sz1 < itemsize) /* boundary? - must read second part */
+ r = bf_read(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1,
+ (char*) buf + sz1);
+ if (r != 1 && !ignoreError)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "read in %s at pos %ld",
+ p->index_fname, (long) pos);
+ }
+ }
+#if 0
+ {
+ struct record_index_entry *ep = buf;
+ yaz_log(YLOG_LOG, "read r=%d sysno=" ZINT_FORMAT " next=" ZINT_FORMAT
+ " sz=%d", r, sysno, ep->next, ep->size);
+ }
+#endif
+ return r;
+}
+
+struct code_read_data {
+ int no;
+ zint sysno;
+ void *buf;
+ int itemsize;
+ int insert_flag;
+};
+
+int bt_code_read(void *vp, char **dst, int *insertMode)
+{
+ struct code_read_data *s = (struct code_read_data *) vp;
+
+ if (s->no == 0)
+ return 0;
+
+ (s->no)--;
+
+ memcpy(*dst, &s->sysno, sizeof(zint));
+ *dst += sizeof(zint);
+ **dst = s->itemsize;
+ (*dst)++;
+ memcpy(*dst, s->buf, s->itemsize);
+ *dst += s->itemsize;
+ *insertMode = s->insert_flag;
+ return 1;
+}
+
+void recindex_write_indx(recindex_t p, zint sysno, void *buf, int itemsize)
+{
+#if 0
+ yaz_log(YLOG_LOG, "write_indx sysno=" ZINT_FORMAT, sysno);
+#endif
+ if (p->isamb)
+ {
+ struct code_read_data input;
+ ISAMC_I isamc_i;
+
+ input.sysno = sysno;
+ input.buf = buf;
+ input.itemsize = itemsize;
+
+ isamc_i.clientData = &input;
+ isamc_i.read_item = bt_code_read;
+
+ input.no = 1;
+ input.insert_flag = 2;
+ isamb_merge(p->isamb, &p->isam_p, &isamc_i);
+ }
+ else
+ {
+ zint pos = (sysno-1)*itemsize;
+ int off = CAST_ZINT_TO_INT(pos%RIDX_CHUNK);
+ int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */
+
+ if (sz1 > itemsize)
+ sz1 = itemsize; /* no more than itemsize bytes */
+
+ bf_write(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf);
+ if (sz1 < itemsize) /* boundary? must write second part */
+ bf_write(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1,
+ (char*) buf + sz1);
+ }