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 #define tdb_traverse_read(tdb, fn, p) \
66 tdb_traverse_read_(tdb, typesafe_cb_preargs(int, void *, (fn), (p), \
67 struct tdb_context *, \
68 TDB_DATA, TDB_DATA), (p))
69 int64_t tdb_traverse_read_(struct tdb_context
*tdb
,
70 int (*fn
)(struct tdb_context
*,
71 TDB_DATA
, TDB_DATA
, void *), void *p
);
73 /* Old-style tdb_errorstr */
74 #define tdb_errorstr_compat(tdb) tdb_errorstr(tdb_error(tdb))
76 /* This typedef doesn't exist in TDB2. */
77 typedef struct tdb_context TDB_CONTEXT
;
79 /* We only need these for the CLEAR_IF_FIRST lock. */
80 int tdb_reopen(struct tdb_context
*tdb
);
81 int tdb_reopen_all(int parent_longlived
);
83 /* These no longer exist in tdb2. */
84 #define TDB_CLEAR_IF_FIRST 1048576
85 #define TDB_INCOMPATIBLE_HASH 2097152
86 #define TDB_VOLATILE 4194304
88 /* tdb2 does nonblocking functions via attibutes. */
89 enum TDB_ERROR
tdb_transaction_start_nonblock(struct tdb_context
*tdb
);
90 enum TDB_ERROR
tdb_chainlock_nonblock(struct tdb_context
*tdb
, TDB_DATA key
);
93 /* Convenient (typesafe) wrapper for tdb open with logging */
94 #define tdb_open_compat(name, hsize, tdb_fl, open_fl, mode, log_fn, log_data) \
95 tdb_open_compat_((name), (hsize), (tdb_fl), (open_fl), (mode), \
96 typesafe_cb_preargs(void, void *, \
97 (log_fn), (log_data), \
98 struct tdb_context *, \
105 tdb_open_compat_(const char *name
, int hash_size
,
106 int tdb_flags
, int open_flags
, mode_t mode
,
107 void (*log_fn
)(struct tdb_context
*,
109 enum TDB_ERROR ecode
,
116 /* FIXME: Inlining this is a bit lazy, but eases S3 build. */
117 static inline struct tdb_context
*
118 tdb_open_compat(const char *name
, int hash_size
,
119 int tdb_flags
, int open_flags
, mode_t mode
,
120 tdb_log_func log_fn
, void *log_private
)
122 struct tdb_logging_context lctx
;
123 lctx
.log_fn
= log_fn
;
124 lctx
.log_private
= log_private
;
127 return tdb_open_ex(name
, hash_size
, tdb_flags
, open_flags
,
130 return tdb_open(name
, hash_size
, tdb_flags
, open_flags
, mode
);
133 #define tdb_firstkey_compat tdb_firstkey
134 /* Note: this frees the old key.dptr. */
135 static inline TDB_DATA
tdb_nextkey_compat(struct tdb_context
*tdb
, TDB_DATA k
)
137 TDB_DATA next
= tdb_nextkey(tdb
, k
);
141 #define tdb_errorstr_compat(tdb) tdb_errorstr(tdb)
142 #define tdb_fetch_compat tdb_fetch
145 #endif /* TDB_COMPAT_H */