37#ifndef __has_attribute
38#define __has_attribute(x) 0
42#if __has_attribute(visibility)
43#define _PUBLIC_ __attribute__((visibility("default")))
85#define TDB_CLEAR_IF_FIRST 1
90#define TDB_BIGENDIAN 32
93#define TDB_VOLATILE 256
94#define TDB_ALLOW_NESTING 512
95#define TDB_DISALLOW_NESTING 1024
96#define TDB_INCOMPATIBLE_HASH 2048
97#define TDB_MUTEX_LOCKING 4096
102enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
103 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
104 TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY,
109 TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
117#ifndef PRINTF_ATTRIBUTE
118#if __has_attribute(format) || (__GNUC__ >= 3)
123#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
125#define PRINTF_ATTRIBUTE(a1, a2)
132typedef int (*tdb_traverse_func)(
struct tdb_context *,
TDB_DATA,
TDB_DATA,
void *);
133typedef void (*tdb_log_func)(
struct tdb_context *,
enum tdb_debug_level,
const char *, ...) PRINTF_ATTRIBUTE(3, 4);
134typedef unsigned int (*tdb_hash_func)(
TDB_DATA *key);
136struct tdb_logging_context {
175_PUBLIC_
struct tdb_context *
tdb_open(
const char *name,
int hash_size,
int tdb_flags,
176 int open_flags, mode_t mode);
222_PUBLIC_
struct tdb_context *
tdb_open_ex(
const char *name,
int hash_size,
int tdb_flags,
223 int open_flags, mode_t mode,
224 const struct tdb_logging_context *log_ctx,
225 tdb_hash_func hash_fn);
249_PUBLIC_
int tdb_reopen(
struct tdb_context *tdb);
293_PUBLIC_
const char *
tdb_errorstr(
struct tdb_context *tdb);
397 const TDB_DATA *dbufs,
int num_dbufs,
int flag);
427_PUBLIC_
int tdb_close(
struct tdb_context *tdb);
475_PUBLIC_
int tdb_traverse(
struct tdb_context *tdb, tdb_traverse_func fn,
void *private_data);
494_PUBLIC_
int tdb_traverse_read(
struct tdb_context *tdb, tdb_traverse_func fn,
void *private_data);
529 tdb_traverse_func fn,
561 tdb_traverse_func fn,
695_PUBLIC_
const char *
tdb_name(
struct tdb_context *tdb);
707_PUBLIC_
int tdb_fd(
struct tdb_context *tdb);
720_PUBLIC_ tdb_log_func
tdb_log_fn(
struct tdb_context *tdb);
897_PUBLIC_
void tdb_add_flags(
struct tdb_context *tdb,
unsigned flag);
960_PUBLIC_
int tdb_check(
struct tdb_context *tdb,
982_PUBLIC_
int tdb_rescue(
struct tdb_context *tdb,
1010_PUBLIC_
int tdb_chainlock(
struct tdb_context *tdb,
TDB_DATA key);
1011_PUBLIC_
int tdb_chainlock_nonblock(
struct tdb_context *tdb,
TDB_DATA key);
1012_PUBLIC_
int tdb_chainunlock(
struct tdb_context *tdb,
TDB_DATA key);
1013_PUBLIC_
int tdb_chainlock_read(
struct tdb_context *tdb,
TDB_DATA key);
1014_PUBLIC_
int tdb_chainlock_read_nonblock(
struct tdb_context *tdb,
TDB_DATA key);
1015_PUBLIC_
int tdb_chainunlock_read(
struct tdb_context *tdb,
TDB_DATA key);
1016_PUBLIC_
int tdb_chainlock_mark(
struct tdb_context *tdb,
TDB_DATA key);
1017_PUBLIC_
int tdb_chainlock_unmark(
struct tdb_context *tdb,
TDB_DATA key);
1019_PUBLIC_
void tdb_setalarm_sigptr(
struct tdb_context *tdb,
volatile sig_atomic_t *sigptr);
1022_PUBLIC_
int tdb_wipe_all(
struct tdb_context *tdb);
1023_PUBLIC_
int tdb_repack(
struct tdb_context *tdb);
1026_PUBLIC_
void tdb_dump_all(
struct tdb_context *tdb);
1027_PUBLIC_
int tdb_printfreelist(
struct tdb_context *tdb);
1028_PUBLIC_
int tdb_validate_freelist(
struct tdb_context *tdb,
int *pnum_entries);
1029_PUBLIC_
int tdb_freelist_size(
struct tdb_context *tdb);
1030_PUBLIC_
char *tdb_summary(
struct tdb_context *tdb);
_PUBLIC_ int tdb_transaction_start_nonblock(struct tdb_context *tdb)
Start a transaction, non-blocking.
_PUBLIC_ int tdb_lockall_unmark(struct tdb_context *tdb)
Lock entire database with write lock - unmark only.
_PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb)
Get the tdb sequence number.
_PUBLIC_ int tdb_lockall_read(struct tdb_context *tdb)
Lock entire database with a read lock.
TDB_ERROR
The tdb error codes.
Definition: tdb.h:100
_PUBLIC_ bool tdb_transaction_active(struct tdb_context *tdb)
Is a transaction active?
_PUBLIC_ int tdb_transaction_commit(struct tdb_context *tdb)
Commit a current transaction.
_PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb)
Get the map size.
_PUBLIC_ unsigned int tdb_jenkins_hash(TDB_DATA *key)
Create a hash of the key.
_PUBLIC_ void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx)
Set a different tdb logging function.
struct TDB_DATA TDB_DATA
The tdb data structure.
_PUBLIC_ void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
Increment the tdb sequence number.
struct tdb_context TDB_CONTEXT
This is the context structure that is returned from a db open.
Definition: tdb.h:128
_PUBLIC_ int tdb_exists(struct tdb_context *tdb, TDB_DATA key)
Check if an entry in the database exists.
_PUBLIC_ int tdb_check(struct tdb_context *tdb, int(*check)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data)
Check the consistency of the database.
_PUBLIC_ void tdb_set_max_dead(struct tdb_context *tdb, int max_dead)
Set the maximum number of dead records per hash chain.
_PUBLIC_ int tdb_delete(struct tdb_context *tdb, TDB_DATA key)
Delete an entry in the database given a key.
_PUBLIC_ int tdb_traverse_chain(struct tdb_context *tdb, unsigned chain, tdb_traverse_func fn, void *private_data)
Traverse a single hash chain.
_PUBLIC_ TDB_DATA tdb_firstkey(struct tdb_context *tdb)
Find the first entry in the database and return its key.
_PUBLIC_ int tdb_lockall_mark(struct tdb_context *tdb)
Lock entire database with write lock - mark only.
_PUBLIC_ int tdb_lockall_read_nonblock(struct tdb_context *tdb)
Lock entire database with a read lock.
_PUBLIC_ int tdb_traverse_key_chain(struct tdb_context *tdb, TDB_DATA key, tdb_traverse_func fn, void *private_data)
Traverse a single hash chain.
_PUBLIC_ const char * tdb_name(struct tdb_context *tdb)
Get the name of the current tdb file.
_PUBLIC_ int tdb_hash_size(struct tdb_context *tdb)
Get the hash size.
_PUBLIC_ tdb_log_func tdb_log_fn(struct tdb_context *tdb)
Get the current logging function.
_PUBLIC_ int tdb_lockall_nonblock(struct tdb_context *tdb)
Lock entire database with a write lock.
_PUBLIC_ int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *private_data)
Traverse the entire database.
_PUBLIC_ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key)
Find the next entry in the database, returning its key.
_PUBLIC_ void tdb_add_flags(struct tdb_context *tdb, unsigned flag)
Add flags to the database.
_PUBLIC_ enum TDB_ERROR tdb_error(struct tdb_context *tdb)
Get the tdb last error code.
_PUBLIC_ int tdb_get_flags(struct tdb_context *tdb)
Get the tdb flags set during open.
_PUBLIC_ void tdb_remove_flags(struct tdb_context *tdb, unsigned flag)
Remove flags from the database.
_PUBLIC_ int tdb_transaction_prepare_commit(struct tdb_context *tdb)
Prepare to commit a current transaction, for two-phase commits.
_PUBLIC_ int tdb_storev(struct tdb_context *tdb, TDB_DATA key, const TDB_DATA *dbufs, int num_dbufs, int flag)
Store an element in the database.
_PUBLIC_ struct tdb_context * tdb_open(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode)
Open the database and creating it if necessary.
_PUBLIC_ int tdb_reopen(struct tdb_context *tdb)
Reopen a tdb.
_PUBLIC_ int tdb_reopen_all(int parent_longlived)
Reopen all tdb's.
_PUBLIC_ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
Append data to an entry.
_PUBLIC_ int tdb_rescue(struct tdb_context *tdb, void(*walk)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data)
Dump all possible records in a corrupt database.
_PUBLIC_ int tdb_lockall(struct tdb_context *tdb)
Lock entire database with a write lock.
_PUBLIC_ int tdb_close(struct tdb_context *tdb)
Close a database.
_PUBLIC_ struct tdb_context * tdb_open_ex(const char *name, int hash_size, int tdb_flags, int open_flags, mode_t mode, const struct tdb_logging_context *log_ctx, tdb_hash_func hash_fn)
Open the database and creating it if necessary.
_PUBLIC_ int tdb_unlockall_read(struct tdb_context *tdb)
Unlock entire database with read lock.
_PUBLIC_ int tdb_transaction_cancel(struct tdb_context *tdb)
Cancel a current transaction.
_PUBLIC_ int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *private_data)
Traverse the entire database.
_PUBLIC_ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, int(*parser)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data)
Hand a record to a parser function without allocating it.
_PUBLIC_ const char * tdb_errorstr(struct tdb_context *tdb)
Get a error string for the last tdb error.
_PUBLIC_ bool tdb_runtime_check_for_robust_mutexes(void)
Check if support for TDB_MUTEX_LOCKING is available at runtime.
_PUBLIC_ int tdb_fd(struct tdb_context *tdb)
Get the underlying file descriptor being used by tdb.
_PUBLIC_ void * tdb_get_logging_private(struct tdb_context *tdb)
Get the private data of the logging function.
_PUBLIC_ TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
Fetch an entry in the database given a key.
tdb_debug_level
Debugging uses one of the following levels.
Definition: tdb.h:106
_PUBLIC_ int tdb_unlockall(struct tdb_context *tdb)
Unlock entire database with write lock.
_PUBLIC_ void tdb_enable_seqnum(struct tdb_context *tdb)
Enable sequence number handling on an open tdb.
_PUBLIC_ int tdb_transaction_start(struct tdb_context *tdb)
Start a transaction.
_PUBLIC_ int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
Store an element in the database.
The tdb data structure.
Definition: tdb.h:110