]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb.c
tdb2: unify tdb1_check and tdb1_summary into tdb_check and tdb_summary.
[ccan] / ccan / tdb2 / tdb.c
index 329a643f5145ac6c452fd2c08e56359a52e405dc..a3897831068dd99f5d0d67a12824d4a5cba6397b 100644 (file)
@@ -114,6 +114,12 @@ enum TDB_ERROR tdb_store(struct tdb_context *tdb,
        struct tdb_used_record rec;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_store(tdb, key, dbuf, flag) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;
@@ -177,6 +183,12 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb,
        struct tdb_data new_dbuf;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_append(tdb, key, dbuf) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;
@@ -242,6 +254,9 @@ enum TDB_ERROR tdb_fetch(struct tdb_context *tdb, struct tdb_data key,
        struct hash_info h;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1)
+               return tdb1_fetch(tdb, key, data);
+
        off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;
@@ -269,6 +284,10 @@ bool tdb_exists(struct tdb_context *tdb, TDB_DATA key)
        struct tdb_used_record rec;
        struct hash_info h;
 
+       if (tdb->flags & TDB_VERSION1) {
+               return tdb1_exists(tdb, key);
+       }
+
        off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                tdb->last_error = off;
@@ -287,6 +306,12 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
        struct hash_info h;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_delete(tdb, key) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;
@@ -501,6 +526,11 @@ enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
        struct hash_info h;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               return tdb->last_error = tdb1_parse_record(tdb, key, parse,
+                                                          data);
+       }
+
        off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;