1 #include "ntdb-source.h"
2 #include "tap-interface.h"
5 /* The largest 32-bit value which is still a multiple of NTDB_PGSIZE */
6 #define ALMOST_4G ((uint32_t)-NTDB_PGSIZE)
7 /* And this pushes it over 32 bits */
8 #define A_LITTLE_BIT (NTDB_PGSIZE * 2)
10 int main(int argc
, char *argv
[])
13 struct ntdb_context
*ntdb
;
14 int flags
[] = { NTDB_DEFAULT
, NTDB_NOMMAP
,
16 NTDB_NOMMAP
|NTDB_CONVERT
};
18 if (sizeof(off_t
) <= 4) {
20 pass("No 64 bit off_t");
24 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 16);
25 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
29 struct ntdb_used_record rec
;
32 ntdb
= ntdb_open("run-64-bit-ntdb.ntdb", flags
[i
]|MAYBE_NOSYNC
,
33 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
38 old_size
= ntdb
->file
->map_size
;
40 /* Add a fake record to chew up the existing free space. */
41 k
= ntdb_mkdata("fake", 4);
42 d
.dsize
= ntdb
->file
->map_size
43 - NEW_DATABASE_HDR_SIZE(ntdb
->hash_bits
) - 8;
44 d
.dptr
= malloc(d
.dsize
);
45 memset(d
.dptr
, 0, d
.dsize
);
46 ok1(ntdb_store(ntdb
, k
, d
, NTDB_INSERT
) == 0);
47 ok1(ntdb
->file
->map_size
== old_size
);
50 /* This makes a sparse file */
51 ok1(ftruncate(ntdb
->file
->fd
, ALMOST_4G
) == 0);
52 ok1(add_free_record(ntdb
, old_size
, ALMOST_4G
- old_size
,
53 NTDB_LOCK_WAIT
, false) == NTDB_SUCCESS
);
55 /* Now add a little record past the 4G barrier. */
56 ok1(ntdb_expand_file(ntdb
, A_LITTLE_BIT
) == NTDB_SUCCESS
);
57 ok1(add_free_record(ntdb
, ALMOST_4G
, A_LITTLE_BIT
,
58 NTDB_LOCK_WAIT
, false)
61 ok1(ntdb_check(ntdb
, NULL
, NULL
) == NTDB_SUCCESS
);
63 /* Test allocation path. */
64 k
= ntdb_mkdata("key", 4);
65 d
= ntdb_mkdata("data", 5);
66 ok1(ntdb_store(ntdb
, k
, d
, NTDB_INSERT
) == 0);
67 ok1(ntdb_check(ntdb
, NULL
, NULL
) == NTDB_SUCCESS
);
69 /* Make sure it put it at end as we expected. */
70 off
= find_and_lock(ntdb
, k
, F_RDLCK
, &h
, &rec
, NULL
);
71 ok1(off
>= ALMOST_4G
);
72 ntdb_unlock_hash(ntdb
, h
.h
, F_RDLCK
);
74 ok1(ntdb_fetch(ntdb
, k
, &d
) == 0);
76 ok1(strcmp((char *)d
.dptr
, "data") == 0);
79 ok1(ntdb_delete(ntdb
, k
) == 0);
80 ok1(ntdb_check(ntdb
, NULL
, NULL
) == NTDB_SUCCESS
);
85 /* We might get messages about mmap failing, so don't test