]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/tdb1.h
tdb2: Make TDB1 use the same tdb_hash() wrapper as TDB2
[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 /** This is the context structure that is returned from a db open. */
40 typedef struct tdb1_context TDB1_CONTEXT;
41
42 typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB_DATA, TDB_DATA, void *);
43 typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb_log_level, enum TDB_ERROR,
44                               const char *, void *);
45 typedef uint64_t (*tdb1_hash_func)(const void *key, size_t len, uint64_t seed,
46                                    void *data);
47
48 struct tdb1_logging_context {
49         tdb1_log_func log_fn;
50         void *log_private;
51 };
52
53 struct tdb1_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
54                       int open_flags, mode_t mode);
55
56 struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
57                          int open_flags, mode_t mode,
58                          const struct tdb1_logging_context *log_ctx,
59                          tdb1_hash_func hash_fn);
60
61 void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead);
62
63 TDB_DATA tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key);
64
65 int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key,
66                               int (*parser)(TDB_DATA key, TDB_DATA data,
67                                             void *private_data),
68                               void *private_data);
69
70 int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key);
71
72 int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
73
74 int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
75
76 int tdb1_close(struct tdb1_context *tdb);
77
78 TDB_DATA tdb1_firstkey(struct tdb1_context *tdb);
79
80 TDB_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB_DATA key);
81
82 int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
83
84 int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
85
86 int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key);
87
88 int tdb1_lockall(struct tdb1_context *tdb);
89
90 int tdb1_unlockall(struct tdb1_context *tdb);
91
92 int tdb1_lockall_read(struct tdb1_context *tdb);
93
94 int tdb1_unlockall_read(struct tdb1_context *tdb);
95
96 int tdb1_transaction_start(struct tdb1_context *tdb);
97
98 int tdb1_transaction_prepare_commit(struct tdb1_context *tdb);
99
100 int tdb1_transaction_commit(struct tdb1_context *tdb);
101
102 int tdb1_transaction_cancel(struct tdb1_context *tdb);
103
104 int tdb1_get_seqnum(struct tdb1_context *tdb);
105
106 int tdb1_hash_size(struct tdb1_context *tdb);
107
108 void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb);
109
110 uint64_t tdb1_incompatible_hash(const void *key, size_t len, uint64_t seed, void *);
111
112 int tdb1_check(struct tdb1_context *tdb,
113               int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
114               void *private_data);
115
116 /* @} ******************************************************************/
117
118 /* Low level locking functions: use with care */
119 int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key);
120 int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key);
121 int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key);
122 int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key);
123
124
125 /* wipe and repack */
126 int tdb1_wipe_all(struct tdb1_context *tdb);
127 int tdb1_repack(struct tdb1_context *tdb);
128
129 /* Debug functions. Not used in production. */
130 char *tdb1_summary(struct tdb1_context *tdb);
131
132 extern TDB_DATA tdb1_null;
133
134 #endif /* tdb1.h */