#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 */
#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;
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);
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 */
/* 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 */
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);
/* 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;
}
/* 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;
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;
}
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;
#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. */
return c;
}
-unsigned int tdb1_jenkins_hash(TDB1_DATA *key)
+unsigned int tdb1_jenkins_hash(TDB_DATA *key)
{
return hashlittle(key->dptr, key->dsize);
}
/* 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;
*/
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;
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) {
/* 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);
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;
/* 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;
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;
}
}
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;
{
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 "
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);
}
/* 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) {
/* 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. */
* 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:
/* 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 */
/* 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 */
/* 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);
}
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;
}
/*
}
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)
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);
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;
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));
/* 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,
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 */
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;
}
}
#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)
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];
};
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 {
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;
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);
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);
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 */
#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
}
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;
}
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;
}
/* 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;
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;
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) {
/* 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 */
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;
}
* 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)
{
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;
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;
}
/* 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;
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;
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;
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;
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;
/* 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
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;
}
/* 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 */
/*
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;
}
/* 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;
/* 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;
/* 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");
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;
/* 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;
}
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;
}
/* 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;
}
/* 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;
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);
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;
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"));
/* 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"));
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,
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);
#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;
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);
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. */
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;
/* 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. */
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)
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,
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"));
#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;
}
{
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);
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. */
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. */
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. */
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");
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);
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));
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));
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();
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);
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);
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);
}
/* 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;
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);
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();
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);
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,
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. */
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);
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);
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");
}
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));
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();
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);
{
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);
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. */
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,
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,
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"));
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!");