Several bug fixes. Commit system runs now.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 30 Nov 1995 17:00:49 +0000 (17:00 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 30 Nov 1995 17:00:49 +0000 (17:00 +0000)
bfile/Makefile
bfile/bfile.c
bfile/cfile.c
bfile/mfile.c

index aafb05e..b01dd80 100644 (file)
@@ -1,13 +1,13 @@
 # Copyright (C) 1994, Index Data I/S 
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.15 1995-11-30 08:33:09 adam Exp $
+# $Id: Makefile,v 1.16 1995-11-30 17:00:49 adam Exp $
 
 SHELL=/bin/sh
 RANLIB=ranlib
 
 YAZLIB=-lyaz
-YAZINC=
+YAZINC=-I../../yaz/include
 
 INCLUDE=-I../include $(YAZINC)
 #CFLAGS=-g -Wall -pedantic -ansi
index bf73dc3..210946e 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: bfile.c,v $
- * Revision 1.12  1995-11-30 08:33:10  adam
+ * Revision 1.13  1995-11-30 17:00:49  adam
+ * Several bug fixes. Commit system runs now.
+ *
+ * Revision 1.12  1995/11/30  08:33:10  adam
  * Started work on commit facility.
  *
  * Revision 1.11  1995/09/04  12:33:21  adam
@@ -75,7 +78,7 @@ BFile bf_open (const char *name, int block_size, int wflag)
         int first_time;
 
         logf (LOG_LOG, "cf,mf_open %s, cache_name=%s", name, cache_name);
-        tmp->mf = mf_open(0, name, block_size, wflag);
+        tmp->mf = mf_open(0, name, block_size, 0);
         tmp->cf = cf_open(tmp->mf, cache_name, name, block_size, wflag,
                           &first_time);
 
@@ -130,7 +133,7 @@ void bf_commit (const char *name)
         logf (LOG_FATAL|LOG_ERRNO, "cannot open commit %s", name);
         exit (1);
     }
