]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/tdb1.h
3869373fbe8b47cdbae4c0d2f4c03fc47f0173c2
[ccan] / ccan / tdb2 / tdb1.h
1 #ifndef TDB1_H
2 #define TDB1_H
3
4 /*
5    Unix SMB/CIFS implementation.
6
7    trivial database library (version 1 compat functions)
8
9    Copyright (C) Andrew Tridgell 1999-2004
10    Copyright (C) Rusty Russell 2011
11
12      ** NOTE! The following LGPL license applies to the tdb
13      ** library. This does NOT imply that all of Samba is released
14      ** under the LGPL
15
16    This library is free software; you can redistribute it and/or
17    modify it under the terms of the GNU Lesser General Public
18    License as published by the Free Software Foundation; either
19    version 3 of the License, or (at your option) any later version.
20
21    This library is distributed in the hope that it will be useful,
22    but WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24    Lesser General Public License for more details.
25
26    You should have received a copy of the GNU Lesser General Public
27    License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 */
29 #include "tdb2.h"
30
31 #ifndef _SAMBA_BUILD_
32 /* For mode_t */
33 #include <sys/types.h>
34 /* For O_* flags. */
35 #include <sys/stat.h>
36 #endif
37
38
39 /** Flags for tdb1_open() */
40 #define TDB1_DEFAULT 0 /** just a readability place holder */
41 #define TDB1_CLEAR_IF_FIRST 1 /** If this is the first open, wipe the db */
42 #define TDB1_INTERNAL 2 /** Don't store on disk */
43 #define TDB1_NOLOCK   4 /** Don't do any locking */
44 #define TDB1_NOMMAP   8 /** Don't use mmap */
45 #define TDB1_CONVERT 16 /** Convert endian (internal use) */
46 #define TDB1_BIGENDIAN 32 /** Header is big-endian (internal use) */
47 #define TDB1_NOSYNC   64 /** Don't use synchronous transactions */
48 #define TDB1_SEQNUM   128 /** Maintain a sequence number */
49 #define TDB1_VOLATILE   256 /** Activate the per-hashchain freelist, default 5 */
50 #define TDB1_ALLOW_NESTING 512 /** Allow transactions to nest */
51 #define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */
52
53 /** This is the context structure that is returned from a db open. */
54 typedef struct tdb1_context TDB1_CONTEXT;
55
56 typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB_DATA, TDB_DATA, void *);
57 typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb_log_level, enum TDB_ERROR,
58                               const char *, void *);
59 typedef unsigned int (*tdb1_hash_func)(TDB_DATA *key);
60
61 struct tdb1_logging_context {
62         tdb1_log_func log_fn;
63         void *log_private;
64 };
65
66 struct tdb1_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
67                       int open_flags, mode_t mode);
68
69 struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
70                          int open_flags, mode_t mode,
71                          const struct tdb1_logging_context *log_ctx,
72                          tdb1_hash_func hash_fn);
73
74 void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead);
75
76 TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
77
78 int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
79                               int (*parser)(TDB_DATA key, TDB_DATA data,
80                                             void *private_data),
81                               void *private_data);
82
83 int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key);
84
85 int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
86
87 int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
88
89 int tdb1_close(struct tdb1_context *tdb);
90
91 TDB_DATA tdb1_firstkey(struct tdb1_context *tdb);
92
93 TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA key);
94
95 int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
96
97 int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
98
99 int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key);
100
101 int tdb1_lockall(struct tdb1_context *tdb);
102
103 int tdb1_unlockall(struct tdb1_context *tdb);
104
105 int tdb1_lockall_read(struct tdb1_context *tdb);
106
107 int tdb1_unlockall_read(struct tdb1_context *tdb);
108
109 int tdb1_transaction_start(struct tdb1_context *tdb);
110
111 int tdb1_transaction_prepare_commit(struct tdb1_context *tdb);
112
113 int tdb1_transaction_commit(struct tdb1_context *tdb);
114
115 int tdb1_transaction_cancel(struct tdb1_context *tdb);
116
117 int tdb1_get_seqnum(struct tdb1_context *tdb);
118
119 int tdb1_hash_size(struct tdb1_context *tdb);
120
121 void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb);
122
123 unsigned int tdb1_incompatible_hash(TDB_DATA *key);
124
125 int tdb1_check(struct tdb1_context *tdb,
126               int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
127               void *private_data);
128
129 /* @} ******************************************************************/
130
131 /* Low level locking functions: use with care */
132 int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key);
133 int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key);
134 int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key);
135 int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key);
136
137
138 /* wipe and repack */
139 int tdb1_wipe_all(struct tdb1_context *tdb);
140 int tdb1_repack(struct tdb1_context *tdb);
141
142 /* Debug functions. Not used in production. */
143 char *tdb1_summary(struct tdb1_context *tdb);
144
145 extern TDB_DATA tdb1_null;
146
147 #endif /* tdb1.h */