tdb2: feature support.
[ccan] / ccan / tdb2 / tdb.c
index ce431208bf4cb4fa28d09f9158c7fb02c93d7d37..4ffcebf56150bffe381018b4f401aa5503455196 100644 (file)
@@ -112,6 +112,7 @@ static enum TDB_ERROR tdb_new_database(struct tdb_context *tdb,
                                         newdb.hdr.hash_seed,
                                         tdb->hash_priv);
        newdb.hdr.recovery = 0;
+       newdb.hdr.features_used = newdb.hdr.features_offered = TDB_FEATURE_MASK;
        memset(newdb.hdr.reserved, 0, sizeof(newdb.hdr.reserved));
        /* Initial hashes are empty. */
        memset(newdb.hdr.hashtable, 0, sizeof(newdb.hdr.hashtable));
@@ -361,6 +362,16 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                goto fail;
        }
 
+       /* Clear any features we don't understand. */
+       if ((open_flags & O_ACCMODE) != O_RDONLY) {
+               hdr.features_used &= TDB_FEATURE_MASK;
+               if (tdb_write_convert(tdb, offsetof(struct tdb_header,
+                                                   features_used),
+                                     &hdr.features_used,
+                                     sizeof(hdr.features_used)) == -1)
+                       goto fail;
+       }
+
        tdb->device = st.st_dev;
        tdb->inode = st.st_ino;
        tdb_unlock_open(tdb);