-    while (fscanf (inf, "%s %d", path, &block_size) == 1)
+    while (fscanf (inf, "%s %d", path, &block_size) == 2)
     {
         mf = mf_open(0, path, block_size, 1);
         cf = cf_open(mf, name, path, block_size, 0, &first_time);
index ee11f0f..f11abbd 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: cfile.c,v $
- * Revision 1.1  1995-11-30 08:33:11  adam
+ * Revision 1.2  1995-11-30 17:00:49  adam
+ * Several bug fixes. Commit system runs now.
+ *
+ * Revision 1.1  1995/11/30  08:33:11  adam
  * Started work on commit facility.
  *
  */
 #include <assert.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <alexutil.h>
+#include <stdlib.h>
+#include <string.h>
 
+#include <alexutil.h>
 #include <mfile.h>
 #include "cfile.h"
 
@@ -118,6 +123,7 @@ CFile cf_open (MFile mf, const char *cname, const char *fname,
     cf->max_bucket_in_memory = 200;
     cf->dirty = 0;
     cf->iobuf = xmalloc (cf->head.block_size);
+    memset (cf->iobuf, 0, cf->head.block_size);
     return cf;
 }
 
@@ -222,7 +228,10 @@ static struct CFile_hash_bucket *new_bucket (CFile cf, int *block_no, int hno)
     p = alloc_bucket (cf, *block_no, hno);
 
     for (i = 0; i<HASH_BUCKET; i++)
+    {
         p->ph.vno[i] = 0;
+        p->ph.no[i] = 0;
+    }
     p->ph.next_bucket = 0;
     p->ph.this_bucket = *block_no;
     p->dirty = 1;
@@ -235,21 +244,21 @@ int cf_lookup (CFile cf, int no)
     struct CFile_hash_bucket *hb;
     int block_no, i;
 
-    logf (LOG_LOG, "cf_lookup pass 1");
     for (hb = cf->parray[hno]; hb; hb = hb->h_next)
     {
-        logf (LOG_LOG, "bucket_no=%d", hb->ph.this_bucket);
         for (i = 0; i<HASH_BUCKET && hb->ph.vno[i]; i++)
             if (hb->ph.no[i] == no)
                 return hb->ph.vno[i];
     }
-    logf (LOG_LOG, "cf_lookup pass 2");
     for (block_no = cf->array[hno]; block_no; block_no = hb->ph.next_bucket)
     {
-        logf (LOG_LOG, "bucket_no=%d", block_no);
         for (hb = cf->parray[hno]; hb; hb = hb->h_next)
+        {
             if (hb->ph.this_bucket == block_no)
-                continue;
+                break;
+        }
+        if (hb)
+            continue;
         hb = get_bucket (cf, block_no, hno);
         for (i = 0; i<HASH_BUCKET && hb->ph.vno[i]; i++)
             if (hb->ph.no[i] == no)
@@ -284,8 +293,10 @@ int cf_new (CFile cf, int no)
             {
                 bucketpp = &hb->ph.next_bucket;
                 hbprev = hb;
-                continue;
+                break;
             }
+        if (hb)
+            continue;
         hb = get_bucket (cf, *bucketpp, hno);
         assert (hb);
         for (i = 0; i<HASH_BUCKET; i++)
@@ -309,10 +320,9 @@ int cf_new (CFile cf, int no)
 
 int cf_read (CFile cf, int no, int offset, int num, void *buf)
 {
-    int block, r;
+    int tor, block, r;
     
     assert (cf);
-    logf (LOG_LOG, "cf_read no=%d, offset=%d, num=%d", no, offset, num);
     if (!(block = cf_lookup (cf, no)))
         return -1;
     if (lseek (cf->block_fd, cf->head.block_size * block + offset,
@@ -322,8 +332,9 @@ int cf_read (CFile cf, int no, int offset, int num, void *buf)
               no, block);
         exit (1);
     }
-    r = read (cf->block_fd, buf, num ? num : cf->head.block_size);
-    if (r != cf->head.block_size)
+    tor = num ? num : cf->head.block_size;
+    r = read (cf->block_fd, buf, tor);
+    if (r != tor)
     {
         logf (LOG_FATAL|LOG_ERRNO, "cf_read, read no=%d, block=%d",
               no, block);
@@ -334,11 +345,9 @@ int cf_read (CFile cf, int no, int offset, int num, void *buf)
 
 int cf_write (CFile cf, int no, int offset, int num, const void *buf)
 {
-    int block, r;
+    int block, r, tow;
 
     assert (cf);
-
-    logf (LOG_LOG, "cf_write no=%d, offset=%d, num=%d", no, offset, num);
     if (!(block = cf_lookup (cf, no)))
     {
         block = cf_new (cf, no);
@@ -358,8 +367,10 @@ int cf_write (CFile cf, int no, int offset, int num, const void *buf)
               no, block);
         exit (1);
     }
-    r = write (cf->block_fd, buf, num ? num : cf->head.block_size);
-    if (r != cf->head.block_size)
+
+    tow = num ? num : cf->head.block_size;
+    r = write (cf->block_fd, buf, tow);
+    if (r != tow)
     {
         logf (LOG_FATAL|LOG_ERRNO, "cf_write, read no=%d, block=%d",
               no, block);
index e3beb1f..78528ff 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: mfile.c,v $
- * Revision 1.12  1995-11-24 17:26:11  quinn
+ * Revision 1.13  1995-11-30 17:00:50  adam
+ * Several bug fixes. Commit system runs now.
+ *
+ * Revision 1.12  1995/11/24  17:26:11  quinn
  * Mostly about making some ISAM stuff in the config file optional.
  *
  * Revision 1.11  1995/11/13  09:32:43  quinn
@@ -126,6 +129,8 @@ static int file_position(MFile mf, int pos, int offset)
     if (mf->files[c].fd < 0 && (mf->files[c].fd = open(mf->files[c].path,
        mf->wr ? O_RDWR|O_CREAT : O_RDONLY, 0666)) < 0)
     {
+        if (!mf->wr && errno == ENOENT && off == 0)
+            return -2;
        logf (LOG_FATAL|LOG_ERRNO, "Failed to open %s", mf->files[c].path);
        return -1;
     }
@@ -353,8 +358,11 @@ int mf_read(MFile mf, int no, int offset, int num, void *buf)
 {
     int rd, toread;
 
-    if (file_position(mf, no, offset) < 0)
-       exit(1);
+    if ((rd = file_position(mf, no, offset)) < 0)
+        if (rd == -2)
+            return 0;
+        else
+            exit(1);
     toread = num ? num : mf->blocksize;
     if ((rd = read(mf->files[mf->cur_file].fd, buf, toread)) < 0)
     {