33 #include <yaz/snprintf.h>
34 #include <yaz/xmalloc.h>
41 #define ISAMC_FREELIST_CHUNK 0
54 { 128, 120, 100, 10 },
55 { 512, 490, 350, 10 },
56 { 2048, 1900, 1700, 10 },
57 { 8192, 8000, 7900, 10 },
58 { 32768, 32000, 31000, 0 },
84 is = (
ISAMC) xmalloc (
sizeof(*is));
87 memcpy (is->
method, method,
sizeof(*method));
93 yaz_log(YLOG_LOG,
"isc: bsize ifill mfill mblocks");
97 yaz_log (YLOG_LOG,
"isc:%6d %6d %6d %6d",
100 if (max_buf_size < filecat[i].
mblocks * filecat[i].
bsize)
102 }
while (filecat[i++].
mblocks);
106 max_buf_size = (1 + max_buf_size / filecat[i].
bsize) * filecat[i].
bsize;
110 yaz_log (YLOG_LOG,
"isc: max_buf_size %d", max_buf_size);
116 is->
merge_buf = (
char *) xmalloc (max_buf_size+256);
117 memset (is->
merge_buf, 0, max_buf_size+256);
153 yaz_snprintf(fname,
sizeof(fname),
"%s%c", name, i+
'A');
174 if (type < 0 || type >= is->
no_files)
182 if (type < 0 || type >= is->
no_files)
184 return filecat[type].
bsize;
193 yaz_log (YLOG_LOG,
"isc: next forw mid-f prev backw mid-b");
195 yaz_log (YLOG_LOG,
"isc:%8d%8d%8.1f%8d%8d%8.1f",
208 yaz_log (YLOG_LOG,
"isc: writes reads skipped alloc released remap");
213 yaz_log (YLOG_LOG,
"isc:%8d%8d%8d%8d%8d%8d",
248 yaz_log (YLOG_LOG,
"isc: write_block %d " ZINT_FORMAT, cat, pos);
253 zint nextpos,
int offset)
257 yaz_log (YLOG_LOG,
"isc: write_dblock. size=%d nextpos=" ZINT_FORMAT,
258 (
int) size, nextpos);
260 memcpy (src, &nextpos,
sizeof(nextpos));
261 memcpy (src +
sizeof(nextpos), &size,
sizeof(size));
265 #if ISAMC_FREELIST_CHUNK
318 memcpy (&block, abuf +
sizeof(
zint) +
sizeof(
int) *
348 memcpy (abuf +
sizeof(
int), &block,
sizeof(
zint));
354 memcpy (abuf +
sizeof(
int) +
368 char buf[
sizeof(
zint)];
384 char buf[
sizeof(
zint)];
403 if ((nb = is->
files[cat].
fc_list[j]) && (!block || nb < block))
413 yaz_log (YLOG_LOG,
"isc: alloc_block in cat %d: " ZINT_FORMAT, cat, block);
420 yaz_log (YLOG_LOG,
"isc: release_block in cat %d:" ZINT_FORMAT, cat, pos);
489 memcpy (&pp->
next, src,
sizeof(pp->
next));
490 src +=
sizeof(pp->
next);
491 memcpy (&pp->
size, src,
sizeof(pp->
size));
492 src +=
sizeof(pp->
size);
504 yaz_log (YLOG_LOG,
"isc: read_block size=%d %d " ZINT_FORMAT " next="
559 memcpy (&pp->
next, src,
sizeof(pp->
next));
560 src +=
sizeof(pp->
next);
561 memcpy (&pp->
size, src,
sizeof(pp->
size));
562 src +=
sizeof(pp->
size);
578 yaz_log (YLOG_LOG,
"isc: read_block size=%d %d " ZINT_FORMAT " next="
int bf_read(BFile bf, zint no, int offset, int nbytes, void *buf)
read from block file (may call exit)
void bf_close(BFile bf)
closes a Block file (may call exit)
BFile bf_open(BFiles bfs, const char *name, int block_size, int wflag)
opens and returns a Block file handle
int bf_write(BFile bf, zint no, int offset, int nbytes, const void *buf)
writes block of bytes to file (may call exit)
#define ISAMC_BLOCK_OFFSET_N
unsigned ISAMC_BLOCK_SIZE
#define ISAMC_BLOCK_OFFSET_1
struct ISAMC_file_s * ISAMC_file
ISAMC isamc_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method)
int isamc_block_size(ISAMC is, int type)
int isamc_write_dblock(ISAMC is, int cat, zint pos, char *src, zint nextpos, int offset)
static void release_fc(ISAMC is, int cat)
int isamc_write_block(ISAMC is, int cat, zint pos, char *src)
zint isamc_pp_num(ISAMC_PP pp)
int isamc_close(ISAMC is)
static void release_block(ISAMC is, int cat, zint pos)
static void flush_block(ISAMC is, int cat)
void isamc_getmethod(ISAMC_M *m)
ISAMC_PP isamc_pp_open(ISAMC is, ISAM_P ipos)
int isamc_read_item(ISAMC_PP pp, char **dst)
int isamc_pp_read(ISAMC_PP pp, void *buf)
static void init_fc(ISAMC is, int cat)
void isamc_pp_close(ISAMC_PP pp)
zint isamc_alloc_block(ISAMC is, int cat)
void isamc_release_block(ISAMC is, int cat, zint pos)
zint isamc_block_used(ISAMC is, int type)
static zint alloc_block(ISAMC is, int cat)
int isamc_read_block(ISAMC is, int cat, zint pos, char *dst)
struct ISAMC_PP_s * ISAMC_PP
int(* compare_item)(const void *a, const void *b)
void(* log_item)(int logmask, const void *p, const char *txt)
void(* decode)(void *p, char **dst, const char **src)
void(* encode)(void *p, char **dst, const char **src)