]> git.ozlabs.org Git - ccan/blob - ccan/ntdb/test/layout.h
Merge branch 'ntdb' of https://github.com/ddiss/ccan into ddiss-ntdb
[ccan] / ccan / ntdb / test / layout.h
1 #ifndef NTDB_TEST_LAYOUT_H
2 #define NTDB_TEST_LAYOUT_H
3 #include "private.h"
4
5 struct ntdb_layout *new_ntdb_layout(void);
6 void ntdb_layout_add_freetable(struct ntdb_layout *layout);
7 void ntdb_layout_add_free(struct ntdb_layout *layout, ntdb_len_t len,
8                          unsigned ftable);
9 void ntdb_layout_add_used(struct ntdb_layout *layout,
10                          NTDB_DATA key, NTDB_DATA data,
11                          ntdb_len_t extra);
12 void ntdb_layout_add_capability(struct ntdb_layout *layout,
13                                uint64_t type,
14                                bool write_breaks,
15                                bool check_breaks,
16                                bool open_breaks,
17                                ntdb_len_t extra);
18
19 #if 0 /* FIXME: Allow allocation of subtables */
20 void ntdb_layout_add_hashtable(struct ntdb_layout *layout,
21                               int htable_parent, /* -1 == toplevel */
22                               unsigned int bucket,
23                               ntdb_len_t extra);
24 #endif
25 /* freefn is needed if we're using failtest_free. */
26 struct ntdb_context *ntdb_layout_get(struct ntdb_layout *layout,
27                                    void (*freefn)(void *),
28                                    union ntdb_attribute *attr);
29 void ntdb_layout_write(struct ntdb_layout *layout, void (*freefn)(void *),
30                        union ntdb_attribute *attr, const char *filename);
31
32 void ntdb_layout_free(struct ntdb_layout *layout);
33
34 enum layout_type {
35         FREETABLE, FREE, DATA, CAPABILITY
36 };
37
38 /* Shared by all union members. */
39 struct tle_base {
40         enum layout_type type;
41         ntdb_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         ntdb_len_t len;
51         unsigned ftable_num;
52 };
53
54 struct tle_used {
55         struct tle_base base;
56         NTDB_DATA key;
57         NTDB_DATA data;
58         ntdb_len_t extra;
59 };
60
61 struct tle_capability {
62         struct tle_base base;
63         uint64_t type;
64         ntdb_len_t extra;
65 };
66
67 union ntdb_layout_elem {
68         struct tle_base base;
69         struct tle_freetable ftable;
70         struct tle_free free;
71         struct tle_used used;
72         struct tle_capability capability;
73 };
74
75 struct ntdb_layout {
76         unsigned int num_elems;
77         union ntdb_layout_elem *elem;
78 };
79 #endif /* NTDB_TEST_LAYOUT_H */