diff options
author | Andrew Tridgell <tridge@samba.org> | 1999-12-21 11:44:43 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1999-12-21 11:44:43 +0000 |
commit | d171864c93c9772414fbe10219e9a19744a5a3be (patch) | |
tree | 875881c9660ef22b2f925416f650d21dabdd9602 /source3/tdb | |
parent | 3da55bfb8e161a704d37b7c148ea4d07dc0111b4 (diff) | |
download | samba-d171864c93c9772414fbe10219e9a19744a5a3be.tar.gz samba-d171864c93c9772414fbe10219e9a19744a5a3be.tar.bz2 samba-d171864c93c9772414fbe10219e9a19744a5a3be.zip |
expanded the tdb documentation
(This used to be commit efb4fbcca876ec661af0d72d4df2f04f36d4dd76)
Diffstat (limited to 'source3/tdb')
-rw-r--r-- | source3/tdb/README | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/source3/tdb/README b/source3/tdb/README index 3c0059c5cb..f4fa30dc64 100644 --- a/source3/tdb/README +++ b/source3/tdb/README @@ -1,3 +1,7 @@ +tdb - a trivial database system +tridge@linuxcare.com December 1999 +================================== + This is a simple database API. It was inspired by the realisation that in Samba we have several ad-hoc bits of code that essentially implement small databases for sharing structures between parts of @@ -38,3 +42,109 @@ The interface is very similar to gdbm except for the following: - no tdbm_sync() function. No operations are cached in the library anyway - added a tdb_traverse() function for traversing the whole database +A general rule for using tdb is that the caller frees any returned +TDB_DATA structures. Just call free(p.dptr) to free a TDB_DATA +return value called p. This is the same as gdbm. + +here is a full list of tdb functions with brief descriptions. + + +---------------------------------------------------------------------- +TDB_CONTEXT *tdb_open(char *name, int hash_size, int flags, mode_t mode); + + open the database, creating it if necessary + + The flags and mode are passed straight to the open call on the database + file. A flags value of O_WRONLY is invalid + + The hash size is advisory, use zero for a default value. + + return is NULL on error + +---------------------------------------------------------------------- +int tdb_close(TDB_CONTEXT *tdb); + + close a database + +---------------------------------------------------------------------- +int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf); + + 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 + +---------------------------------------------------------------------- +TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); + + fetch an entry in the database given a key + if the return value has a null dptr then a error occurred + + caller must free the resulting data + +---------------------------------------------------------------------- +int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); + + check if an entry in the database exists + + note that 1 is returned if the key is found and 0 is returned if not found + this doesn't match the conventions in the rest of this module, but is + compatible with gdbm + +---------------------------------------------------------------------- +int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, + TDB_DATA key, TDB_DATA dbuf)); + + traverse the entire database - calling fn(tdb, key, data) on each element. + + return -1 on error or the record count traversed + + if fn is NULL then it is not called + + a non-zero return value from fn() indicates that the traversal should stop + +---------------------------------------------------------------------- +TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); + + find the first entry in the database and return its key + + the caller must free the returned data + +---------------------------------------------------------------------- +TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); + + find the next entry in the database, returning its key + + the caller must free the returned data + +---------------------------------------------------------------------- +int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key); + + delete an entry in the database given a key + +---------------------------------------------------------------------- +int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); + + store an element in the database, replacing any existing element + with the same key + + return 0 on success, -1 on failure + +---------------------------------------------------------------------- +int tdb_writelock(TDB_CONTEXT *tdb); + + lock the database. If we already have it locked then don't do anything + +---------------------------------------------------------------------- +int tdb_writeunlock(TDB_CONTEXT *tdb); + unlock the database + +---------------------------------------------------------------------- +int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key); + + lock one hash chain. This is meant to be used to reduce locking + contention - it cannot guarantee how many records will be locked + +---------------------------------------------------------------------- +int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key); + + unlock one hash chain |