X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb1_tdb.c;h=8392e71240f33c70e1747d62b06ad9ba71df4c52;hp=c9406c4b16448be789c761ba86355f6c52106a28;hb=3e46dde21261966941469a6c75e1b45cd2d26324;hpb=8a47d50d72ea62e378dc92b150c92c1317c73fa3 diff --git a/ccan/tdb2/tdb1_tdb.c b/ccan/tdb2/tdb1_tdb.c index c9406c4b..8392e712 100644 --- a/ccan/tdb2/tdb1_tdb.c +++ b/ccan/tdb2/tdb1_tdb.c @@ -31,13 +31,13 @@ TDB_DATA tdb1_null; /* non-blocking increment of the tdb sequence number if the tdb has been opened using - the TDB1_SEQNUM flag + the TDB_SEQNUM flag */ void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb) { tdb1_off_t seqnum=0; - if (!(tdb->flags & TDB1_SEQNUM)) { + if (!(tdb->flags & TDB_SEQNUM)) { return; } @@ -51,11 +51,11 @@ void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb) /* increment the tdb sequence number if the tdb has been opened using - the TDB1_SEQNUM flag + the TDB_SEQNUM flag */ static void tdb1_increment_seqnum(struct tdb1_context *tdb) { - if (!(tdb->flags & TDB1_SEQNUM)) { + if (!(tdb->flags & TDB_SEQNUM)) { return; } @@ -189,7 +189,7 @@ static TDB_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB_DATA key) uint32_t hash; /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); + hash = tdb_hash(tdb, key.dptr, key.dsize); if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) return tdb1_null; @@ -236,7 +236,7 @@ int tdb1_parse_record(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash; /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); + hash = tdb_hash(tdb, key.dptr, key.dsize); if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) { /* record not found */ @@ -270,7 +270,7 @@ static int tdb1_exists_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t has int tdb1_exists(struct tdb1_context *tdb, TDB_DATA key) { - uint32_t hash = tdb->hash_fn(&key); + uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize); int ret; ret = tdb1_exists_hash(tdb, key, hash); @@ -429,7 +429,7 @@ static int tdb1_delete_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t has int tdb1_delete(struct tdb1_context *tdb, TDB_DATA key) { - uint32_t hash = tdb->hash_fn(&key); + uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize); int ret; ret = tdb1_delete_hash(tdb, key, hash); @@ -607,7 +607,7 @@ int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) } /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); + hash = tdb_hash(tdb, key.dptr, key.dsize); if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1) return -1; @@ -624,7 +624,7 @@ int tdb1_append(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA new_dbuf) int ret = -1; /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); + hash = tdb_hash(tdb, key.dptr, key.dsize); if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1) return -1; @@ -698,7 +698,7 @@ static int tdb1_free_region(struct tdb1_context *tdb, tdb1_off_t offset, ssize_t /* the region is not worth adding */ return 0; } - if (length + offset > tdb->map_size) { + if (length + offset > tdb->file->map_size) { tdb->last_error = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR, "tdb1_free_region: adding region beyond" " end of file"); @@ -774,7 +774,7 @@ int tdb1_wipe_all(struct tdb1_context *tdb) for the recovery area */ if (recovery_size == 0) { /* the simple case - the whole file can be used as a freelist */ - data_len = (tdb->map_size - TDB1_DATA_START(tdb->header.hash_size)); + data_len = (tdb->file->map_size - TDB1_DATA_START(tdb->header.hash_size)); if (tdb1_free_region(tdb, TDB1_DATA_START(tdb->header.hash_size), data_len) != 0) { goto failed; } @@ -792,7 +792,7 @@ int tdb1_wipe_all(struct tdb1_context *tdb) goto failed; } /* and the 2nd free list entry after the recovery area - if any */ - data_len = tdb->map_size - (recovery_head+recovery_size); + data_len = tdb->file->map_size - (recovery_head+recovery_size); if (tdb1_free_region(tdb, recovery_head+recovery_size, data_len) != 0) { goto failed; } @@ -843,7 +843,7 @@ int tdb1_repack(struct tdb1_context *tdb) return -1; } - tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB1_INTERNAL, O_RDWR|O_CREAT, 0); + tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0); if (tmp_db == NULL) { tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR, __location__ " Failed to create tmp_db");