2 Unix SMB/CIFS implementation.
4 Compatibility layer for TDB1 vs TDB2.
6 Copyright (C) Rusty Russell 2011
8 ** NOTE! The following LGPL license applies to the tdb_compat
9 ** library. This does NOT imply that all of Samba is released
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 3 of the License, or (at your option) any later version.
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public
23 License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 #include <ccan/typesafe_cb/typesafe_cb.h>
35 extern TDB_DATA tdb_null
;
37 /* Old-style tdb_fetch. */
38 static inline TDB_DATA
tdb_fetch_compat(struct tdb_context
*tdb
, TDB_DATA k
)
41 if (tdb_fetch(tdb
, k
, &dbuf
) != TDB_SUCCESS
) {
47 static inline TDB_DATA
tdb_firstkey_compat(struct tdb_context
*tdb
)
50 if (tdb_firstkey(tdb
, &k
) != TDB_SUCCESS
) {
56 /* Note: this frees the old key.dptr. */
57 static inline TDB_DATA
tdb_nextkey_compat(struct tdb_context
*tdb
, TDB_DATA k
)
59 if (tdb_nextkey(tdb
, &k
) != TDB_SUCCESS
) {
65 /* tdb_traverse_read and tdb_traverse are equal: both only take read locks. */
66 #define tdb_traverse_read tdb_traverse
68 /* Old-style tdb_errorstr */
69 #define tdb_errorstr_compat(tdb) tdb_errorstr(tdb_error(tdb))
71 /* This typedef doesn't exist in TDB2. */
72 typedef struct tdb_context TDB_CONTEXT
;
74 /* We don't need these any more. */
75 #define tdb_reopen_all(flag) 0
76 #define tdb_reopen(tdb) 0
78 /* These no longer exist in tdb2. */
79 #define TDB_CLEAR_IF_FIRST 1048576
80 #define TDB_INCOMPATIBLE_HASH 0
81 #define TDB_VOLATILE 0
83 /* tdb2 does nonblocking functions via attibutes. */
84 enum TDB_ERROR
tdb_transaction_start_nonblock(struct tdb_context
*tdb
);
86 /* Convenient (typesafe) wrapper for tdb open with logging */
87 #define tdb_open_compat(name, hsize, tdb_fl, open_fl, mode, log_fn, log_data) \
88 tdb_open_compat_((name), (hsize), (tdb_fl), (open_fl), (mode), \
89 typesafe_cb_preargs(void, void *, \
90 (log_fn), (log_data), \
91 struct tdb_context *, \
97 tdb_open_compat_(const char *name
, int hash_size_unused
,
98 int tdb_flags
, int open_flags
, mode_t mode
,
99 void (*log_fn
)(struct tdb_context
*,
107 /* FIXME: Inlining this is a bit lazy, but eases S3 build. */
108 static inline struct tdb_context
*
109 tdb_open_compat(const char *name
, int hash_size
,
110 int tdb_flags
, int open_flags
, mode_t mode
,
111 tdb_log_func log_fn
, void *log_private
)
113 struct tdb_logging_context lctx
;
114 lctx
.log_fn
= log_fn
;
115 lctx
.log_private
= log_private
;
118 return tdb_open_ex(name
, hash_size
, tdb_flags
, open_flags
,
121 return tdb_open(name
, hash_size
, tdb_flags
, open_flags
, mode
);
124 #define tdb_firstkey_compat tdb_firstkey
125 /* Note: this frees the old key.dptr. */
126 static inline TDB_DATA
tdb_nextkey_compat(struct tdb_context
*tdb
, TDB_DATA k
)
128 TDB_DATA next
= tdb_nextkey(tdb
, k
);
132 #define tdb_errorstr_compat(tdb) tdb_errorstr(tdb)
133 #define tdb_fetch_compat tdb_fetch
136 #endif /* TDB_COMPAT_H */