]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/layout.h
tdb2: add a capability list from the header.
[ccan] / ccan / tdb2 / test / layout.h
1 #ifndef TDB2_TEST_LAYOUT_H
2 #define TDB2_TEST_LAYOUT_H
3 #include <ccan/tdb2/private.h>
4
5 struct tdb_layout *new_tdb_layout(void);
6 void tdb_layout_add_freetable(struct tdb_layout *layout);
7 void tdb_layout_add_free(struct tdb_layout *layout, tdb_len_t len,
8                          unsigned ftable);
9 void tdb_layout_add_used(struct tdb_layout *layout,
10                          TDB_DATA key, TDB_DATA data,
11                          tdb_len_t extra);
12 void tdb_layout_add_capability(struct tdb_layout *layout,
13                                uint64_t type,
14                                bool write_breaks,
15                                bool check_breaks,
16                                bool open_breaks,
17                                tdb_len_t extra);
18
19 #if 0 /* FIXME: Allow allocation of subtables */
20 void tdb_layout_add_hashtable(struct tdb_layout *layout,
21                               int htable_parent, /* -1 == toplevel */
22                               unsigned int bucket,
23                               tdb_len_t extra);
24 #endif
25 /* freefn is needed if we're using failtest_free. */
26 struct tdb_context *tdb_layout_get(struct tdb_layout *layout,
27                                    void (*freefn)(void *),
28                                    union tdb_attribute *attr);
29 void tdb_layout_write(struct tdb_layout *layout, void (*freefn)(void *),
30                        union tdb_attribute *attr, const char *filename);
31
32 void tdb_layout_free(struct tdb_layout *layout);
33
34 enum layout_type {
35         FREETABLE, FREE, DATA, HASHTABLE, CAPABILITY
36 };
37
38 /* Shared by all union members. */
39 struct tle_base {
40         enum layout_type type;
41         tdb_off_t off;
42 };
43
44 struct tle_freetable {
45         struct tle_base base;
46 };
47
48 struct tle_free {
49         struct tle_base base;
50         tdb_len_t len;
51         unsigned ftable_num;
52 };
53
54 struct tle_used {
55         struct tle_base base;
56         TDB_DATA key;
57         TDB_DATA data;
58         tdb_len_t extra;
59 };
60
61 struct tle_hashtable {
62         struct tle_base base;
63         int parent;
64         unsigned int bucket;
65         tdb_len_t extra;
66 };
67
68 struct tle_capability {
69         struct tle_base base;
70         uint64_t type;
71         tdb_len_t extra;
72 };
73
74 union tdb_layout_elem {
75         struct tle_base base;
76         struct tle_freetable ftable;
77         struct tle_free free;
78         struct tle_used used;
79         struct tle_hashtable hashtable;
80         struct tle_capability capability;
81 };
82
83 struct tdb_layout {
84         unsigned int num_elems;
85         union tdb_layout_elem *elem;
86 };
87 #endif /* TDB2_TEST_LAYOUT_H */