1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tdb2/traverse.c>
9 #include <ccan/tdb2/transaction.c>
10 #include <ccan/tap/tap.h>
13 int main(int argc
, char *argv
[])
16 struct tdb_context
*tdb
;
17 int flags
[] = { TDB_DEFAULT
, TDB_NOMMAP
,
19 TDB_NOMMAP
|TDB_CONVERT
};
21 if (sizeof(off_t
) <= 4) {
23 pass("No 64 bit off_t");
27 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 14);
28 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
32 struct tdb_used_record rec
;
35 tdb
= tdb_open("run-64-bit-tdb.tdb", flags
[i
],
36 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
41 old_size
= tdb
->file
->map_size
;
43 /* This makes a sparse file */
44 ok1(ftruncate(tdb
->file
->fd
, 0xFFFFFFF0) == 0);
45 ok1(add_free_record(tdb
, old_size
, 0xFFFFFFF0 - old_size
,
46 TDB_LOCK_WAIT
, false) == TDB_SUCCESS
);
48 /* Now add a little record past the 4G barrier. */
49 ok1(tdb_expand_file(tdb
, 100) == TDB_SUCCESS
);
50 ok1(add_free_record(tdb
, 0xFFFFFFF0, 100, TDB_LOCK_WAIT
, false)
53 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
55 /* Test allocation path. */
56 k
= tdb_mkdata("key", 4);
57 d
= tdb_mkdata("data", 5);
58 ok1(tdb_store(tdb
, k
, d
, TDB_INSERT
) == 0);
59 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
61 /* Make sure it put it at end as we expected. */
62 off
= find_and_lock(tdb
, k
, F_RDLCK
, &h
, &rec
, NULL
);
63 ok1(off
>= 0xFFFFFFF0);
64 tdb_unlock_hashes(tdb
, h
.hlock_start
, h
.hlock_range
, F_RDLCK
);
66 ok1(tdb_fetch(tdb
, k
, &d
) == 0);
68 ok1(strcmp((char *)d
.dptr
, "data") == 0);
71 ok1(tdb_delete(tdb
, k
) == 0);
72 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
77 /* We might get messages about mmap failing, so don't test