]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb1_open.c
tdb2: use tdb->flags & TDB_RDONLY instead of tdb->read_only for TDB1 code.
[ccan] / ccan / tdb2 / tdb1_open.c
index 5c4f62f67c8c3f3d572a8576e049344d5e1206e1..73f7f26710e1c1a3691d98acdf9bedfa275cf75b 100644 (file)
@@ -34,16 +34,10 @@ static struct tdb1_context *tdb1s = NULL;
 void tdb1_header_hash(struct tdb1_context *tdb,
                     uint32_t *magic1_hash, uint32_t *magic2_hash)
 {
-       TDB_DATA hash_key;
        uint32_t tdb1_magic = TDB1_MAGIC;
 
-       hash_key.dptr = (unsigned char *)TDB_MAGIC_FOOD;
-       hash_key.dsize = sizeof(TDB_MAGIC_FOOD);
-       *magic1_hash = tdb->hash_fn(&hash_key);
-
-       hash_key.dptr = (unsigned char *)TDB1_CONV(tdb1_magic);
-       hash_key.dsize = sizeof(tdb1_magic);
-       *magic2_hash = tdb->hash_fn(&hash_key);
+       *magic1_hash = tdb_hash(tdb, TDB_MAGIC_FOOD, sizeof(TDB_MAGIC_FOOD));
+       *magic2_hash = tdb_hash(tdb, TDB1_CONV(tdb1_magic), sizeof(tdb1_magic));
 
        /* Make sure at least one hash is non-zero! */
        if (*magic1_hash == 0 && *magic2_hash == 0)
@@ -189,6 +183,8 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
        tdb->file->map_ptr = NULL;
        tdb->flags = tdb1_flags|TDB_VERSION1;
        tdb->open_flags = open_flags;
+       tdb->lock_fn = tdb_fcntl_lock;
+       tdb->unlock_fn = tdb_fcntl_unlock;
        if (log_ctx) {
                tdb->log_fn = log_ctx->log_fn;
                tdb->log_data = log_ctx->log_private;
@@ -221,6 +217,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
                errno = ENOMEM;
                goto fail;
        }
+       tdb->hash_seed = 0;
 
        if (hash_fn) {
                tdb->hash_fn = hash_fn;
@@ -253,7 +250,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
        if (hash_size == 0)
                hash_size = TDB1_DEFAULT_HASH_SIZE;
        if ((open_flags & O_ACCMODE) == O_RDONLY) {
-               tdb->read_only = 1;
+               tdb->flags |= TDB_RDONLY;
                /* read only databases don't do locking */
                tdb->flags |= TDB_NOLOCK;
        }