Moved hash file information to union.
[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.6  1995-12-15 12:36:53  adam
8  * Moved hash file information to union.
9  * Renamed commit files.
10  *
11  * Revision 1.5  1995/12/12  15:57:55  adam
12  * Implemented mf_unlink. cf_unlink uses mf_unlink.
13  *
14  * Revision 1.4  1995/12/11  09:03:55  adam
15  * New function: cf_unlink.
16  * New member of commit file head: state (0) deleted, (1) hash file.
17  *
18  * Revision 1.3  1995/12/01  16:24:29  adam
19  * Commit files use separate meta file area.
20  *
21  * Revision 1.2  1995/12/01  11:37:24  adam
22  * Cached/commit files implemented as meta-files.
23  *
24  * Revision 1.1  1995/11/30  08:33:13  adam
25  * Started work on commit facility.
26  *
27  */
28
29 #include <assert.h>
30 #include <stdlib.h>
31
32 #include <alexutil.h>
33 #include <mfile.h>
34 #include "cfile.h"
35
36 void cf_unlink (CFile cf)
37 {
38     if (cf->bucket_in_memory)
39     {
40         logf (LOG_FATAL, "Cannot unlink potential dirty cache");
41         exit (1);
42     }
43     cf->head.state = 0;
44     cf->dirty = 1;
45     mf_unlink (cf->block_mf);
46     mf_unlink (cf->hash_mf);
47 }
48
49 void cf_commit (CFile cf)
50 {
51     int i, bucket_no;
52     int hash_bytes;
53     struct CFile_ph_bucket *p;
54
55     if (cf->bucket_in_memory)
56     {
57         logf (LOG_FATAL, "Cannot commit potential dirty cache");
58         exit (1);
59     }
60     p = xmalloc (sizeof(*p));
61     hash_bytes = cf->head.u.hash.hash_size * sizeof(int);
62     bucket_no = (hash_bytes+sizeof(cf->head))/HASH_BSIZE + 2;
63     for (; bucket_no < cf->head.u.hash.next_bucket; bucket_no++)
64     {
65         if (!mf_read (cf->hash_mf, bucket_no, 0, 0, p))
66         {
67             logf (LOG_FATAL, "read commit hash");
68             exit (1);
69         }
70         for (i = 0; i<HASH_BUCKET && p->vno[i]; i++)
71         {
72             if (!mf_read (cf->block_mf, p->vno[i], 0, 0, cf->iobuf))
73             {
74                 logf (LOG_FATAL, "read commit block");
75                 exit (1);
76             }
77             mf_write (cf->rmf, p->no[i], 0, 0, cf->iobuf);
78         }
79     }
80     xfree (p);
81 }
82