2 * Copyright (C) 1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1996-04-18 16:02:56 adam
8 * Changed logging a bit.
9 * Removed warning message when commiting flat shadow files.
11 * Revision 1.9 1996/04/12 07:01:57 adam
12 * Yet another bug fix (next_block was initialized to 0; now set to 1).
14 * Revision 1.8 1996/02/07 14:03:49 adam
15 * Work on flat indexed shadow files.
17 * Revision 1.7 1996/02/07 10:08:46 adam
18 * Work on flat shadow (not finished yet).
20 * Revision 1.6 1995/12/15 12:36:53 adam
21 * Moved hash file information to union.
22 * Renamed commit files.
24 * Revision 1.5 1995/12/12 15:57:55 adam
25 * Implemented mf_unlink. cf_unlink uses mf_unlink.
27 * Revision 1.4 1995/12/11 09:03:55 adam
28 * New function: cf_unlink.
29 * New member of commit file head: state (0) deleted, (1) hash file.
31 * Revision 1.3 1995/12/01 16:24:29 adam
32 * Commit files use separate meta file area.
34 * Revision 1.2 1995/12/01 11:37:24 adam
35 * Cached/commit files implemented as meta-files.
37 * Revision 1.1 1995/11/30 08:33:13 adam
38 * Started work on commit facility.
49 void cf_unlink (CFile cf)
51 if (cf->bucket_in_memory)
53 logf (LOG_FATAL, "Cannot unlink potential dirty cache");
58 mf_unlink (cf->block_mf);
59 mf_unlink (cf->hash_mf);
63 static void cf_commit_hash (CFile cf)
67 struct CFile_ph_bucket *p;
69 p = xmalloc (sizeof(*p));
70 hash_bytes = cf->head.hash_size * sizeof(int);
71 bucket_no = cf->head.first_bucket;
72 for (; bucket_no < cf->head.next_bucket; bucket_no++)
74 if (!mf_read (cf->hash_mf, bucket_no, 0, 0, p))
76 logf (LOG_FATAL, "read commit hash");
79 for (i = 0; i<HASH_BUCKET && p->vno[i]; i++)
81 if (!mf_read (cf->block_mf, p->vno[i], 0, 0, cf->iobuf))
83 logf (LOG_FATAL, "read commit block");
86 mf_write (cf->rmf, p->no[i], 0, 0, cf->iobuf);
92 static void cf_commit_flat (CFile cf)
98 fp = xmalloc (HASH_BSIZE);
99 for (hno = cf->head.next_bucket; hno < cf->head.flat_bucket; hno++)
101 if (hno == cf->head.flat_bucket-1)
103 for (i = 0; i < (HASH_BSIZE/sizeof(int)); i++)
106 if (!mf_read (cf->hash_mf, hno, 0, 0, fp) &&
107 hno != cf->head.flat_bucket-1)
109 logf (LOG_FATAL, "read index block hno=%d (%d-%d) commit",
110 hno, cf->head.next_bucket, cf->head.flat_bucket-1);
112 for (i = 0; i < (HASH_BSIZE/sizeof(int)); i++)
116 if (!mf_read (cf->block_mf, fp[i], 0, 0, cf->iobuf))
118 logf (LOG_FATAL, "read data block hno=%d (%d-%d) "
119 "i=%d commit block at %d (->%d)",
120 hno, cf->head.next_bucket, cf->head.flat_bucket-1,
124 mf_write (cf->rmf, vno, 0, 0, cf->iobuf);
132 void cf_commit (CFile cf)
135 if (cf->bucket_in_memory)
137 logf (LOG_FATAL, "Cannot commit potential dirty cache");
140 if (cf->head.state == 1)
142 else if (cf->head.state == 2)