summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:00:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:00:13 +0930
commit658ff5b0f28e364d22ada4dbbc988ca0f82b911e (patch)
treec6c8b9ec5c3f46cc5cf234ba0e57c28fe45f0100
parent8e14a3e06d42b0302868dc3911a2e607e42a51b3 (diff)
downloadsamba-658ff5b0f28e364d22ada4dbbc988ca0f82b911e.tar.gz
samba-658ff5b0f28e364d22ada4dbbc988ca0f82b911e.tar.bz2
samba-658ff5b0f28e364d22ada4dbbc988ca0f82b911e.zip
tdb2: unify tdb1_firstkey/tdb1_nextkey into tdb_firstkey/tdb_nextkey.
Switch on the TDB_VERSION1 flag. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 7366486e29e4f3d89a3e08fc114079d6441af850)
-rw-r--r--lib/tdb2/private.h4
-rw-r--r--lib/tdb2/tdb1.h4
-rw-r--r--lib/tdb2/traverse.c22
3 files changed, 26 insertions, 4 deletions
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h
index 816d5f70f8..50c48fa9a5 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -697,6 +697,10 @@ int tdb1_transaction_start(struct tdb_context *tdb);
int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
int tdb1_transaction_commit(struct tdb_context *tdb);
+/* tdb1_traverse.c: */
+TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
+TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
+
/* tdb.c: */
enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
enum TDB_ERROR ecode,
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
index 2855d0c1b0..59c2dd0d1d 100644
--- a/lib/tdb2/tdb1.h
+++ b/lib/tdb2/tdb1.h
@@ -38,10 +38,6 @@
void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead);
-TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
-
-TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
-
int tdb1_get_seqnum(struct tdb_context *tdb);
void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);
diff --git a/lib/tdb2/traverse.c b/lib/tdb2/traverse.c
index a065ad0042..b27550032f 100644
--- a/lib/tdb2/traverse.c
+++ b/lib/tdb2/traverse.c
@@ -61,6 +61,16 @@ enum TDB_ERROR tdb_firstkey(struct tdb_context *tdb, struct tdb_data *key)
{
struct traverse_info tinfo;
+ if (tdb->flags & TDB_VERSION1) {
+ tdb->last_error = TDB_SUCCESS;
+ *key = tdb1_firstkey(tdb);
+ /* TDB1 didn't set error for last key. */
+ if (!key->dptr && tdb->last_error == TDB_SUCCESS) {
+ tdb->last_error = TDB_ERR_NOEXIST;
+ }
+ return tdb->last_error;
+ }
+
return tdb->last_error = first_in_hash(tdb, &tinfo, key, NULL);
}
@@ -71,6 +81,18 @@ enum TDB_ERROR tdb_nextkey(struct tdb_context *tdb, struct tdb_data *key)
struct hash_info h;
struct tdb_used_record rec;
+ if (tdb->flags & TDB_VERSION1) {
+ struct tdb_data last_key = *key;
+ tdb->last_error = TDB_SUCCESS;
+ *key = tdb1_nextkey(tdb, last_key);
+ free(last_key.dptr);
+ /* TDB1 didn't set error for last key. */
+ if (!key->dptr && tdb->last_error == TDB_SUCCESS) {
+ tdb->last_error = TDB_ERR_NOEXIST;
+ }
+ return tdb->last_error;
+ }
+
tinfo.prev = find_and_lock(tdb, *key, F_RDLCK, &h, &rec, &tinfo);
free(key->dptr);
if (TDB_OFF_IS_ERR(tinfo.prev)) {