s3:smb2_write: pass fsp->fnum to init_strict_lock_struct()
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-64-bit-tdb.c
blobef6e243a053a4f4b413839cfd884e16e2937433c
1 #include "tdb2-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
5 int main(int argc, char *argv[])
7 unsigned int i;
8 struct tdb_context *tdb;
9 int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
10 TDB_CONVERT,
11 TDB_NOMMAP|TDB_CONVERT };
13 if (sizeof(off_t) <= 4) {
14 plan_tests(1);
15 pass("No 64 bit off_t");
16 return exit_status();
19 plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
20 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
21 off_t old_size;
22 TDB_DATA k, d;
23 struct hash_info h;
24 struct tdb_used_record rec;
25 tdb_off_t off;
27 tdb = tdb_open("run-64-bit-tdb.tdb", flags[i],
28 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
29 ok1(tdb);
30 if (!tdb)
31 continue;
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)
43 == TDB_SUCCESS);
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);
59 ok1(d.dsize == 5);
60 ok1(strcmp((char *)d.dptr, "data") == 0);
61 free(d.dptr);
63 ok1(tdb_delete(tdb, k) == 0);
64 ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
66 tdb_close(tdb);
69 /* We might get messages about mmap failing, so don't test
70 * tap_log_messages */
71 return exit_status();