5 Unix SMB/CIFS implementation.
7 trivial database library
9 Copyright (C) Andrew Tridgell 1999-2004
11 ** NOTE! The following LGPL license applies to the tdb
12 ** library. This does NOT imply that all of Samba is released
15 This library is free software; you can redistribute it and/or
16 modify it under the terms of the GNU Lesser General Public
17 License as published by the Free Software Foundation; either
18 version 2 of the License, or (at your option) any later version.
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 /* flags to tdb_store() */
40 /* flags for tdb_open() */
41 #define TDB_DEFAULT 0 /* just a readability place holder */
42 #define TDB_CLEAR_IF_FIRST 1
43 #define TDB_INTERNAL 2 /* don't store on disk */
44 #define TDB_NOLOCK 4 /* don't do any locking */
45 #define TDB_NOMMAP 8 /* don't use mmap */
46 #define TDB_CONVERT 16 /* convert endian (internal use) */
47 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
48 #define TDB_NOSYNC 64 /* don't use synchronous transactions */
50 #define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
53 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
54 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
55 TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY};
57 typedef struct TDB_DATA {
62 #ifndef PRINTF_ATTRIBUTE
64 /** Use gcc attribute to check printf fns. a1 is the 1-based index of
65 * the parameter containing the format, and a2 the index of the first
66 * argument. Note that some gcc 2.x versions don't handle this
68 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
70 #define PRINTF_ATTRIBUTE(a1, a2)
74 /* this is the context structure that is returned from a db open */
75 typedef struct tdb_context TDB_CONTEXT;
77 typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
78 typedef void (*tdb_log_func)(struct tdb_context *, int , const char *, ...);
79 typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
81 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
82 int open_flags, mode_t mode);
83 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
84 int open_flags, mode_t mode,
86 tdb_hash_func hash_fn);
88 int tdb_reopen(struct tdb_context *tdb);
89 int tdb_reopen_all(void);
90 void tdb_logging_function(struct tdb_context *tdb, tdb_log_func);
91 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
92 const char *tdb_errorstr(struct tdb_context *tdb);
93 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
94 int tdb_delete(struct tdb_context *tdb, TDB_DATA key);
95 int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
96 int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
97 int tdb_close(struct tdb_context *tdb);
98 TDB_DATA tdb_firstkey(struct tdb_context *tdb);
99 TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
100 int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *);
101 int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *);
102 int tdb_exists(struct tdb_context *tdb, TDB_DATA key);
103 int tdb_lockall(struct tdb_context *tdb);
104 void tdb_unlockall(struct tdb_context *tdb);
105 const char *tdb_name(struct tdb_context *tdb);
106 int tdb_fd(struct tdb_context *tdb);
107 tdb_log_func tdb_log_fn(struct tdb_context *tdb);
108 int tdb_transaction_start(struct tdb_context *tdb);
109 int tdb_transaction_commit(struct tdb_context *tdb);
110 int tdb_transaction_cancel(struct tdb_context *tdb);
111 int tdb_transaction_recover(struct tdb_context *tdb);
113 /* Low level locking functions: use with care */
114 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
115 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
116 int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
117 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
119 /* Debug functions. Not used in production. */
120 void tdb_dump_all(struct tdb_context *tdb);
121 int tdb_printfreelist(struct tdb_context *tdb);
123 extern TDB_DATA tdb_null;