X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=bfile%2Fcommit.c;h=547df668232af6a9af0066010b77ff319e270e1c;hb=7edae22b5d556f3db505615888ef02b950dd5e83;hp=9d53e021cd295230d50c98215a264b8fc0590a67;hpb=bee234a243b7bfc164f7096f35d1bcb98e7b24a9;p=idzebra-moved-to-github.git diff --git a/bfile/commit.c b/bfile/commit.c index 9d53e02..547df66 100644 --- a/bfile/commit.c +++ b/bfile/commit.c @@ -4,7 +4,17 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: commit.c,v $ - * Revision 1.7 1996-02-07 10:08:46 adam + * Revision 1.10 1996-04-18 16:02:56 adam + * Changed logging a bit. + * Removed warning message when commiting flat shadow files. + * + * Revision 1.9 1996/04/12 07:01:57 adam + * Yet another bug fix (next_block was initialized to 0; now set to 1). + * + * Revision 1.8 1996/02/07 14:03:49 adam + * Work on flat indexed shadow files. + * + * Revision 1.7 1996/02/07 10:08:46 adam * Work on flat shadow (not finished yet). * * Revision 1.6 1995/12/15 12:36:53 adam @@ -49,20 +59,16 @@ void cf_unlink (CFile cf) mf_unlink (cf->hash_mf); } -void cf_commit (CFile cf) -{ + +static void cf_commit_hash (CFile cf) +{ int i, bucket_no; int hash_bytes; struct CFile_ph_bucket *p; - if (cf->bucket_in_memory) - { - logf (LOG_FATAL, "Cannot commit potential dirty cache"); - exit (1); - } p = xmalloc (sizeof(*p)); hash_bytes = cf->head.hash_size * sizeof(int); - bucket_no = (hash_bytes+sizeof(cf->head))/HASH_BSIZE + 2; + bucket_no = cf->head.first_bucket; for (; bucket_no < cf->head.next_bucket; bucket_no++) { if (!mf_read (cf->hash_mf, bucket_no, 0, 0, p)) @@ -83,3 +89,57 @@ void cf_commit (CFile cf) xfree (p); } +static void cf_commit_flat (CFile cf) +{ + int *fp; + int hno; + int i, vno = 0; + + fp = xmalloc (HASH_BSIZE); + for (hno = cf->head.next_bucket; hno < cf->head.flat_bucket; hno++) + { + if (hno == cf->head.flat_bucket-1) + { + for (i = 0; i < (HASH_BSIZE/sizeof(int)); i++) + fp[i] = 0; + } + if (!mf_read (cf->hash_mf, hno, 0, 0, fp) && + hno != cf->head.flat_bucket-1) + { + logf (LOG_FATAL, "read index block hno=%d (%d-%d) commit", + hno, cf->head.next_bucket, cf->head.flat_bucket-1); + } + for (i = 0; i < (HASH_BSIZE/sizeof(int)); i++) + { + if (fp[i]) + { + if (!mf_read (cf->block_mf, fp[i], 0, 0, cf->iobuf)) + { + logf (LOG_FATAL, "read data block hno=%d (%d-%d) " + "i=%d commit block at %d (->%d)", + hno, cf->head.next_bucket, cf->head.flat_bucket-1, + i, fp[i], vno); + exit (1); + } + mf_write (cf->rmf, vno, 0, 0, cf->iobuf); + } + vno++; + } + } + xfree (fp); +} + +void cf_commit (CFile cf) +{ + + if (cf->bucket_in_memory) + { + logf (LOG_FATAL, "Cannot commit potential dirty cache"); + exit (1); + } + if (cf->head.state == 1) + cf_commit_hash (cf); + else if (cf->head.state == 2) + cf_commit_flat (cf); +} +