1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
29 #include <idzebra/bfile.h>
38 zint max_block = 200000;
40 YAZ_CHECK(block_size <= sizeof(buf));
41 if (!(block_size <= sizeof(buf)))
44 YAZ_CHECK(max_block * block_size < 4 * 1000000); /* 4M */
46 r = mkdir("register", 0777);
47 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
49 r = mkdir("shadow", 0777);
50 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
52 bfs = bfs_create("register.bad:4M", 0 /* base: current dir */);
57 bfs = bfs_create("register:4M", 0 /* base: current dir */);
62 r = bf_cache(bfs, "shadow.bad:4M");
63 YAZ_CHECK_EQ(r, ZEBRA_FAIL);
65 r = bf_cache(bfs, "shadow:4M");
66 YAZ_CHECK_EQ(r, ZEBRA_OK);
71 /* we have to destroy bfs after reset. Unfortunately! */
74 bfs = bfs_create("register:4M", 0 /* base: current dir */);
79 r = bf_cache(bfs, "shadow:4M");
80 YAZ_CHECK_EQ(r, ZEBRA_OK);
83 yaz_log(YLOG_LOG, "writing file 1");
84 bf = bf_open(bfs, "file", block_size, 1);
89 memset(buf, ' ', block_size);
93 while (bno[0] < max_block)
95 zint next = bno[0] + bno[1];
97 sprintf(buf, ZINT_FORMAT, bno[0]);
98 YAZ_CHECK_EQ(bf_write(bf, bno[0], 0, 0, buf), 0);
106 yaz_log(YLOG_LOG, "reading file 1");
107 bf = bf_open(bfs, "file", block_size, 0);
115 while (bno[0] < max_block)
117 zint next = bno[0] + bno[1];
118 memset(buf, ' ', block_size);
120 YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1);
121 YAZ_CHECK_EQ(atoi(buf), bno[0]);
130 yaz_log(YLOG_LOG, "writing file 2");
131 bf = bf_open(bfs, "file", block_size, 1);
136 while (bno < max_block)
138 memset(buf, ' ', block_size);
140 sprintf(buf, ZINT_FORMAT, bno);
141 YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0);
148 yaz_log(YLOG_LOG, "reading file 2");
149 bf = bf_open(bfs, "file", block_size, 0);
154 int step = max_block / 50;
156 while (bno < max_block)
158 memset(buf, ' ', block_size);
160 YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1);
161 YAZ_CHECK_EQ(atoi(buf), bno);
172 int main(int argc, char **argv)
174 YAZ_CHECK_INIT(argc, argv);