r23798: updated old Temple Place FSF addresses to new URL
[Samba.git] / source / lib / tdb / include / tdb.h
bloba75df2d7d5376b3a1b2bd7583685945ca4150000
1 #ifndef __TDB_H__
2 #define __TDB_H__
4 /*
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
13 ** under the LGPL
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 3 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, see <http://www.gnu.org/licenses/>.
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
34 /* flags to tdb_store() */
35 #define TDB_REPLACE 1
36 #define TDB_INSERT 2
37 #define TDB_MODIFY 3
39 /* flags for tdb_open() */
40 #define TDB_DEFAULT 0 /* just a readability place holder */
41 #define TDB_CLEAR_IF_FIRST 1
42 #define TDB_INTERNAL 2 /* don't store on disk */
43 #define TDB_NOLOCK 4 /* don't do any locking */
44 #define TDB_NOMMAP 8 /* don't use mmap */
45 #define TDB_CONVERT 16 /* convert endian (internal use) */
46 #define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */
47 #define TDB_NOSYNC 64 /* don't use synchronous transactions */
48 #define TDB_SEQNUM 128 /* maintain a sequence number */
49 #define TDB_VOLATILE 256 /* Activate the per-hashchain freelist, default 5 */
51 #define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret)
53 /* error codes */
54 enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
55 TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT,
56 TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY};
58 /* debugging uses one of the following levels */
59 enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR,
60 TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
62 typedef struct TDB_DATA {
63 unsigned char *dptr;
64 size_t dsize;
65 } TDB_DATA;
67 #ifndef PRINTF_ATTRIBUTE
68 #if (__GNUC__ >= 3)
69 /** Use gcc attribute to check printf fns. a1 is the 1-based index of
70 * the parameter containing the format, and a2 the index of the first
71 * argument. Note that some gcc 2.x versions don't handle this
72 * properly **/
73 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
74 #else
75 #define PRINTF_ATTRIBUTE(a1, a2)
76 #endif
77 #endif
79 /* this is the context structure that is returned from a db open */
80 typedef struct tdb_context TDB_CONTEXT;
82 typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
83 typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
84 typedef unsigned int (*tdb_hash_func)(TDB_DATA *key);
86 struct tdb_logging_context {
87 tdb_log_func log_fn;
88 void *log_private;
91 struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags,
92 int open_flags, mode_t mode);
93 struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
94 int open_flags, mode_t mode,
95 const struct tdb_logging_context *log_ctx,
96 tdb_hash_func hash_fn);
97 void tdb_set_max_dead(struct tdb_context *tdb, int max_dead);
99 int tdb_reopen(struct tdb_context *tdb);
100 int tdb_reopen_all(int parent_longlived);
101 void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx);
102 enum TDB_ERROR tdb_error(struct tdb_context *tdb);
103 const char *tdb_errorstr(struct tdb_context *tdb);
104 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key);
105 int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
106 int (*parser)(TDB_DATA key, TDB_DATA data,
107 void *private_data),
108 void *private_data);
109 int tdb_delete(struct tdb_context *tdb, TDB_DATA key);
110 int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
111 int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
112 int tdb_close(struct tdb_context *tdb);
113 TDB_DATA tdb_firstkey(struct tdb_context *tdb);
114 TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key);
115 int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *);
116 int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *);
117 int tdb_exists(struct tdb_context *tdb, TDB_DATA key);
118 int tdb_lockall(struct tdb_context *tdb);
119 int tdb_unlockall(struct tdb_context *tdb);
120 int tdb_lockall_read(struct tdb_context *tdb);
121 int tdb_unlockall_read(struct tdb_context *tdb);
122 const char *tdb_name(struct tdb_context *tdb);
123 int tdb_fd(struct tdb_context *tdb);
124 tdb_log_func tdb_log_fn(struct tdb_context *tdb);
125 void *tdb_get_logging_private(struct tdb_context *tdb);
126 int tdb_transaction_start(struct tdb_context *tdb);
127 int tdb_transaction_commit(struct tdb_context *tdb);
128 int tdb_transaction_cancel(struct tdb_context *tdb);
129 int tdb_transaction_recover(struct tdb_context *tdb);
130 int tdb_get_seqnum(struct tdb_context *tdb);
131 int tdb_hash_size(struct tdb_context *tdb);
132 size_t tdb_map_size(struct tdb_context *tdb);
133 int tdb_get_flags(struct tdb_context *tdb);
135 /* Low level locking functions: use with care */
136 int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
137 int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
138 int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
139 int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
141 /* Debug functions. Not used in production. */
142 void tdb_dump_all(struct tdb_context *tdb);
143 int tdb_printfreelist(struct tdb_context *tdb);
144 int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries);
146 extern TDB_DATA tdb_null;
148 #ifdef __cplusplus
150 #endif
152 #endif /* tdb.h */