24 #include <sys/types.h>
29 #include <yaz/snprintf.h>
40 zint max_block = 200000;
42 YAZ_CHECK(block_size <=
sizeof(buf));
43 if (!(block_size <=
sizeof(buf)))
46 YAZ_CHECK(max_block * block_size < 4 * 1000000);
48 r = mkdir(
"register", 0777);
49 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
51 r = mkdir(
"shadow", 0777);
52 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
85 yaz_log(YLOG_LOG,
"writing file 1");
86 bf =
bf_open(bfs,
"file", block_size, 1);
91 memset(buf,
' ', block_size);
95 while (bno[0] < max_block)
100 yaz_snprintf(buf,
sizeof(buf),
ZINT_FORMAT, bno[0]);
101 YAZ_CHECK_EQ(
bf_write(bf, bno[0], 0, 0, buf), 0);
109 yaz_log(YLOG_LOG,
"reading file 1");
110 bf =
bf_open(bfs,
"file", block_size, 0);
118 while (bno[0] < max_block)
120 zint next = bno[0] + bno[1];
121 memset(buf,
' ', block_size);
123 YAZ_CHECK_EQ(
bf_read(bf, bno[0], 0, 0, buf), 1);
124 YAZ_CHECK_EQ(atoi(buf), bno[0]);
133 yaz_log(YLOG_LOG,
"writing file 2");
134 bf =
bf_open(bfs,
"file", block_size, 1);
139 while (bno < max_block)
141 memset(buf,
' ', block_size);
144 YAZ_CHECK_EQ(
bf_write(bf, bno, 0, 0, buf), 0);
151 yaz_log(YLOG_LOG,
"reading file 2");
152 bf =
bf_open(bfs,
"file", block_size, 0);
157 int step = max_block / 50;
159 while (bno < max_block)
161 memset(buf,
' ', block_size);
163 YAZ_CHECK_EQ(
bf_read(bf, bno, 0, 0, buf), 1);
164 YAZ_CHECK_EQ(atoi(buf), bno);
175 int main(
int argc,
char **argv)
177 YAZ_CHECK_INIT(argc, argv);
int bf_read(BFile bf, zint no, int offset, int nbytes, void *buf)
read from block file (may call exit)
ZEBRA_RES bf_cache(BFiles bfs, const char *spec)
enables or disables shadow for block files
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)
void bf_reset(BFiles bfs)
Removes register and shadow completely.
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
void bfs_destroy(BFiles bfiles)
destroys a block files handle
int main(int argc, char **argv)