+ {
+ *vno = hb->ph.vno[i];
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int cf_write_flat(CFile cf, zint no, zint vno)
+{
+ zint hno = (no*sizeof(zint))/HASH_BSIZE;
+ int off = (int) ((no*sizeof(zint)) - hno*HASH_BSIZE);
+
+ hno += cf->head.next_bucket;
+ if (hno >= cf->head.flat_bucket)
+ cf->head.flat_bucket = hno+1;
+ cf->dirty = 1;
+ return mf_write(cf->hash_mf, hno, off, sizeof(zint), &vno);
+}
+
+static int cf_moveto_flat(CFile cf)
+{
+ struct CFile_hash_bucket *p;
+ int j;
+ zint i;
+
+ yaz_log(YLOG_DEBUG, "cf: Moving to flat shadow: %s", cf->rmf->name);
+ yaz_log(YLOG_DEBUG, "cf: hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT " total="
+ ZINT_FORMAT,
+ cf->no_hits, cf->no_miss, cf->bucket_in_memory,
+ cf->head.next_bucket - cf->head.first_bucket);
+ assert(cf->head.state == 1);
+ if (flush_bucket(cf, -1))
+ return -1;
+ assert(cf->bucket_in_memory == 0);
+ p = (struct CFile_hash_bucket *) xmalloc(sizeof(*p));
+ for (i = cf->head.first_bucket; i < cf->head.next_bucket; i++)
+ {
+ if (mf_read(cf->hash_mf, i, 0, 0, &p->ph) != 1)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "read bucket moveto flat");
+ xfree(p);
+ return -1;
+ }
+ for (j = 0; j < HASH_BUCKET && p->ph.vno[j]; j++)
+ {
+ if (cf_write_flat(cf, p->ph.no[j], p->ph.vno[j]))
+ {
+ xfree(p);
+ return -1;
+ }
+ }