summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tdb2/tdb1.h46
-rw-r--r--lib/tdb2/tdb1_check.c14
-rw-r--r--lib/tdb2/tdb1_hash.c4
-rw-r--r--lib/tdb2/tdb1_io.c6
-rw-r--r--lib/tdb2/tdb1_lock.c44
-rw-r--r--lib/tdb2/tdb1_open.c16
-rw-r--r--lib/tdb2/tdb1_private.h29
-rw-r--r--lib/tdb2/tdb1_tdb.c58
-rw-r--r--lib/tdb2/tdb1_transaction.c6
-rw-r--r--lib/tdb2/tdb1_traverse.c14
-rw-r--r--lib/tdb2/test/run-tdb1-3G-file.c10
-rw-r--r--lib/tdb2/test/run-tdb1-check.c4
-rw-r--r--lib/tdb2/test/run-tdb1-corrupt.c8
-rw-r--r--lib/tdb2/test/run-tdb1-die-during-transaction.c6
-rw-r--r--lib/tdb2/test/run-tdb1-endian.c10
-rw-r--r--lib/tdb2/test/run-tdb1-incompatible.c10
-rw-r--r--lib/tdb2/test/run-tdb1-nested-transactions.c4
-rw-r--r--lib/tdb2/test/run-tdb1-nested-traverse.c12
-rw-r--r--lib/tdb2/test/run-tdb1-no-lock-during-traverse.c8
-rw-r--r--lib/tdb2/test/run-tdb1-open-during-transaction.c4
-rw-r--r--lib/tdb2/test/run-tdb1-readonly-check.c6
-rw-r--r--lib/tdb2/test/run-tdb1-summary.c6
-rw-r--r--lib/tdb2/test/run-tdb1-traverse-in-transaction.c10
-rw-r--r--lib/tdb2/test/run-tdb1-wronghash-fail.c4
-rw-r--r--lib/tdb2/test/run-tdb1-zero-append.c2
-rw-r--r--lib/tdb2/test/run-tdb1.c10
-rw-r--r--lib/tdb2/test/tdb1-external-agent.c4
27 files changed, 168 insertions, 187 deletions
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
index 8b3130ad2a..b2435ba53e 100644
--- a/lib/tdb2/tdb1.h
+++ b/lib/tdb2/tdb1.h
@@ -35,10 +35,6 @@
#include <sys/stat.h>
#endif
-/** Flags to tdb1_store() */
-#define TDB1_REPLACE 1 /** Unused */
-#define TDB1_INSERT 2 /** Don't overwrite an existing entry */
-#define TDB1_MODIFY 3 /** Don't create an existing entry */
/** Flags for tdb1_open() */
#define TDB1_DEFAULT 0 /** just a readability place holder */
@@ -55,19 +51,13 @@
#define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */
#define TDB1_INCOMPATIBLE_HASH 2048 /** Better hashing: can't be opened by tdb < 1.2.6. */
-/** The tdb data structure */
-typedef struct TDB1_DATA {
- unsigned char *dptr;
- size_t dsize;
-} TDB1_DATA;
-
/** This is the context structure that is returned from a db open. */
typedef struct tdb1_context TDB1_CONTEXT;
-typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB1_DATA, TDB1_DATA, void *);
+typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB_DATA, TDB_DATA, void *);
typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb_log_level, enum TDB_ERROR,
const char *, void *);
-typedef unsigned int (*tdb1_hash_func)(TDB1_DATA *key);
+typedef unsigned int (*tdb1_hash_func)(TDB_DATA *key);
struct tdb1_logging_context {
tdb1_log_func log_fn;
@@ -84,30 +74,30 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead);
-TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key);
+TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
-int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
- int (*parser)(TDB1_DATA key, TDB1_DATA data,
+int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data);
-int tdb1_delete(struct tdb1_context *tdb, TDB1_DATA key);
+int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key);
-int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag);
+int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
-int tdb1_append(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA new_dbuf);
+int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
int tdb1_close(struct tdb1_context *tdb);
-TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb);
+TDB_DATA tdb1_firstkey(struct tdb1_context *tdb);
-TDB1_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB1_DATA key);
+TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
-int tdb1_exists(struct tdb1_context *tdb, TDB1_DATA key);
+int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key);
int tdb1_lockall(struct tdb1_context *tdb);
@@ -131,19 +121,19 @@ int tdb1_hash_size(struct tdb1_context *tdb);
void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb);
-unsigned int tdb1_jenkins_hash(TDB1_DATA *key);
+unsigned int tdb1_jenkins_hash(TDB_DATA *key);
int tdb1_check(struct tdb1_context *tdb,
- int (*check) (TDB1_DATA key, TDB1_DATA data, void *private_data),
+ int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data);
/* @} ******************************************************************/
/* Low level locking functions: use with care */
-int tdb1_chainlock(struct tdb1_context *tdb, TDB1_DATA key);
-int tdb1_chainunlock(struct tdb1_context *tdb, TDB1_DATA key);
-int tdb1_chainlock_read(struct tdb1_context *tdb, TDB1_DATA key);
-int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB1_DATA key);
+int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key);
+int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key);
+int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key);
+int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key);
/* wipe and repack */
@@ -153,6 +143,6 @@ int tdb1_repack(struct tdb1_context *tdb);
/* Debug functions. Not used in production. */
char *tdb1_summary(struct tdb1_context *tdb);
-extern TDB1_DATA tdb1_null;
+extern TDB_DATA tdb1_null;
#endif /* tdb1.h */
diff --git a/lib/tdb2/tdb1_check.c b/lib/tdb2/tdb1_check.c
index f0eb32bdef..74b3a02d73 100644
--- a/lib/tdb2/tdb1_check.c
+++ b/lib/tdb2/tdb1_check.c
@@ -32,7 +32,7 @@ static bool tdb1_check_header(struct tdb1_context *tdb, tdb1_off_t *recovery)
if (tdb->methods->tdb1_read(tdb, 0, &hdr, sizeof(hdr), 0) == -1)
return false;
- if (strcmp(hdr.magic_food, TDB1_MAGIC_FOOD) != 0)
+ if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0)
goto corrupt;
TDB1_CONV(hdr);
@@ -132,10 +132,10 @@ corrupt:
/* Grab some bytes: may copy if can't use mmap.
Caller has already done bounds check. */
-static TDB1_DATA get_bytes(struct tdb1_context *tdb,
+static TDB_DATA get_bytes(struct tdb1_context *tdb,
tdb1_off_t off, tdb1_len_t len)
{
- TDB1_DATA d;
+ TDB_DATA d;
d.dsize = len;
@@ -147,7 +147,7 @@ static TDB1_DATA get_bytes(struct tdb1_context *tdb,
}
/* Frees data if we're not able to simply use mmap. */
-static void put_bytes(struct tdb1_context *tdb, TDB1_DATA d)
+static void put_bytes(struct tdb1_context *tdb, TDB_DATA d)
{
if (tdb->transaction == NULL && tdb->map_ptr != NULL)
return;
@@ -236,10 +236,10 @@ static bool tdb1_check_used_record(struct tdb1_context *tdb,
tdb1_off_t off,
const struct tdb1_record *rec,
unsigned char **hashes,
- int (*check)(TDB1_DATA, TDB1_DATA, void *),
+ int (*check)(TDB_DATA, TDB_DATA, void *),
void *private_data)
{
- TDB1_DATA key, data;
+ TDB_DATA key, data;
if (!tdb1_check_record(tdb, off, rec))
return false;
@@ -323,7 +323,7 @@ size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off)
}
int tdb1_check(struct tdb1_context *tdb,
- int (*check)(TDB1_DATA key, TDB1_DATA data, void *private_data),
+ int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data)
{
unsigned int h;
diff --git a/lib/tdb2/tdb1_hash.c b/lib/tdb2/tdb1_hash.c
index a8dd065535..50e49505ca 100644
--- a/lib/tdb2/tdb1_hash.c
+++ b/lib/tdb2/tdb1_hash.c
@@ -25,7 +25,7 @@
#include "tdb1_private.h"
/* This is based on the hash algorithm from gdbm */
-unsigned int tdb1_old_hash(TDB1_DATA *key)
+unsigned int tdb1_old_hash(TDB_DATA *key)
{
uint32_t value; /* Used to compute the hash value. */
uint32_t i; /* Used to cycle through random values. */
@@ -339,7 +339,7 @@ static uint32_t hashlittle( const void *key, size_t length )
return c;
}
-unsigned int tdb1_jenkins_hash(TDB1_DATA *key)
+unsigned int tdb1_jenkins_hash(TDB_DATA *key)
{
return hashlittle(key->dptr, key->dsize);
}
diff --git a/lib/tdb2/tdb1_io.c b/lib/tdb2/tdb1_io.c
index cd6efc34b1..758eac6394 100644
--- a/lib/tdb2/tdb1_io.c
+++ b/lib/tdb2/tdb1_io.c
@@ -427,13 +427,13 @@ unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1
/* Give a piece of tdb data to a parser */
-int tdb1_parse_data(struct tdb1_context *tdb, TDB1_DATA key,
+int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key,
tdb1_off_t offset, tdb1_len_t len,
- int (*parser)(TDB1_DATA key, TDB1_DATA data,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data)
{
- TDB1_DATA data;
+ TDB_DATA data;
int result;
data.dsize = len;
diff --git a/lib/tdb2/tdb1_lock.c b/lib/tdb2/tdb1_lock.c
index 68f394aad2..c427804893 100644
--- a/lib/tdb2/tdb1_lock.c
+++ b/lib/tdb2/tdb1_lock.c
@@ -130,7 +130,7 @@ static tdb1_off_t lock_offset(int list)
*/
int tdb1_brlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len,
- enum tdb1_lock_flags flags)
+ enum tdb_lock_flags flags)
{
int ret;
@@ -145,7 +145,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
do {
ret = fcntl_lock(tdb, rw_type, offset, len,
- flags & TDB1_LOCK_WAIT);
+ flags & TDB_LOCK_WAIT);
} while (ret == -1 && errno == EINTR);
if (ret == -1) {
@@ -153,7 +153,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
/* Generic lock error. errno set by fcntl.
* EAGAIN is an expected return from non-blocking
* locks. */
- if (!(flags & TDB1_LOCK_PROBE) && errno != EAGAIN) {
+ if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) {
tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
"tdb1_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d",
tdb->fd, offset, rw_type, flags, (int)len);
@@ -213,7 +213,7 @@ int tdb1_allrecord_upgrade(struct tdb1_context *tdb)
while (count--) {
struct timeval tv;
if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0,
- TDB1_LOCK_WAIT|TDB1_LOCK_PROBE) == 0) {
+ TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
tdb->allrecord_lock.ltype = F_WRLCK;
tdb->allrecord_lock.off = 0;
return 0;
@@ -246,7 +246,7 @@ static struct tdb1_lock_type *tdb1_find_nestlock(struct tdb1_context *tdb,
/* lock an offset in the database. */
int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
- enum tdb1_lock_flags flags)
+ enum tdb_lock_flags flags)
{
struct tdb1_lock_type *new_lck;
@@ -298,11 +298,11 @@ static int tdb1_lock_and_recover(struct tdb1_context *tdb)
int ret;
/* We need to match locking order in transaction commit. */
- if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0, TDB1_LOCK_WAIT)) {
+ if (tdb1_brlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0, TDB_LOCK_WAIT)) {
return -1;
}
- if (tdb1_brlock(tdb, F_WRLCK, TDB1_OPEN_LOCK, 1, TDB1_LOCK_WAIT)) {
+ if (tdb1_brlock(tdb, F_WRLCK, TDB1_OPEN_LOCK, 1, TDB_LOCK_WAIT)) {
tdb1_brunlock(tdb, F_WRLCK, TDB1_FREELIST_TOP, 0);
return -1;
}
@@ -327,7 +327,7 @@ static bool have_data_locks(const struct tdb1_context *tdb)
}
static int tdb1_lock_list(struct tdb1_context *tdb, int list, int ltype,
- enum tdb1_lock_flags waitflag)
+ enum tdb_lock_flags waitflag)
{
int ret;
bool check = false;
@@ -363,7 +363,7 @@ int tdb1_lock(struct tdb1_context *tdb, int list, int ltype)
{
int ret;
- ret = tdb1_lock_list(tdb, list, ltype, TDB1_LOCK_WAIT);
+ ret = tdb1_lock_list(tdb, list, ltype, TDB_LOCK_WAIT);
if (ret) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_lock failed on list %d "
@@ -447,7 +447,7 @@ int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype)
get the transaction lock
*/
int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags lockflags)
+ enum tdb_lock_flags lockflags)
{
return tdb1_nest_lock(tdb, TDB1_TRANSACTION_LOCK, ltype, lockflags);
}
@@ -462,7 +462,7 @@ int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype)
/* Returns 0 if all done, -1 if error, 1 if ok. */
static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags flags, bool upgradable)
+ enum tdb_lock_flags flags, bool upgradable)
{
/* There are no locks on read-only dbs */
if (tdb->read_only || tdb->traverse_read) {
@@ -498,11 +498,11 @@ static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype,
/* We only need to lock individual bytes, but Linux merges consecutive locks
* so we lock in contiguous ranges. */
static int tdb1_chainlock_gradual(struct tdb1_context *tdb,
- int ltype, enum tdb1_lock_flags flags,
+ int ltype, enum tdb_lock_flags flags,
size_t off, size_t len)
{
int ret;
- enum tdb1_lock_flags nb_flags = (flags & ~TDB1_LOCK_WAIT);
+ enum tdb_lock_flags nb_flags = (flags & ~TDB_LOCK_WAIT);
if (len <= 4) {
/* Single record. Just do blocking lock. */
@@ -533,7 +533,7 @@ static int tdb1_chainlock_gradual(struct tdb1_context *tdb,
* other way of guaranteeing exclusivity (ie. transaction write lock).
* We do the locking gradually to avoid being starved by smaller locks. */
int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags flags, bool upgradable)
+ enum tdb_lock_flags flags, bool upgradable)
{
switch (tdb1_allrecord_check(tdb, ltype, flags, upgradable)) {
case -1:
@@ -622,7 +622,7 @@ int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype)
/* lock entire database with write lock */
int tdb1_lockall(struct tdb1_context *tdb)
{
- return tdb1_allrecord_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT, false);
+ return tdb1_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
}
/* unlock entire database with write lock */
@@ -634,7 +634,7 @@ int tdb1_unlockall(struct tdb1_context *tdb)
/* lock entire database with read lock */
int tdb1_lockall_read(struct tdb1_context *tdb)
{
- return tdb1_allrecord_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT, false);
+ return tdb1_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
}
/* unlock entire database with read lock */
@@ -645,25 +645,25 @@ int tdb1_unlockall_read(struct tdb1_context *tdb)
/* lock/unlock one hash chain. This is meant to be used to reduce
contention - it cannot guarantee how many records will be locked */
-int tdb1_chainlock(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key)
{
int ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
return ret;
}
-int tdb1_chainunlock(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key)
{
return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
}
-int tdb1_chainlock_read(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key)
{
int ret;
ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
return ret;
}
-int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key)
{
return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
}
@@ -674,7 +674,7 @@ int tdb1_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
if (tdb->allrecord_lock.count) {
return 0;
}
- return off ? tdb1_brlock(tdb, F_RDLCK, off, 1, TDB1_LOCK_WAIT) : 0;
+ return off ? tdb1_brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
}
/*
@@ -694,7 +694,7 @@ int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
}
return -1;
}
- return tdb1_brlock(tdb, F_WRLCK, off, 1, TDB1_LOCK_NOWAIT|TDB1_LOCK_PROBE);
+ return tdb1_brlock(tdb, F_WRLCK, off, 1, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
}
int tdb1_write_unlock_record(struct tdb1_context *tdb, tdb1_off_t off)
diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c
index e1f1605366..30c11956ac 100644
--- a/lib/tdb2/tdb1_open.c
+++ b/lib/tdb2/tdb1_open.c
@@ -34,11 +34,11 @@ static struct tdb1_context *tdb1s = NULL;
void tdb1_header_hash(struct tdb1_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash)
{
- TDB1_DATA hash_key;
+ TDB_DATA hash_key;
uint32_t tdb1_magic = TDB1_MAGIC;
- hash_key.dptr = (unsigned char *)TDB1_MAGIC_FOOD;
- hash_key.dsize = sizeof(TDB1_MAGIC_FOOD);
+ hash_key.dptr = (unsigned char *)TDB_MAGIC_FOOD;
+ hash_key.dsize = sizeof(TDB_MAGIC_FOOD);
*magic1_hash = tdb->hash_fn(&hash_key);
hash_key.dptr = (unsigned char *)TDB1_CONV(tdb1_magic);
@@ -93,7 +93,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
TDB1_CONV(*newdb);
memcpy(&tdb->header, newdb, sizeof(tdb->header));
/* Don't endian-convert the magic food! */
- memcpy(newdb->magic_food, TDB1_MAGIC_FOOD, strlen(TDB1_MAGIC_FOOD)+1);
+ memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
/* we still have "ret == -1" here */
if (tdb1_write_all(tdb->fd, newdb, size))
ret = 0;
@@ -293,7 +293,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
/* ensure there is only one process initialising at once */
- if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB1_LOCK_WAIT) == -1) {
+ if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_open_ex: failed to get open lock on %s: %s",
name, strerror(errno));
@@ -303,7 +303,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
/* we need to zero database if we are the only one with it open */
if ((tdb1_flags & TDB1_CLEAR_IF_FIRST) &&
(!tdb->read_only) &&
- (locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB1_LOCK_NOWAIT|TDB1_LOCK_PROBE) == 0))) {
+ (locked = (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) {
open_flags |= O_CREAT;
if (ftruncate(tdb->fd, 0) == -1) {
tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
@@ -316,7 +316,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
errno = 0;
if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
- || strcmp(tdb->header.magic_food, TDB1_MAGIC_FOOD) != 0) {
+ || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
if (!(open_flags & O_CREAT) || tdb1_new_database(tdb, hash_size) == -1) {
if (errno == 0) {
errno = EIO; /* ie bad format or something */
@@ -401,7 +401,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
if (tdb1_flags & TDB1_CLEAR_IF_FIRST) {
/* leave this lock in place to indicate it's in use */
- if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB1_LOCK_WAIT) == -1) {
+ if (tdb1_nest_lock(tdb, TDB1_ACTIVE_LOCK, F_RDLCK, TDB_LOCK_WAIT) == -1) {
goto fail;
}
}
diff --git a/lib/tdb2/tdb1_private.h b/lib/tdb2/tdb1_private.h
index 932e76110b..20838bfe7b 100644
--- a/lib/tdb2/tdb1_private.h
+++ b/lib/tdb2/tdb1_private.h
@@ -63,7 +63,6 @@ typedef uint32_t tdb1_off_t;
#define offsetof(t,f) ((unsigned int)&((t *)0)->f)
#endif
-#define TDB1_MAGIC_FOOD "TDB file\n"
#define TDB1_VERSION (0x26011967 + 6)
#define TDB1_MAGIC (0x26011999U)
#define TDB1_FREE_MAGIC (~TDB1_MAGIC)
@@ -131,7 +130,7 @@ struct tdb1_header {
tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */
tdb1_off_t recovery_start; /* offset of transaction recovery region */
tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */
- uint32_t magic1_hash; /* hash of TDB1_MAGIC_FOOD. */
+ uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */
uint32_t magic2_hash; /* hash of TDB1_MAGIC. */
tdb1_off_t reserved[27];
};
@@ -149,14 +148,6 @@ struct tdb1_traverse_lock {
int lock_rw;
};
-enum tdb1_lock_flags {
- /* WAIT == F_SETLKW, NOWAIT == F_SETLK */
- TDB1_LOCK_NOWAIT = 0,
- TDB1_LOCK_WAIT = 1,
- /* If set, don't log an error on failure. */
- TDB1_LOCK_PROBE = 2,
-};
-
struct tdb1_context;
struct tdb1_methods {
@@ -197,7 +188,7 @@ struct tdb1_context {
struct tdb1_traverse_lock travlocks; /* current traversal locks */
dev_t device; /* uniquely identifies this tdb */
ino_t inode; /* uniquely identifies this tdb */
- unsigned int (*hash_fn)(TDB1_DATA *key);
+ unsigned int (*hash_fn)(TDB_DATA *key);
int open_flags; /* flags used in the open - needed by reopen */
const struct tdb1_methods *methods;
struct tdb1_transaction *transaction;
@@ -212,25 +203,25 @@ int tdb1_munmap(struct tdb1_context *tdb);
void tdb1_mmap(struct tdb1_context *tdb);
int tdb1_lock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
- enum tdb1_lock_flags flags);
+ enum tdb_lock_flags flags);
int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype);
int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_brlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len,
- enum tdb1_lock_flags flags);
+ enum tdb_lock_flags flags);
int tdb1_brunlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len);
bool tdb1_have_extra_locks(struct tdb1_context *tdb);
void tdb1_release_transaction_locks(struct tdb1_context *tdb);
int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags lockflags);
+ enum tdb_lock_flags lockflags);
int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_recovery_area(struct tdb1_context *tdb,
const struct tdb1_methods *methods,
tdb1_off_t *recovery_offset,
struct tdb1_record *rec);
int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags flags, bool upgradable);
+ enum tdb_lock_flags flags, bool upgradable);
int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_allrecord_upgrade(struct tdb1_context *tdb);
int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off);
@@ -249,12 +240,12 @@ int tdb1_rec_read(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_recor
int tdb1_rec_write(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec);
int tdb1_do_delete(struct tdb1_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec);
unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t len);
-int tdb1_parse_data(struct tdb1_context *tdb, TDB1_DATA key,
+int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key,
tdb1_off_t offset, tdb1_len_t len,
- int (*parser)(TDB1_DATA key, TDB1_DATA data,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data);
-tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, int locktype,
+tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb1_record *rec);
void tdb1_io_init(struct tdb1_context *tdb);
int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size);
@@ -264,6 +255,6 @@ bool tdb1_write_all(int fd, const void *buf, size_t count);
int tdb1_transaction_recover(struct tdb1_context *tdb);
void tdb1_header_hash(struct tdb1_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash);
-unsigned int tdb1_old_hash(TDB1_DATA *key);
+unsigned int tdb1_old_hash(TDB_DATA *key);
size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off);
#endif /* CCAN_TDB2_TDB1_PRIVATE_H */
diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c
index 8023115045..c9406c4b16 100644
--- a/lib/tdb2/tdb1_tdb.c
+++ b/lib/tdb2/tdb1_tdb.c
@@ -27,7 +27,7 @@
#include "tdb1_private.h"
-TDB1_DATA tdb1_null;
+TDB_DATA tdb1_null;
/*
non-blocking increment of the tdb sequence number if the tdb has been opened using
@@ -60,7 +60,7 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
}
if (tdb1_nest_lock(tdb, TDB1_SEQNUM_OFS, F_WRLCK,
- TDB1_LOCK_WAIT|TDB1_LOCK_PROBE) != 0) {
+ TDB_LOCK_WAIT|TDB_LOCK_PROBE) != 0) {
return;
}
@@ -69,14 +69,14 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
tdb1_nest_unlock(tdb, TDB1_SEQNUM_OFS, F_WRLCK);
}
-static int tdb1_key_compare(TDB1_DATA key, TDB1_DATA data, void *private_data)
+static int tdb1_key_compare(TDB_DATA key, TDB_DATA data, void *private_data)
{
return memcmp(data.dptr, key.dptr, data.dsize);
}
/* Returns 0 on fail. On success, return offset of record, and fills
in rec */
-static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash,
+static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash,
struct tdb1_record *r)
{
tdb1_off_t rec_ptr;
@@ -111,7 +111,7 @@ static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
}
/* As tdb1_find, but if you succeed, keep the lock */
-tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, int locktype,
+tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb1_record *rec)
{
uint32_t rec_ptr;
@@ -123,13 +123,13 @@ tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t
return rec_ptr;
}
-static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key);
+static TDB_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
/* update an entry in place - this only works if the new data size
is <= the old data size and the key exists.
on failure return -1.
*/
-static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, TDB1_DATA dbuf)
+static int tdb1_update_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
{
struct tdb1_record rec;
tdb1_off_t rec_ptr;
@@ -143,7 +143,7 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
if (rec.key_len == key.dsize &&
rec.data_len == dbuf.dsize &&
rec.full_hash == hash) {
- TDB1_DATA data = _tdb1_fetch(tdb, key);
+ TDB_DATA data = _tdb1_fetch(tdb, key);
if (data.dsize == dbuf.dsize &&
memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) {
if (data.dptr) {
@@ -178,14 +178,14 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
/* find an entry in the database given a key */
/* If an entry doesn't exist tdb1_err will be set to
* TDB_ERR_NOEXIST. If a key has no data attached
- * then the TDB1_DATA will have zero length but
+ * then the TDB_DATA will have zero length but
* a non-zero pointer
*/
-static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
+static TDB_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key)
{
tdb1_off_t rec_ptr;
struct tdb1_record rec;
- TDB1_DATA ret;
+ TDB_DATA ret;
uint32_t hash;
/* find which hash bucket it is in */
@@ -200,9 +200,9 @@ static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
return ret;
}
-TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
+TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key)
{
- TDB1_DATA ret = _tdb1_fetch(tdb, key);
+ TDB_DATA ret = _tdb1_fetch(tdb, key);
return ret;
}
@@ -225,8 +225,8 @@ TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
* Return -1 if the record was not found.
*/
-int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
- int (*parser)(TDB1_DATA key, TDB1_DATA data,
+int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data)
{
@@ -258,7 +258,7 @@ int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
this doesn't match the conventions in the rest of this module, but is
compatible with gdbm
*/
-static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash)
+static int tdb1_exists_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash)
{
struct tdb1_record rec;
@@ -268,7 +268,7 @@ static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return 1;
}
-int tdb1_exists(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key)
{
uint32_t hash = tdb->hash_fn(&key);
int ret;
@@ -374,7 +374,7 @@ static int tdb1_purge_dead(struct tdb1_context *tdb, uint32_t hash)
}
/* delete an entry in the database given a key */
-static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash)
+static int tdb1_delete_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash)
{
tdb1_off_t rec_ptr;
struct tdb1_record rec;
@@ -427,7 +427,7 @@ static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return ret;
}
-int tdb1_delete(struct tdb1_context *tdb, TDB1_DATA key)
+int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key)
{
uint32_t hash = tdb->hash_fn(&key);
int ret;
@@ -465,8 +465,8 @@ static tdb1_off_t tdb1_find_dead(struct tdb1_context *tdb, uint32_t hash,
return 0;
}
-static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
- TDB1_DATA dbuf, int flag, uint32_t hash)
+static int _tdb1_store(struct tdb1_context *tdb, TDB_DATA key,
+ TDB_DATA dbuf, int flag, uint32_t hash)
{
struct tdb1_record rec;
tdb1_off_t rec_ptr;
@@ -474,7 +474,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
int ret = -1;
/* check for it existing, on insert. */
- if (flag == TDB1_INSERT) {
+ if (flag == TDB_INSERT) {
if (tdb1_exists_hash(tdb, key, hash)) {
tdb->last_error = TDB_ERR_EXISTS;
goto fail;
@@ -485,7 +485,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
goto done;
}
if (tdb->last_error == TDB_ERR_NOEXIST &&
- flag == TDB1_MODIFY) {
+ flag == TDB_MODIFY) {
/* if the record doesn't exist and we are in TDB1_MODIFY mode then
we should fail the store */
goto fail;
@@ -497,7 +497,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
/* delete any existing record - if it doesn't exist we don't
care. Doing this first reduces fragmentation, and avoids
coalescing with `allocated' block before it's updated. */
- if (flag != TDB1_INSERT)
+ if (flag != TDB_INSERT)
tdb1_delete_hash(tdb, key, hash);
/* Copy key+value *before* allocating free space in case malloc
@@ -596,7 +596,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
return 0 on success, -1 on failure
*/
-int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag)
+int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
{
uint32_t hash;
int ret;
@@ -617,10 +617,10 @@ int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag
}
/* Append to an entry. Create if not exist. */
-int tdb1_append(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA new_dbuf)
+int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
{
uint32_t hash;
- TDB1_DATA dbuf;
+ TDB_DATA dbuf;
int ret = -1;
/* find which hash bucket it is in */
@@ -819,10 +819,10 @@ struct traverse_state {
/*
traverse function for repacking
*/
-static int repack_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data, void *private_data)
+static int repack_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
{
struct traverse_state *state = (struct traverse_state *)private_data;
- if (tdb1_store(state->dest_db, key, data, TDB1_INSERT) != 0) {
+ if (tdb1_store(state->dest_db, key, data, TDB_INSERT) != 0) {
state->error = state->dest_db->last_error;
return -1;
}
diff --git a/lib/tdb2/tdb1_transaction.c b/lib/tdb2/tdb1_transaction.c
index 165fd7f972..51aa2e11b0 100644
--- a/lib/tdb2/tdb1_transaction.c
+++ b/lib/tdb2/tdb1_transaction.c
@@ -478,7 +478,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get the transaction write lock. This is a blocking lock. As
discussed with Volker, there are a number of ways we could
make this async, which we will probably do in the future */
- if (tdb1_transaction_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT) == -1) {
+ if (tdb1_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT) == -1) {
SAFE_FREE(tdb->transaction->blocks);
SAFE_FREE(tdb->transaction);
return -1;
@@ -486,7 +486,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get a read lock from the freelist to the end of file. This
is upgraded to a write lock during the commit */
- if (tdb1_allrecord_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT, true) == -1) {
+ if (tdb1_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_start: failed to get hash locks");
goto fail_allrecord_lock;
@@ -973,7 +973,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
/* get the open lock - this prevents new users attaching to the database
during the commit */
- if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB1_LOCK_WAIT) == -1) {
+ if (tdb1_nest_lock(tdb, TDB1_OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_transaction_prepare_commit:"
" failed to get open lock");
diff --git a/lib/tdb2/tdb1_traverse.c b/lib/tdb2/tdb1_traverse.c
index 13813eebbb..23897c1441 100644
--- a/lib/tdb2/tdb1_traverse.c
+++ b/lib/tdb2/tdb1_traverse.c
@@ -147,7 +147,7 @@ static int tdb1_traverse_internal(struct tdb1_context *tdb,
tdb1_traverse_func fn, void *private_data,
struct tdb1_traverse_lock *tl)
{
- TDB1_DATA key, dbuf;
+ TDB_DATA key, dbuf;
struct tdb1_record rec;
int ret = 0, count = 0;
tdb1_off_t off;
@@ -223,7 +223,7 @@ int tdb1_traverse_read(struct tdb1_context *tdb,
/* we need to get a read lock on the transaction lock here to
cope with the lock ordering semantics of solaris10 */
- if (tdb1_transaction_lock(tdb, F_RDLCK, TDB1_LOCK_WAIT)) {
+ if (tdb1_transaction_lock(tdb, F_RDLCK, TDB_LOCK_WAIT)) {
return -1;
}
@@ -253,7 +253,7 @@ int tdb1_traverse(struct tdb1_context *tdb,
return tdb1_traverse_read(tdb, fn, private_data);
}
- if (tdb1_transaction_lock(tdb, F_WRLCK, TDB1_LOCK_WAIT)) {
+ if (tdb1_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT)) {
return -1;
}
@@ -268,9 +268,9 @@ int tdb1_traverse(struct tdb1_context *tdb,
/* find the first entry in the database and return its key */
-TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb)
+TDB_DATA tdb1_firstkey(struct tdb1_context *tdb)
{
- TDB1_DATA key;
+ TDB_DATA key;
struct tdb1_record rec;
tdb1_off_t off;
@@ -298,10 +298,10 @@ TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb)
}
/* find the next entry in the database, returning its key */
-TDB1_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB1_DATA oldkey)
+TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA oldkey)
{
uint32_t oldhash;
- TDB1_DATA key = tdb1_null;
+ TDB_DATA key = tdb1_null;
struct tdb1_record rec;
unsigned char *k = NULL;
tdb1_off_t off;
diff --git a/lib/tdb2/test/run-tdb1-3G-file.c b/lib/tdb2/test/run-tdb1-3G-file.c
index fd66c047b1..6121b4de48 100644
--- a/lib/tdb2/test/run-tdb1-3G-file.c
+++ b/lib/tdb2/test/run-tdb1-3G-file.c
@@ -46,10 +46,10 @@ static const struct tdb1_methods large_io_methods = {
tdb1_expand_file_sparse
};
-static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int test_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *_data)
{
- TDB1_DATA *expect = _data;
+ TDB_DATA *expect = _data;
ok1(key.dsize == strlen("hi"));
ok1(memcmp(key.dptr, "hi", strlen("hi")) == 0);
ok1(data.dsize == expect->dsize);
@@ -60,7 +60,7 @@ static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, orig_data, data;
+ TDB_DATA key, orig_data, data;
uint32_t hash;
tdb1_off_t rec_ptr;
struct tdb1_record rec;
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
orig_data.dsize = strlen("world");
orig_data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, orig_data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
/* Transactions should work. */
ok1(tdb1_transaction_start(tdb) == 0);
- ok1(tdb1_store(tdb, key, orig_data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
diff --git a/lib/tdb2/test/run-tdb1-check.c b/lib/tdb2/test/run-tdb1-check.c
index b3b240e002..fb49b64e48 100644
--- a/lib/tdb2/test/run-tdb1-check.c
+++ b/lib/tdb2/test/run-tdb1-check.c
@@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(13);
tdb = tdb1_open_ex("run-check.tdb", 1, TDB1_CLEAR_IF_FIRST,
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
data.dsize = strlen("world");
data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
tdb1_close(tdb);
diff --git a/lib/tdb2/test/run-tdb1-corrupt.c b/lib/tdb2/test/run-tdb1-corrupt.c
index b2dcafadc0..bfc25a5711 100644
--- a/lib/tdb2/test/run-tdb1-corrupt.c
+++ b/lib/tdb2/test/run-tdb1-corrupt.c
@@ -4,7 +4,7 @@
#include <err.h>
#include "tdb1-logging.h"
-static int check(TDB1_DATA key, TDB1_DATA data, void *private)
+static int check(TDB_DATA key, TDB_DATA data, void *private)
{
unsigned int *sizes = private;
@@ -42,7 +42,7 @@ static void tdb1_flip_bit(struct tdb1_context *tdb, unsigned int bit)
static void check_test(struct tdb1_context *tdb)
{
- TDB1_DATA key, data;
+ TDB_DATA key, data;
unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize;
ok1(tdb1_check(tdb, NULL, NULL) == 0);
@@ -58,13 +58,13 @@ static void check_test(struct tdb1_context *tdb)
for (key.dsize = 1; key.dsize <= 5; key.dsize++) {
ksize += key.dsize;
dsize += data.dsize;
- if (tdb1_store(tdb, key, data, TDB1_INSERT) != 0)
+ if (tdb1_store(tdb, key, data, TDB_INSERT) != 0)
abort();
}
/* This is how many bytes we expect to be verifiable. */
/* From the file header. */
- verifiable = strlen(TDB1_MAGIC_FOOD) + 1
+ verifiable = strlen(TDB_MAGIC_FOOD) + 1
+ 2 * sizeof(uint32_t) + 2 * sizeof(tdb1_off_t)
+ 2 * sizeof(uint32_t);
/* From the free list chain and hash chains. */
diff --git a/lib/tdb2/test/run-tdb1-die-during-transaction.c b/lib/tdb2/test/run-tdb1-die-during-transaction.c
index ae03d5f8b9..3097e13a33 100644
--- a/lib/tdb2/test/run-tdb1-die-during-transaction.c
+++ b/lib/tdb2/test/run-tdb1-die-during-transaction.c
@@ -82,7 +82,7 @@ static int ftruncate_check(int fd, off_t length)
static bool test_death(enum operation op, struct agent *agent)
{
struct tdb1_context *tdb = NULL;
- TDB1_DATA key;
+ TDB_DATA key;
enum agent_return ret;
int needed_recovery = 0;
@@ -150,7 +150,7 @@ reset:
/* Put key for agent to fetch. */
key.dsize = strlen(KEY_STRING);
key.dptr = (void *)KEY_STRING;
- if (tdb1_store(tdb, key, key, TDB1_INSERT) != 0)
+ if (tdb1_store(tdb, key, key, TDB_INSERT) != 0)
return false;
/* This is the key we insert in transaction. */
@@ -168,7 +168,7 @@ reset:
if (tdb1_transaction_start(tdb) != 0)
return false;
- if (tdb1_store(tdb, key, key, TDB1_INSERT) != 0)
+ if (tdb1_store(tdb, key, key, TDB_INSERT) != 0)
return false;
if (tdb1_transaction_commit(tdb) != 0)
diff --git a/lib/tdb2/test/run-tdb1-endian.c b/lib/tdb2/test/run-tdb1-endian.c
index 7691260606..35067d7182 100644
--- a/lib/tdb2/test/run-tdb1-endian.c
+++ b/lib/tdb2/test/run-tdb1-endian.c
@@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(13);
tdb = tdb1_open_ex("run-endian.tdb", 1024,
@@ -20,12 +20,12 @@ int main(int argc, char *argv[])
data.dsize = strlen("world");
data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0);
+ ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0);
ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0);
ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
- ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
diff --git a/lib/tdb2/test/run-tdb1-incompatible.c b/lib/tdb2/test/run-tdb1-incompatible.c
index 13ba810169..51aa52d4b7 100644
--- a/lib/tdb2/test/run-tdb1-incompatible.c
+++ b/lib/tdb2/test/run-tdb1-incompatible.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <err.h>
-static unsigned int tdb1_dumb_hash(TDB1_DATA *key)
+static unsigned int tdb1_dumb_hash(TDB_DATA *key)
{
return key->dsize;
}
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
unsigned int log_count, flags;
- TDB1_DATA d;
+ TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count };
plan_tests(38 * 2);
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0);
d.dptr = (void *)"Hello";
d.dsize = 5;
- ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb);
/* Should not have marked rwlocks field. */
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0);
d.dptr = (void *)"Hello";
d.dsize = 5;
- ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb);
/* Should have marked rwlocks field. */
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0);
d.dptr = (void *)"Hello";
d.dsize = 5;
- ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb);
/* Should have marked rwlocks field. */
diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c
index e9640990e0..f9891fe70d 100644
--- a/lib/tdb2/test/run-tdb1-nested-transactions.c
+++ b/lib/tdb2/test/run-tdb1-nested-transactions.c
@@ -8,7 +8,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(27);
key.dsize = strlen("hi");
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
ok1(tdb1_transaction_start(tdb) == 0);
data.dptr = (void *)"world";
data.dsize = strlen("world");
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
diff --git a/lib/tdb2/test/run-tdb1-nested-traverse.c b/lib/tdb2/test/run-tdb1-nested-traverse.c
index 9a17b56019..a33efec735 100644
--- a/lib/tdb2/test/run-tdb1-nested-traverse.c
+++ b/lib/tdb2/test/run-tdb1-nested-traverse.c
@@ -11,19 +11,19 @@
static struct agent *agent;
-static bool correct_key(TDB1_DATA key)
+static bool correct_key(TDB_DATA key)
{
return key.dsize == strlen("hi")
&& memcmp(key.dptr, "hi", key.dsize) == 0;
}
-static bool correct_data(TDB1_DATA data)
+static bool correct_data(TDB_DATA data)
{
return data.dsize == strlen("world")
&& memcmp(data.dptr, "world", data.dsize) == 0;
}
-static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int traverse2(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p)
{
ok1(correct_key(key));
@@ -31,7 +31,7 @@ static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return 0;
}
-static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int traverse1(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p)
{
ok1(correct_key(key));
@@ -49,7 +49,7 @@ static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(17);
agent = prepare_external_agent1();
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
data.dsize = strlen("world");
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
tdb1_traverse(tdb, traverse1, NULL);
tdb1_traverse_read(tdb, traverse1, NULL);
tdb1_close(tdb);
diff --git a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c
index 570562991d..4035c78c73 100644
--- a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c
+++ b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c
@@ -17,7 +17,7 @@
static bool prepare_entries(struct tdb1_context *tdb)
{
unsigned int i;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
for (i = 0; i < NUM_ENTRIES; i++) {
key.dsize = sizeof(i);
@@ -34,7 +34,7 @@ static bool prepare_entries(struct tdb1_context *tdb)
static void delete_entries(struct tdb1_context *tdb)
{
unsigned int i;
- TDB1_DATA key;
+ TDB_DATA key;
for (i = 0; i < NUM_ENTRIES; i++) {
key.dsize = sizeof(i);
@@ -45,7 +45,7 @@ static void delete_entries(struct tdb1_context *tdb)
}
/* We don't know how many times this will run. */
-static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int delete_other(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data)
{
unsigned int i;
@@ -57,7 +57,7 @@ static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return 0;
}
-static int delete_self(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int delete_self(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data)
{
ok1(tdb1_delete(tdb, key) == 0);
diff --git a/lib/tdb2/test/run-tdb1-open-during-transaction.c b/lib/tdb2/test/run-tdb1-open-during-transaction.c
index 7b22320a73..ad6c6d6074 100644
--- a/lib/tdb2/test/run-tdb1-open-during-transaction.c
+++ b/lib/tdb2/test/run-tdb1-open-during-transaction.c
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP };
int i;
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(20);
agent = prepare_external_agent1();
@@ -164,7 +164,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
data.dsize = strlen("world");
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_transaction_commit(tdb) == 0);
ok(!errors, "We had %u open errors", errors);
diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c
index 6bfa0dc3f5..a764f2da42 100644
--- a/lib/tdb2/test/run-tdb1-readonly-check.c
+++ b/lib/tdb2/test/run-tdb1-readonly-check.c
@@ -9,7 +9,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(11);
tdb = tdb1_open_ex("run-readonly-check.tdb", 1024,
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
data.dsize = strlen("world");
data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
/* We are also allowed to do a check inside a transaction. */
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
TDB1_DEFAULT, O_RDONLY, 0, &taplogctx, NULL);
ok1(tdb);
- ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == -1);
+ ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1);
ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
ok1(tdb1_close(tdb) == 0);
diff --git a/lib/tdb2/test/run-tdb1-summary.c b/lib/tdb2/test/run-tdb1-summary.c
index ccfc0958e1..616c522507 100644
--- a/lib/tdb2/test/run-tdb1-summary.c
+++ b/lib/tdb2/test/run-tdb1-summary.c
@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP,
TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT,
TDB1_NOMMAP|TDB1_CONVERT };
- TDB1_DATA key = { (unsigned char *)&j, sizeof(j) };
- TDB1_DATA data = { (unsigned char *)&j, sizeof(j) };
+ TDB_DATA key = { (unsigned char *)&j, sizeof(j) };
+ TDB_DATA data = { (unsigned char *)&j, sizeof(j) };
char *summary;
plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
for (j = 0; j < 500; j++) {
/* Make sure padding varies to we get some graphs! */
data.dsize = j % (sizeof(j) + 1);
- if (tdb1_store(tdb, key, data, TDB1_REPLACE) != 0)
+ if (tdb1_store(tdb, key, data, TDB_REPLACE) != 0)
fail("Storing in tdb");
}
diff --git a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
index 9cb70686fe..4d3a81f19e 100644
--- a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
+++ b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c
@@ -12,19 +12,19 @@
static struct agent *agent;
-static bool correct_key(TDB1_DATA key)
+static bool correct_key(TDB_DATA key)
{
return key.dsize == strlen("hi")
&& memcmp(key.dptr, "hi", key.dsize) == 0;
}
-static bool correct_data(TDB1_DATA data)
+static bool correct_data(TDB_DATA data)
{
return data.dsize == strlen("world")
&& memcmp(data.dptr, "world", data.dsize) == 0;
}
-static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
+static int traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
void *p)
{
ok1(correct_key(key));
@@ -35,7 +35,7 @@ static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(13);
agent = prepare_external_agent1();
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
data.dsize = strlen("world");
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
diff --git a/lib/tdb2/test/run-tdb1-wronghash-fail.c b/lib/tdb2/test/run-tdb1-wronghash-fail.c
index 59bfbbeccb..368835ed7f 100644
--- a/lib/tdb2/test/run-tdb1-wronghash-fail.c
+++ b/lib/tdb2/test/run-tdb1-wronghash-fail.c
@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
unsigned int log_count;
- TDB1_DATA d;
+ TDB_DATA d;
struct tdb1_logging_context log_ctx = { log_fn, &log_count };
plan_tests(28);
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
ok1(log_count == 0);
d.dptr = (void *)"Hello";
d.dsize = 5;
- ok1(tdb1_store(tdb, d, d, TDB1_INSERT) == 0);
+ ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0);
tdb1_close(tdb);
/* Fail to open with different hash. */
diff --git a/lib/tdb2/test/run-tdb1-zero-append.c b/lib/tdb2/test/run-tdb1-zero-append.c
index e79ab60a00..1ecab54ce4 100644
--- a/lib/tdb2/test/run-tdb1-zero-append.c
+++ b/lib/tdb2/test/run-tdb1-zero-append.c
@@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(4);
tdb = tdb1_open_ex(NULL, 1024, TDB1_INTERNAL, O_CREAT|O_TRUNC|O_RDWR,
diff --git a/lib/tdb2/test/run-tdb1.c b/lib/tdb2/test/run-tdb1.c
index 30de924cd2..1f234b12e3 100644
--- a/lib/tdb2/test/run-tdb1.c
+++ b/lib/tdb2/test/run-tdb1.c
@@ -7,7 +7,7 @@
int main(int argc, char *argv[])
{
struct tdb1_context *tdb;
- TDB1_DATA key, data;
+ TDB_DATA key, data;
plan_tests(10);
tdb = tdb1_open_ex("run.tdb", 1024, TDB1_CLEAR_IF_FIRST,
@@ -19,12 +19,12 @@ int main(int argc, char *argv[])
data.dsize = strlen("world");
data.dptr = (void *)"world";
- ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0);
+ ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0);
ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
- ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0);
ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
- ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0);
+ ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c
index 7ccbd9ca37..f60df5b702 100644
--- a/lib/tdb2/test/tdb1-external-agent.c
+++ b/lib/tdb2/test/tdb1-external-agent.c
@@ -20,9 +20,9 @@ static struct tdb1_context *tdb;
static enum agent_return do_operation(enum operation op, const char *name)
{
- TDB1_DATA k;
+ TDB_DATA k;
enum agent_return ret;
- TDB1_DATA data;
+ TDB_DATA data;
if (op != OPEN && op != OPEN_WITH_CLEAR_IF_FIRST && !tdb) {
diag("external: No tdb open!");