X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Frecindex.c;h=10327c0d6ca0a9a3cf18edca08cc739fd612e0ef;hb=a9eae0225b1a51b0257f80d9da9f95475dd04f53;hp=64eea73eb8c48cf99d051b34eb38fde5eb032127;hpb=1bb217ab477284fd7fee47f19a6e8a780fa2bb50;p=idzebra-moved-to-github.git diff --git a/index/recindex.c b/index/recindex.c index 64eea73..10327c0 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -1,4 +1,4 @@ -/* $Id: recindex.c,v 1.36 2004-08-06 12:28:22 adam Exp $ +/* $Id: recindex.c,v 1.38 2004-09-26 20:19:44 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,16 +20,17 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define RIDX_CHUNK 128 /* * Format of first block - * next (4 bytes) - * ref_count (4 bytes) - * block (504 bytes) + * next (8 bytes) + * ref_count (2 bytes) + * block (500 bytes) * * Format of subsequent blocks - * next (4 bytes) - * block (508 bytes) + * next (8 bytes) + * block (502 bytes) * * Format of each record * sysno @@ -76,8 +77,15 @@ static int read_indx (Records p, SYSNO sysno, void *buf, int itemsize, { int r; zint pos = (sysno-1)*itemsize; + int off = (int) (pos%RIDX_CHUNK); + int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ - r = bf_read (p->index_BFile, 1+pos/128, (int) (pos%128), itemsize, buf); + if (sz1 > itemsize) + sz1 = itemsize; /* no more than itemsize bytes */ + + r = bf_read (p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf); + if (r == 1 && sz1 < itemsize) /* boundary? - must read second part */ + r = bf_read (p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1, buf + sz1); if (r != 1 && !ignoreError) { logf (LOG_FATAL|LOG_ERRNO, "read in %s at pos %ld", @@ -90,15 +98,22 @@ static int read_indx (Records p, SYSNO sysno, void *buf, int itemsize, static void write_indx (Records p, SYSNO sysno, void *buf, int itemsize) { zint pos = (sysno-1)*itemsize; + int off = (int) (pos%RIDX_CHUNK); + int sz1 = RIDX_CHUNK - off; /* sz1 is size of buffer to read.. */ + + if (sz1 > itemsize) + sz1 = itemsize; /* no more than itemsize bytes */ - bf_write (p->index_BFile, 1+pos/128, (int) (pos%128), itemsize, buf); + bf_write(p->index_BFile, 1+pos/RIDX_CHUNK, off, sz1, buf); + if (sz1 < itemsize) /* boundary? must write second part */ + bf_write(p->index_BFile, 2+pos/RIDX_CHUNK, 0, itemsize - sz1, buf + sz1); } static void rec_release_blocks (Records p, SYSNO sysno) { struct record_index_entry entry; zint freeblock; - char block_and_ref[sizeof(short) + sizeof(zint)]; + char block_and_ref[sizeof(zint) + sizeof(short)]; int dst_type; int first = 1; @@ -113,7 +128,8 @@ static void rec_release_blocks (Records p, SYSNO sysno) while (freeblock) { if (bf_read (p->data_BFile[dst_type], freeblock, 0, - sizeof(block_and_ref), block_and_ref) != 1) + first ? sizeof(block_and_ref) : sizeof(zint), + block_and_ref) != 1) { logf (LOG_FATAL|LOG_ERRNO, "read in rec_del_single"); exit (1); @@ -231,7 +247,7 @@ Records rec_open (BFiles bfs, int rw, int compression_method) 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); + p->index_BFile = bf_open (bfs, p->index_fname, RIDX_CHUNK, rw); if (p->index_BFile == NULL) { logf (LOG_FATAL|LOG_ERRNO, "open %s", p->index_fname);