#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <err.h>
-#include "tdb1-logging.h"
+#include "logging.h"
static int check(TDB_DATA key, TDB_DATA data, void *private)
{
return 0;
}
-static void tdb1_flip_bit(struct tdb1_context *tdb, unsigned int bit)
+static void tdb1_flip_bit(struct tdb_context *tdb, unsigned int bit)
{
unsigned int off = bit / CHAR_BIT;
unsigned char mask = (1 << (bit % CHAR_BIT));
- if (tdb->map_ptr)
- ((unsigned char *)tdb->map_ptr)[off] ^= mask;
+ if (tdb->file->map_ptr)
+ ((unsigned char *)tdb->file->map_ptr)[off] ^= mask;
else {
unsigned char c;
- if (pread(tdb->fd, &c, 1, off) != 1)
+ if (pread(tdb->file->fd, &c, 1, off) != 1)
err(1, "pread");
c ^= mask;
- if (pwrite(tdb->fd, &c, 1, off) != 1)
+ if (pwrite(tdb->file->fd, &c, 1, off) != 1)
err(1, "pwrite");
}
}
-static void check_test(struct tdb1_context *tdb)
+static void check_test(struct tdb_context *tdb)
{
TDB_DATA key, data;
unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize;
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
key.dptr = (void *)"hello";
data.dsize = strlen("world");
for (key.dsize = 1; key.dsize <= 5; key.dsize++) {
ksize += key.dsize;
dsize += data.dsize;
- if (tdb1_store(tdb, key, data, TDB_INSERT) != 0)
+ if (tdb_store(tdb, key, data, TDB_INSERT) != TDB_SUCCESS)
abort();
}
verifiable += ksize + dsize;
/* Flip one bit at a time, make sure it detects verifiable bytes. */
- for (i = 0, corrupt = 0; i < tdb->map_size * CHAR_BIT; i++) {
+ for (i = 0, corrupt = 0; i < tdb->file->map_size * CHAR_BIT; i++) {
tdb1_flip_bit(tdb, i);
memset(sizes, 0, sizeof(sizes));
- if (tdb1_check(tdb, check, sizes) != 0)
+ if (tdb_check(tdb, check, sizes) == TDB_ERR_CORRUPT)
corrupt++;
else if (sizes[0] != ksize || sizes[1] != dsize)
corrupt++;
int main(int argc, char *argv[])
{
- struct tdb1_context *tdb;
+ struct tdb_context *tdb;
+ union tdb_attribute hsize;
+
+ hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
+ hsize.base.next = &tap_log_attr;
+ hsize.tdb1_hashsize.hsize = 2;
plan_tests(4);
/* This should use mmap. */
- tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB1_CLEAR_IF_FIRST,
- O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+ tdb = tdb_open("run-corrupt.tdb1", TDB_VERSION1,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
if (!tdb)
abort();
check_test(tdb);
- tdb1_close(tdb);
+ tdb_close(tdb);
/* This should not. */
- tdb = tdb1_open_ex("run-corrupt.tdb", 2, TDB1_CLEAR_IF_FIRST|TDB1_NOMMAP,
- O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+ tdb = tdb_open("run-corrupt.tdb1", TDB_VERSION1|TDB_NOMMAP,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
if (!tdb)
abort();
check_test(tdb);
- tdb1_close(tdb);
+ tdb_close(tdb);
return exit_status();
}