1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tdb2/check.c>
7 #include <ccan/tap/tap.h>
11 /* Calculate start of zone offset from layout directly. */
12 static tdb_off_t layout_zone_off(tdb_off_t off, struct tdb_layout *layout)
16 /* Every second one is a free entry, so divide by 2 to get zone */
17 for (i = 0; i < layout->num_elems; i++) {
18 if (layout->elem[i].base.type != ZONE)
20 if (layout->elem[i].base.off
21 + (1ULL << layout->elem[i].zone.zone_bits) > off)
22 return layout->elem[i].base.off;
27 int main(int argc, char *argv[])
29 struct tdb_context *tdb;
30 struct tdb_layout *layout;
31 struct free_zone_header zhdr;
35 /* FIXME: Test TDB_CONVERT */
39 /* No coalescing can be done due to EOF */
40 layout = new_tdb_layout(NULL);
41 tdb_layout_add_zone(layout, INITIAL_ZONE_BITS, false);
42 tdb_layout_add_zone(layout, INITIAL_ZONE_BITS, true);
43 tdb_layout_add_zone(layout, INITIAL_ZONE_BITS+1, true);
44 tdb_layout_add_zone(layout, INITIAL_ZONE_BITS+2, true);
45 tdb_layout_add_zone(layout, INITIAL_ZONE_BITS+2, true);
46 tdb = tdb_layout_get(layout);
48 ok1(tdb_check(tdb, NULL, NULL) == 0);
50 /* Last zone should get right zone. */
51 ok1(last_zone(tdb, &zhdr)
52 == layout->elem[layout->num_elems-1].base.off);
53 ok1(zhdr.zone_bits == INITIAL_ZONE_BITS+2);
55 off = sizeof(struct tdb_header);
56 step = (tdb->map_size - 1 - off) / 100;
57 for (i = 0; i < 100; i++, off += step) {
58 ok1(off_to_zone(tdb, off, &zhdr) == layout_zone_off(off, layout));