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