- Records p;
- int i, r;
- int version;
-
- p = (Records) xmalloc (sizeof(*p));
- p->compression_method = compression_method;
- p->rw = rw;
- p->tmp_size = 1024;
- p->tmp_buf = (char *) xmalloc (p->tmp_size);
- p->index_fname = "reci";
- p->index_BFile = bf_open (bfs, p->index_fname, 128, rw);
- if (p->index_BFile == NULL)
- {
- logf (LOG_FATAL|LOG_ERRNO, "open %s", p->index_fname);
- exit (1);
- }
- r = bf_read (p->index_BFile, 0, 0, 0, p->tmp_buf);
- switch (r)
- {
- case 0:
- memcpy (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic));
- sprintf (p->head.version, "%3d", REC_VERSION);
- p->head.index_free = 0;
- p->head.index_last = 1;
- p->head.no_records = 0;
- p->head.total_bytes = 0;
- for (i = 0; i<REC_BLOCK_TYPES; i++)
- {
- p->head.block_free[i] = 0;
- p->head.block_last[i] = 1;
- p->head.block_used[i] = 0;
- }
- p->head.block_size[0] = 128;
- p->head.block_move[0] = 0;
- for (i = 1; i<REC_BLOCK_TYPES; i++)
- {
- p->head.block_size[i] = p->head.block_size[i-1] * 4;
- p->head.block_move[i] = p->head.block_size[i] * 24;
- }
- if (rw)
- rec_write_head (p);
- break;
- case 1:
- memcpy (&p->head, p->tmp_buf, sizeof(p->head));
- if (memcmp (p->head.magic, REC_HEAD_MAGIC, sizeof(p->head.magic)))
- {
- logf (LOG_FATAL, "file %s has bad format", p->index_fname);
- exit (1);
- }
- version = atoi (p->head.version);
- if (version != REC_VERSION)
- {
- logf (LOG_FATAL, "file %s is version %d, but version"
- " %d is required", p->index_fname, version, REC_VERSION);
- exit (1);
- }
- break;
- }
- for (i = 0; i<REC_BLOCK_TYPES; i++)
- {
- char str[80];
- sprintf (str, "recd%c", i + 'A');
- p->data_fname[i] = (char *) xmalloc (strlen(str)+1);
- strcpy (p->data_fname[i], str);
- p->data_BFile[i] = NULL;
- }
- for (i = 0; i<REC_BLOCK_TYPES; i++)
- {
- if (!(p->data_BFile[i] = bf_open (bfs, p->data_fname[i],
- p->head.block_size[i],
- rw)))
- {
- logf (LOG_FATAL|LOG_ERRNO, "bf_open %s", p->data_fname[i]);
- exit (1);
- }
- }
- p->cache_max = 400;
- p->cache_cur = 0;
- p->record_cache = (struct record_cache_entry *)
- xmalloc (sizeof(*p->record_cache)*p->cache_max);
- zebra_mutex_init (&p->mutex);
- return p;
-}