- r = bf_write (p->index_BFile, 0, 0, sizeof(p->head), &p->head);
- if (r)
- {
- logf (LOG_FATAL|LOG_ERRNO, "write head of %s", p->index_fname);
- exit (1);
- }
-}
-
-static void rec_tmp_expand (Records p, int size)
-{
- if (p->tmp_size < size + 2048 ||
- p->tmp_size < p->head.block_size[REC_BLOCK_TYPES-1]*2)
- {
- xfree (p->tmp_buf);
- p->tmp_size = size + p->head.block_size[REC_BLOCK_TYPES-1]*2 + 2048;
- p->tmp_buf = (char *) xmalloc (p->tmp_size);
- }
-}
-
-static int read_indx (Records p, int sysno, void *buf, int itemsize,
- int ignoreError)
-{
- int r;
- int pos = (sysno-1)*itemsize;
-
- r = bf_read (p->index_BFile, 1+pos/128, pos%128, itemsize, buf);
- if (r != 1 && !ignoreError)
- {
- logf (LOG_FATAL|LOG_ERRNO, "read in %s at pos %ld",
- p->index_fname, (long) pos);
- exit (1);
- }
- return r;
-}
-
-static void write_indx (Records p, int sysno, void *buf, int itemsize)
-{
- int pos = (sysno-1)*itemsize;
-
- bf_write (p->index_BFile, 1+pos/128, pos%128, itemsize, buf);
-}
-
-static void rec_release_blocks (Records p, int sysno)
-{
- struct record_index_entry entry;
- int freeblock;
- int block_and_ref[2];
- int dst_type;
- int first = 1;
-
- logf (LOG_LOG, "release_blocks for sysno=%d", sysno);
- if (read_indx (p, sysno, &entry, sizeof(entry), 1) != 1)
- return ;
-
- freeblock = entry.next;
- assert (freeblock > 0);
- dst_type = freeblock & 7;
- assert (dst_type < REC_BLOCK_TYPES);
- freeblock = freeblock / 8;
- while (freeblock)
- {
- if (bf_read (p->data_BFile[dst_type], freeblock, 0,
- sizeof(block_and_ref), block_and_ref) != 1)
- {
- logf (LOG_FATAL|LOG_ERRNO, "read in rec_del_single");
- exit (1);
- }
- if (first)
- {
- block_and_ref[1]--;
- if (block_and_ref[1])
- {
- if (bf_write (p->data_BFile[dst_type], freeblock, 0,
- sizeof(block_and_ref), block_and_ref))
- {
- logf (LOG_FATAL|LOG_ERRNO, "write in rec_del_single");
- exit (1);
- }
- return;
- }
- first = 0;
- }
-
- if (bf_write (p->data_BFile[dst_type], freeblock, 0, sizeof(freeblock),
- &p->head.block_free[dst_type]))
- {
- logf (LOG_FATAL|LOG_ERRNO, "write in rec_del_single");
- exit (1);
- }
- p->head.block_free[dst_type] = freeblock;
- freeblock = block_and_ref[0];
-
- p->head.block_used[dst_type]--;
- }
- p->head.total_bytes -= entry.size;
-}
-
-static void rec_delete_single (Records p, Record rec)
-{
- struct record_index_entry entry;
-
- rec_release_blocks (p, rec->sysno);
-
- entry.next = p->head.index_free;
- entry.size = 0;
- p->head.index_free = rec->sysno;
- write_indx (p, rec->sysno, &entry, sizeof(entry));
-}
-
-static void rec_write_tmp_buf (Records p, int size, int *sysnos);
-
-static void rec_write_single (Records p, Record rec)
-{
-
- int sysnos[2];
- int i, size = 0;
- char *cptr;
-
- logf (LOG_LOG, " rec_write_single !!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- for (i = 0; i < REC_NO_INFO; i++)
- if (!rec->info[i])
- size += sizeof(*rec->size);
- else
- size += sizeof(*rec->size) + rec->size[i];
-
- rec_tmp_expand (p, size);