1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 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
21 #include <sys/types.h>
26 #include <idzebra/bfile.h>
35 zint max_block = 200000;
37 YAZ_CHECK(block_size <= sizeof(buf));
38 if (!(block_size <= sizeof(buf)))
41 YAZ_CHECK(max_block * block_size < 4 * 1000000); /* 4M */
43 r = mkdir("register", 0777);
44 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
46 r = mkdir("shadow", 0777);
47 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
49 bfs = bfs_create("register.bad:4M", 0 /* base: current dir */);
54 bfs = bfs_create("register:4M", 0 /* base: current dir */);
59 r = bf_cache(bfs, "shadow.bad:4M");
60 YAZ_CHECK_EQ(r, ZEBRA_FAIL);
62 r = bf_cache(bfs, "shadow:4M");
63 YAZ_CHECK_EQ(r, ZEBRA_OK);
68 /* we have to destroy bfs after reset. Unfortunately! */
71 bfs = bfs_create("register:4M", 0 /* base: current dir */);
76 r = bf_cache(bfs, "shadow:4M");
77 YAZ_CHECK_EQ(r, ZEBRA_OK);
80 yaz_log(YLOG_LOG, "writing file 1");
81 bf = bf_open(bfs, "file", block_size, 1);
86 memset(buf, ' ', block_size);
90 while (bno[0] < max_block)
92 zint next = bno[0] + bno[1];
94 sprintf(buf, ZINT_FORMAT, bno[0]);
95 YAZ_CHECK_EQ(bf_write(bf, bno[0], 0, 0, buf), 0);
103 yaz_log(YLOG_LOG, "reading file 1");
104 bf = bf_open(bfs, "file", block_size, 0);
112 while (bno[0] < max_block)
114 zint next = bno[0] + bno[1];
115 memset(buf, ' ', block_size);
117 YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1);
118 YAZ_CHECK_EQ(atoi(buf), bno[0]);
127 yaz_log(YLOG_LOG, "writing file 2");
128 bf = bf_open(bfs, "file", block_size, 1);
133 while (bno < max_block)
135 memset(buf, ' ', block_size);
137 sprintf(buf, ZINT_FORMAT, bno);
138 YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0);
145 yaz_log(YLOG_LOG, "reading file 2");
146 bf = bf_open(bfs, "file", block_size, 0);
151 int step = max_block / 50;
153 while (bno < max_block)
155 memset(buf, ' ', block_size);
157 YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1);
158 YAZ_CHECK_EQ(atoi(buf), bno);
169 int main(int argc, char **argv)
171 YAZ_CHECK_INIT(argc, argv);