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