summaryrefslogtreecommitdiff
path: root/lib/tdb2/traverse.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-18 22:30:26 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:06 +0200
commit16cc345d4f84367e70e133200f7aa335c2aae8c6 (patch)
tree955a33c25c19f3127e24ba6b0e108da6b1f7f804 /lib/tdb2/traverse.c
parent76758b9767fad45ff144bbfef3ab84bca5d4650e (diff)
downloadsamba-16cc345d4f84367e70e133200f7aa335c2aae8c6.tar.gz
samba-16cc345d4f84367e70e133200f7aa335c2aae8c6.tar.bz2
samba-16cc345d4f84367e70e133200f7aa335c2aae8c6.zip
TDB2: Goodbye TDB2, Hello NTDB.
This renames everything from tdb2 to ntdb: importantly, we no longer use the tdb_ namespace, so you can link against both ntdb and tdb if you want to. This also enables building of standalone ntdb by the autobuild script. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/tdb2/traverse.c')
-rw-r--r--lib/tdb2/traverse.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/lib/tdb2/traverse.c b/lib/tdb2/traverse.c
deleted file mode 100644
index ed51a9ee72..0000000000
--- a/lib/tdb2/traverse.c
+++ /dev/null
@@ -1,99 +0,0 @@
- /*
- Trivial Database 2: traverse function.
- Copyright (C) Rusty Russell 2010
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 3 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-#include "private.h"
-#include <ccan/likely/likely.h>
-
-_PUBLIC_ int64_t tdb_traverse_(struct tdb_context *tdb,
- int (*fn)(struct tdb_context *,
- TDB_DATA, TDB_DATA, void *),
- void *p)
-{
- enum TDB_ERROR ecode;
- struct traverse_info tinfo;
- struct tdb_data k, d;
- int64_t count = 0;
-
- k.dptr = NULL;
- for (ecode = first_in_hash(tdb, &tinfo, &k, &d.dsize);
- ecode == TDB_SUCCESS;
- ecode = next_in_hash(tdb, &tinfo, &k, &d.dsize)) {
- d.dptr = k.dptr + k.dsize;
-
- count++;
- if (fn && fn(tdb, k, d, p)) {
- free(k.dptr);
- tdb->last_error = TDB_SUCCESS;
- return count;
- }
- free(k.dptr);
- }
-
- if (ecode != TDB_ERR_NOEXIST) {
- return TDB_ERR_TO_OFF(tdb->last_error = ecode);
- }
- tdb->last_error = TDB_SUCCESS;
- return count;
-}
-
-_PUBLIC_ enum TDB_ERROR tdb_firstkey(struct tdb_context *tdb, struct tdb_data *key)
-{
- struct traverse_info tinfo;
-
- return tdb->last_error = first_in_hash(tdb, &tinfo, key, NULL);
-}
-
-/* We lock twice, not very efficient. We could keep last key & tinfo cached. */
-_PUBLIC_ enum TDB_ERROR tdb_nextkey(struct tdb_context *tdb, struct tdb_data *key)
-{
- struct traverse_info tinfo;
- struct hash_info h;
- struct tdb_used_record rec;
-
- tinfo.prev = find_and_lock(tdb, *key, F_RDLCK, &h, &rec, &tinfo);
- free(key->dptr);
- if (TDB_OFF_IS_ERR(tinfo.prev)) {
- return tdb->last_error = TDB_OFF_TO_ERR(tinfo.prev);
- }
- tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK);
-
- return tdb->last_error = next_in_hash(tdb, &tinfo, key, NULL);
-}
-
-static int wipe_one(struct tdb_context *tdb,
- TDB_DATA key, TDB_DATA data, enum TDB_ERROR *ecode)
-{
- *ecode = tdb_delete(tdb, key);
- return (*ecode != TDB_SUCCESS);
-}
-
-_PUBLIC_ enum TDB_ERROR tdb_wipe_all(struct tdb_context *tdb)
-{
- enum TDB_ERROR ecode;
- int64_t count;
-
- ecode = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
- if (ecode != TDB_SUCCESS)
- return tdb->last_error = ecode;
-
- /* FIXME: Be smarter. */
- count = tdb_traverse(tdb, wipe_one, &ecode);
- if (count < 0)
- ecode = TDB_OFF_TO_ERR(count);
- tdb_allrecord_unlock(tdb, F_WRLCK);
- return tdb->last_error = ecode;
-}