#include <ccan/tdb/error.c>
#include <ccan/tdb/open.c>
#include <ccan/tdb/check.c>
+#include <ccan/tdb/hash.c>
#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <err.h>
+#include "logging.h"
static int check(TDB_DATA key, TDB_DATA data, void *private)
{
((unsigned char *)tdb->map_ptr)[off] ^= mask;
else {
unsigned char c;
- pread(tdb->fd, &c, 1, off);
+ if (pread(tdb->fd, &c, 1, off) != 1)
+ err(1, "pread");
c ^= mask;
- pwrite(tdb->fd, &c, 1, off);
+ if (pwrite(tdb->fd, &c, 1, off) != 1)
+ err(1, "pwrite");
}
}
/* This is how many bytes we expect to be verifiable. */
/* From the file header. */
verifiable = strlen(TDB_MAGIC_FOOD) + 1
- + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t);
+ + 2 * sizeof(uint32_t) + 2 * sizeof(tdb_off_t)
+ + 2 * sizeof(uint32_t);
/* From the free list chain and hash chains. */
verifiable += 3 * sizeof(tdb_off_t);
/* From the record headers & tailer */
plan_tests(4);
/* This should use mmap. */
- tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST,
- O_CREAT|O_TRUNC|O_RDWR, 0600);
+ tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
if (!tdb)
abort();
tdb_close(tdb);
/* This should not. */
- tdb = tdb_open("/tmp/test6.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP,
- O_CREAT|O_TRUNC|O_RDWR, 0600);
+ tdb = tdb_open_ex("run-corrupt.tdb", 2, TDB_CLEAR_IF_FIRST|TDB_NOMMAP,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
if (!tdb)
abort();