+ int r;
+
+ zebra_lock_rdwr_rlock (&bf->rdwr_lock);
+ if (bf->cf)
+ {
+ if ((r = cf_read (bf->cf, no, offset, nbytes, buf)) == -1)
+ r = mf_read (bf->mf, no, offset, nbytes, buf);
+ }
+ else
+ r = mf_read (bf->mf, no, offset, nbytes, buf);
+ zebra_lock_rdwr_runlock (&bf->rdwr_lock);
+ return r;
+}
+
+int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf)
+{
+ int r;
+ zebra_lock_rdwr_wlock (&bf->rdwr_lock);
+ if (bf->cf)
+ r = cf_write (bf->cf, no, offset, nbytes, buf);
+ else
+ r = mf_write (bf->mf, no, offset, nbytes, buf);
+ zebra_lock_rdwr_wunlock (&bf->rdwr_lock);
+ return r;
+}
+
+int bf_commitExists (BFiles bfs)
+{
+ FILE *inf;
+
+ inf = open_cache (bfs, "rb");
+ if (inf)
+ {
+ fclose (inf);
+ return 1;
+ }
+ return 0;
+}
+
+void bf_reset (BFiles bfs)
+{
+ if (!bfs)
+ return;
+ mf_reset (bfs->commit_area);
+ mf_reset (bfs->register_area);
+}
+
+void bf_commitExec (BFiles bfs)
+{
+ FILE *inf;
+ int block_size;
+ char path[256];
+ MFile mf;
+ CFile cf;
+ int first_time;
+
+ assert (bfs->commit_area);
+ if (!(inf = open_cache (bfs, "rb")))
+ {
+ yaz_log (YLOG_LOG, "No commit file");
+ return ;
+ }
+ while (fscanf (inf, "%s %d", path, &block_size) == 2)
+ {
+ mf = mf_open (bfs->register_area, path, block_size, 1);
+ cf = cf_open (mf, bfs->commit_area, path, block_size, 0, &first_time);
+
+ cf_commit (cf);
+
+ cf_close (cf);
+ mf_close (mf);
+ }
+ fclose (inf);
+}
+
+void bf_commitClean (BFiles bfs, const char *spec)
+{
+ FILE *inf;
+ int block_size;
+ char path[256];
+ MFile mf;
+ CFile cf;
+ int mustDisable = 0;
+ int firstTime;
+
+ if (!bfs->commit_area)
+ {
+ bf_cache (bfs, spec);
+ mustDisable = 1;
+ }
+
+ if (!(inf = open_cache (bfs, "rb")))
+ return ;
+ while (fscanf (inf, "%s %d", path, &block_size) == 2)
+ {
+ mf = mf_open (bfs->register_area, path, block_size, 0);
+ cf = cf_open (mf, bfs->commit_area, path, block_size, 1, &firstTime);
+ cf_unlink (cf);
+ cf_close (cf);
+ mf_close (mf);
+ }
+ fclose (inf);
+ unlink_cache (bfs);
+ if (mustDisable)
+ bf_cache (bfs, 0);