Cached/commit files implemented as meta-files.
[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.2  1995-12-01 11:37:24  adam
8  * Cached/commit files implemented as meta-files.
9  *
10  * Revision 1.1  1995/11/30  08:33:13  adam
11  * Started work on commit facility.
12  *
13  */
14
15 #include <assert.h>
16 #include <stdlib.h>
17
18 #include <alexutil.h>
19 #include <mfile.h>
20 #include "cfile.h"
21
22 void cf_commit (CFile cf)
23 {
24     int i, r, bucket_no;
25     int hash_bytes;
26     struct CFile_ph_bucket *p;
27
28     if (cf->bucket_in_memory)
29     {
30         logf (LOG_FATAL, "Cannot commit potential dirty cache");
31         exit (1);
32     }
33     p = xmalloc (sizeof(*p));
34     hash_bytes = cf->head.hash_size * sizeof(int);
35     bucket_no = (hash_bytes+sizeof(cf->head))/HASH_BSIZE + 2;
36     for (; bucket_no < cf->head.next_bucket; bucket_no++)
37     {
38         if (!mf_read (cf->hash_mf, bucket_no, 0, 0, p))
39         {
40             logf (LOG_FATAL, "read commit hash");
41             exit (1);
42         }
43         for (i = 0; i<HASH_BUCKET && p->vno[i]; i++)
44         {
45             if (!mf_read (cf->block_mf, p->vno[i], 0, 0, cf->iobuf))
46             {
47                 logf (LOG_FATAL, "read commit block");
48                 exit (1);
49             }
50             mf_write (cf->rmf, p->no[i], 0, 0, cf->iobuf);
51         }
52     }
53     xfree (p);
54 }
55