* 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
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);
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);
* 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"
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;
}
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;
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)
{
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++)
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,
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);
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);
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);
* 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
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;
}
{
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)
{