* Sebastian Hammer, Adam Dickmeiss
*
* $Log: cfile.c,v $
- * Revision 1.4 1995-12-01 16:24:28 adam
+ * Revision 1.9 1996-02-07 10:08:43 adam
+ * Work on flat shadow (not finished yet).
+ *
+ * Revision 1.8 1995/12/15 12:36:52 adam
+ * Moved hash file information to union.
+ * Renamed commit files.
+ *
+ * Revision 1.7 1995/12/15 10:35:07 adam
+ * Changed names of commit files.
+ *
+ * Revision 1.6 1995/12/11 09:03:53 adam
+ * New function: cf_unlink.
+ * New member of commit file head: state (0) deleted, (1) hash file.
+ *
+ * Revision 1.5 1995/12/08 16:21:14 adam
+ * Work on commit/update.
+ *
+ * Revision 1.4 1995/12/01 16:24:28 adam
* Commit files use separate meta file area.
*
* Revision 1.3 1995/12/01 11:37:22 adam
CFile cf_open (MFile mf, MFile_area area, const char *fname,
int block_size, int wflag, int *firstp)
{
- char path[256];
+ char path[1024];
int i;
CFile cf = xmalloc (sizeof(*cf));
int hash_bytes;
cf->rmf = mf;
- sprintf (path, "%s.b", fname);
+ sprintf (path, "%s-b", fname);
if (!(cf->block_mf = mf_open (area, path, block_size, wflag)))
{
logf (LOG_FATAL|LOG_ERRNO, "Failed to open %s", path);
exit (1);
}
- sprintf (path, "%s.h", fname);
+ sprintf (path, "%s-i", fname);
if (!(cf->hash_mf = mf_open (area, path, HASH_BSIZE, wflag)))
{
logf (LOG_FATAL|LOG_ERRNO, "Failed to open %s", path);
exit (1);
}
- if (!mf_read (cf->hash_mf, 0, 0, sizeof(cf->head), &cf->head))
+ assert (firstp);
+ if (!mf_read (cf->hash_mf, 0, 0, sizeof(cf->head), &cf->head) ||
+ !cf->head.state)
{
*firstp = 1;
+ cf->head.state = 1;
cf->head.block_size = block_size;
cf->head.hash_size = 401;
hash_bytes = cf->head.hash_size * sizeof(int);
{
*firstp = 0;
assert (cf->head.block_size == block_size);
- assert (cf->head.hash_size > 2 && cf->head.hash_size < 200000);
+ assert (cf->head.hash_size > 2);
hash_bytes = cf->head.hash_size * sizeof(int);
assert (cf->head.next_bucket > 0);
cf->array = xmalloc (hash_bytes);
return p;
}
-int cf_lookup (CFile cf, int no)
+static int cf_lookup_flat (CFile cf, int no)
+{
+ int hno = (no*sizeof(int))/HASH_BSIZE;
+ int off = (no*sizeof(int)) - hno*sizeof(HASH_BSIZE);
+ int vno = 0;
+
+ mf_read (cf->hash_mf, hno+cf->head.next_bucket, off, sizeof(int), &vno);
+ return vno;
+}
+
+static int cf_lookup_hash (CFile cf, int no)
{
int hno = cf_hash (cf, no);
struct CFile_hash_bucket *hb;
return 0;
}
-int cf_new (CFile cf, int no)
+static int cf_lookup (CFile cf, int no)
+{
+ if (cf->head.state > 1)
+ return cf_lookup_flat (cf, no);
+ return cf_lookup_hash (cf, no);
+}
+
+int cf_new_flat (CFile cf, int no)
+{
+ int hno = (no*sizeof(int))/HASH_BSIZE;
+ int off = (no*sizeof(int)) - hno*sizeof(HASH_BSIZE);
+ int vno = (cf->head.next_block)++;
+
+ mf_write (cf->hash_mf, hno+cf->head.next_bucket, off, sizeof(int), &vno);
+ return vno;
+}
+
+static int cf_new_hash (CFile cf, int no)
{
int hno = cf_hash (cf, no);
struct CFile_hash_bucket *hbprev = NULL, *hb = cf->parray[hno];
- int *bucketpp = &cf->array[hno];
- int i;
- int vno = (cf->head.next_block)++;
-
+ int *bucketpp = &cf->array[hno];
+ int i, vno = (cf->head.next_block)++;
+
for (hb = cf->parray[hno]; hb; hb = hb->h_next)
if (!hb->ph.vno[HASH_BUCKET-1])
for (i = 0; i<HASH_BUCKET; i++)
return vno;
}
+int cf_new (CFile cf, int no)
+{
+ if (cf->head.state > 1)
+ return cf_new_flat (cf, no);
+ return cf_new_hash (cf, no);
+}
+
+
int cf_read (CFile cf, int no, int offset, int num, void *buf)
{
int block;