2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.18 1996-01-02 08:59:06 quinn
8 * Changed "commit" setting to "shadow".
10 * Revision 1.17 1995/12/11 09:03:51 adam
11 * New function: cf_unlink.
12 * New member of commit file head: state (0) deleted, (1) hash file.
14 * Revision 1.16 1995/12/08 16:21:13 adam
15 * Work on commit/update.
17 * Revision 1.15 1995/12/01 16:24:28 adam
18 * Commit files use separate meta file area.
20 * Revision 1.14 1995/12/01 11:37:21 adam
21 * Cached/commit files implemented as meta-files.
23 * Revision 1.13 1995/11/30 17:00:49 adam
24 * Several bug fixes. Commit system runs now.
26 * Revision 1.12 1995/11/30 08:33:10 adam
27 * Started work on commit facility.
29 * Revision 1.11 1995/09/04 12:33:21 adam
30 * Various cleanup. YAZ util used instead.
32 * Revision 1.10 1994/08/25 10:15:54 quinn
35 * Revision 1.9 1994/08/24 08:45:48 quinn
38 * Revision 1.8 1994/08/23 15:03:34 quinn
39 * *** empty log message ***
41 * Revision 1.7 1994/08/23 14:25:45 quinn
42 * Added O_CREAT because some geek wanted it. Sheesh.
44 * Revision 1.6 1994/08/23 14:21:38 quinn
47 * Revision 1.5 1994/08/18 08:10:08 quinn
50 * Revision 1.4 1994/08/17 14:27:32 quinn
53 * Revision 1.2 1994/08/17 14:09:32 quinn
54 * Compiles cleanly (still only dummy).
56 * Revision 1.1 1994/08/17 13:55:08 quinn
57 * New blocksystem. dummy only
70 static MFile_area commit_area = NULL;
72 void bf_cache (int enableFlag)
77 if (res_get (common_resource, "shadow"))
78 commit_area = mf_init ("shadow");
81 logf (LOG_FATAL, "Shadow area must be defined if commit"
90 int bf_close (BFile bf)
99 BFile bf_open (const char *name, int block_size, int wflag)
101 BFile tmp = xmalloc(sizeof(BFile_struct));
108 logf (LOG_LOG, "cf,mf_open %s", name);
110 tmp->mf = mf_open (0, name, block_size, 0);
111 tmp->cf = cf_open (tmp->mf, commit_area, name, block_size,
115 outf = fopen ("cache", "a");
116 fprintf (outf, "%s %d\n", name, block_size);
122 tmp->mf = mf_open(0, name, block_size, wflag);
127 logf (LOG_FATAL, "mf_open failed for %s", name);
134 int bf_read (BFile bf, int no, int offset, int num, void *buf)
138 if (bf->cf && (r=cf_read (bf->cf, no, offset, num, buf)) != -1)
140 return mf_read (bf->mf, no, offset, num, buf);
143 int bf_write (BFile bf, int no, int offset, int num, const void *buf)
146 return cf_write (bf->cf, no, offset, num, buf);
147 return mf_write (bf->mf, no, offset, num, buf);
150 int bf_commitExists (void)
154 inf = fopen ("cache", "r");
163 void bf_commitExec (void)
172 assert (commit_area);
173 if (!(inf = fopen ("cache", "r")))
175 logf (LOG_LOG, "No commit file");
178 while (fscanf (inf, "%s %d", path, &block_size) == 2)
180 mf = mf_open (0, path, block_size, 1);
181 cf = cf_open (mf, commit_area, path, block_size, 0, &first_time);
191 void bf_commitClean (void)
207 if (!(inf = fopen ("cache", "r")))
209 while (fscanf (inf, "%s %d", path, &block_size) == 2)
211 mf = mf_open (0, path, block_size, 0);
212 cf = cf_open (mf, commit_area, path, block_size, 1, &firstTime);