1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
5 int main(int argc
, char *argv
[])
8 struct tdb_context
*tdb
;
9 int flags
[] = { TDB_DEFAULT
, TDB_NOMMAP
,
11 TDB_NOMMAP
|TDB_CONVERT
};
13 if (sizeof(off_t
) <= 4) {
15 pass("No 64 bit off_t");
19 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 14);
20 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
24 struct tdb_used_record rec
;
27 tdb
= tdb_open("run-64-bit-tdb.tdb", flags
[i
],
28 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
33 old_size
= tdb
->file
->map_size
;
35 /* This makes a sparse file */
36 ok1(ftruncate(tdb
->file
->fd
, 0xFFFFFFF0) == 0);
37 ok1(add_free_record(tdb
, old_size
, 0xFFFFFFF0 - old_size
,
38 TDB_LOCK_WAIT
, false) == TDB_SUCCESS
);
40 /* Now add a little record past the 4G barrier. */
41 ok1(tdb_expand_file(tdb
, 100) == TDB_SUCCESS
);
42 ok1(add_free_record(tdb
, 0xFFFFFFF0, 100, TDB_LOCK_WAIT
, false)
45 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
47 /* Test allocation path. */
48 k
= tdb_mkdata("key", 4);
49 d
= tdb_mkdata("data", 5);
50 ok1(tdb_store(tdb
, k
, d
, TDB_INSERT
) == 0);
51 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
53 /* Make sure it put it at end as we expected. */
54 off
= find_and_lock(tdb
, k
, F_RDLCK
, &h
, &rec
, NULL
);
55 ok1(off
>= 0xFFFFFFF0);
56 tdb_unlock_hashes(tdb
, h
.hlock_start
, h
.hlock_range
, F_RDLCK
);
58 ok1(tdb_fetch(tdb
, k
, &d
) == 0);
60 ok1(strcmp((char *)d
.dptr
, "data") == 0);
63 ok1(tdb_delete(tdb
, k
) == 0);
64 ok1(tdb_check(tdb
, NULL
, NULL
) == TDB_SUCCESS
);
69 /* We might get messages about mmap failing, so don't test