+/**
+ * enum TDB_ERROR - error returns for TDB
+ *
+ * See Also:
+ * tdb_errorstr()
+ */
+enum TDB_ERROR {
+ TDB_SUCCESS = 0, /* No error. */
+ TDB_ERR_CORRUPT = -1, /* We read the db, and it was bogus. */
+ TDB_ERR_IO = -2, /* We couldn't read/write the db. */
+ TDB_ERR_LOCK = -3, /* Locking failed. */
+ TDB_ERR_OOM = -4, /* Out of Memory. */
+ TDB_ERR_EXISTS = -5, /* The key already exists. */
+ TDB_ERR_NOEXIST = -6, /* The key does not exist. */
+ TDB_ERR_EINVAL = -7, /* You're using it wrong. */
+ TDB_ERR_RDONLY = -8, /* The database is read-only. */
+ TDB_ERR_LAST = TDB_ERR_RDONLY
+};
+
+/**
+ * tdb_store - store a key/value pair in a tdb.
+ * @tdb: the tdb context returned from tdb_open()
+ * @key: the key
+ * @dbuf: the data to associate with the key.
+ * @flag: TDB_REPLACE, TDB_INSERT or TDB_MODIFY.
+ *
+ * This inserts (or overwrites) a key/value pair in the TDB. If flag
+ * is TDB_REPLACE, it doesn't matter whether the key exists or not;
+ * TDB_INSERT means it must not exist (TDB_ERR_EXISTS otherwise),
+ * and TDB_MODIFY means it must exist (TDB_ERR_NOEXIST otherwise).
+ *
+ * On success, this returns 0, on failure -1, and sets tdb_error().
+ *
+ * See also:
+ * tdb_fetch, tdb_transaction_start, tdb_append, tdb_delete.
+ */
+int tdb_store(struct tdb_context *tdb,
+ struct tdb_data key,
+ struct tdb_data dbuf,
+ int flag);
+
+/* flags to tdb_store() */
+#define TDB_REPLACE 1 /* A readability place holder */
+#define TDB_INSERT 2 /* Don't overwrite an existing entry */
+#define TDB_MODIFY 3 /* Don't create an existing entry */
+
+/**
+ * tdb_fetch - fetch a value from a tdb.
+ * @tdb: the tdb context returned from tdb_open()
+ * @key: the key
+ *
+ * This looks up a key in the database and returns it, or returns tdb_null
+ * and sets tdb_error() if there's a problem (usually, TDB_ERR_NOEXIST).
+ *
+ * It is your responsibility to call free() on the returned structure's
+ * dptr.
+ */
+struct tdb_data tdb_fetch(struct tdb_context *tdb, struct tdb_data key);
+
+/**
+ * enum TDB_ERROR - error codes for TDB
+ *
+ * See Also:
+ * tdb_error(), tdb_errorstr()
+ */
+
+/**
+ * tdb_error - fetch the last error value from the tdb.
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This returns the last error, or TDB_SUCCESS. It always returns TDB_SUCCESS
+ * immediately after tdb_open() returns the (non-NULL) tdb context.
+ *
+ * See Also:
+ * tdb_errorstr()
+ */
+enum TDB_ERROR tdb_error(const struct tdb_context *tdb);
+
+/**
+ * tdb_errorstr - map the tdb error onto a constant readable string
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This is more useful for displaying errors to users than tdb_error.
+ *
+ * See Also:
+ * tdb_error()
+ */
+const char *tdb_errorstr(const struct tdb_context *tdb);
+
+/**
+ * tdb_append - append a value to a key/value pair in a tdb.
+ * @tdb: the tdb context returned from tdb_open()
+ * @key: the key
+ * @dbuf: the data to append.
+ *
+ * This is equivalent to fetching a record, reallocating .dptr to add the
+ * data, and writing it back, only it's much more efficient. If the key
+ * doesn't exist, it's equivalent to tdb_store (with an additional hint that
+ * you expect to expand the record in future).
+ *
+ * Returns 0 on success, -1 on failure (and sets tdb_error()).
+ *
+ * See Also:
+ * tdb_fetch(), tdb_store()
+ */
+int tdb_append(struct tdb_context *tdb,
+ struct tdb_data key,
+ struct tdb_data dbuf);
+
+/**
+ * tdb_delete - delete a key from a tdb.
+ * @tdb: the tdb context returned from tdb_open()
+ * @key: the key to delete.
+ *
+ * Returns 0 on success, or -1 on error (usually tdb_error() would be
+ * TDB_ERR_NOEXIST in that case).
+ *
+ * See Also:
+ * tdb_fetch(), tdb_store()
+ */
+int tdb_delete(struct tdb_context *tdb, struct tdb_data key);
+
+/**
+ * tdb_transaction_start - start a transaction
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This begins a series of atomic operations. Other processes will be able
+ * to read the tdb, but not alter it (they will block), nor will they see
+ * any changes until tdb_transaction_commit() is called.
+ *
+ * On failure, returns -1 and sets tdb_error().
+ *
+ * See Also:
+ * tdb_transaction_cancel, tdb_transaction_commit.
+ */
+int tdb_transaction_start(struct tdb_context *tdb);
+
+/**
+ * tdb_transaction_cancel - abandon a transaction
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This aborts a transaction, discarding any changes which were made.
+ * tdb_close() does this implicitly.
+ */
+void tdb_transaction_cancel(struct tdb_context *tdb);
+
+/**
+ * tdb_transaction_commit - commit a transaction
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This completes a transaction, writing any changes which were made.
+ *
+ * fsync() is used to commit the transaction (unless TDB_NOSYNC is set),
+ * making it robust against machine crashes, but very slow compared to
+ * other TDB operations.
+ *
+ * Returns 0 on success, or -1 on failure: this can only be caused by
+ * unexpected errors (eg. I/O or memory); this is no point looping on
+ * transaction failure.
+ *
+ * See Also:
+ * tdb_transaction_prepare_commit()
+ */
+int tdb_transaction_commit(struct tdb_context *tdb);
+
+/**
+ * tdb_transaction_prepare_commit - prepare to commit a transaction
+ * @tdb: the tdb context returned from tdb_open()
+ *
+ * This ensures we have the resources to commit a transaction (using
+ * tdb_transaction_commit): if this succeeds then a transaction will only
+ * fail if the write() or fsync() calls fail.
+ *
+ * Returns 0 on success, or -1 on failure.
+ *
+ * See Also:
+ * tdb_transaction_commit()
+ */
+int tdb_transaction_prepare_commit(struct tdb_context *tdb);