Commit files use separate meta file area.
[idzebra-moved-to-github.git] / bfile / commit.c
1 /*
2  * Copyright (C) 1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: commit.c,v $
7  * Revision 1.3  1995-12-01 16:24:29  adam
8  * Commit files use separate meta file area.
9  *
10  * Revision 1.2  1995/12/01  11:37:24  adam
11  * Cached/commit files implemented as meta-files.
12  *
13  * Revision 1.1  1995/11/30  08:33:13  adam
14  * Started work on commit facility.
15  *
16  */
17
18 #include <assert.h>
19 #include <stdlib.h>
20
21 #include <alexutil.h>
22 #include <mfile.h>
23 #include "cfile.h"
24
25 void cf_commit (CFile cf)
26 {
27     int i, bucket_no;
28     int hash_bytes;
29     struct CFile_ph_bucket *p;
30
31     if (cf->bucket_in_memory)
32     {
33         logf (LOG_FATAL, "Cannot commit potential dirty cache");
34         exit (1);
35     }
36     p = xmalloc (sizeof(*p));
37     hash_bytes = cf->head.hash_size * sizeof(int);
38     bucket_no = (hash_bytes+sizeof(cf->head))/HASH_BSIZE + 2;
39     for (; bucket_no < cf->head.next_bucket; bucket_no++)
40     {
41         if (!mf_read (cf->hash_mf, bucket_no, 0, 0, p))
42         {
43             logf (LOG_FATAL, "read commit hash");
44             exit (1);
45         }
46         for (i = 0; i<HASH_BUCKET && p->vno[i]; i++)
47         {
48             if (!mf_read (cf->block_mf, p->vno[i], 0, 0, cf->iobuf))
49             {
50                 logf (LOG_FATAL, "read commit block");
51                 exit (1);
52             }
53             mf_write (cf->rmf, p->no[i], 0, 0, cf->iobuf);
54         }
55     }
56     xfree (p);
57 }
58