-static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash,
+static tdb1_off_t tdb1_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
-tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
+tdb1_off_t tdb1_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
/* update an entry in place - this only works if the new data size
is <= the old data size and the key exists.
on failure return -1.
*/
/* update an entry in place - this only works if the new data size
is <= the old data size and the key exists.
on failure return -1.
*/
-static int tdb1_update_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
+static int tdb1_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec)))
return tdb1_null;
if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec)))
return tdb1_null;
if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
/* record not found */
if (!(rec_ptr = tdb1_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
/* record not found */
tdb1_write_lock_record(tdb, rec_ptr) == -1) {
/* Someone traversing here: mark it as dead */
rec->magic = TDB1_DEAD_MAGIC;
tdb1_write_lock_record(tdb, rec_ptr) == -1) {
/* Someone traversing here: mark it as dead */
rec->magic = TDB1_DEAD_MAGIC;
/*
* Don't let the per-chain freelist grow too large,
* delete all existing dead records
/*
* Don't let the per-chain freelist grow too large,
* delete all existing dead records
/*
* Allow for some dead records per hash chain, look if we can
* find one that can hold the new record. We need enough space
/*
* Allow for some dead records per hash chain, look if we can
* find one that can hold the new record. We need enough space
tdb, rec_ptr + sizeof(rec),
p, key.dsize + dbuf.dsize) == -1) {
goto fail;
tdb, rec_ptr + sizeof(rec),
p, key.dsize + dbuf.dsize) == -1) {
goto fail;
&& (tdb1_purge_dead(tdb, hash) == -1)) {
tdb1_unlock(tdb, -1, F_WRLCK);
goto fail;
&& (tdb1_purge_dead(tdb, hash) == -1)) {
tdb1_unlock(tdb, -1, F_WRLCK);
goto fail;
/* write out and point the top of the hash chain at it */
if (tdb1_rec_write(tdb, rec_ptr, &rec) == -1
/* write out and point the top of the hash chain at it */
if (tdb1_rec_write(tdb, rec_ptr, &rec) == -1
- || tdb->methods->tdb1_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
+ || tdb->tdb1.io->tdb1_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1
|| tdb1_ofs_write(tdb, TDB1_HASH_TOP(hash), &rec_ptr) == -1) {
/* Need to tdb1_unallocate() here */
goto fail;
|| tdb1_ofs_write(tdb, TDB1_HASH_TOP(hash), &rec_ptr) == -1) {
/* Need to tdb1_unallocate() here */
goto fail;
-int tdb1_store(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
+int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
add a region of the file to the freelist. Length is the size of the region in bytes,
which includes the free list header that needs to be added
*/
add a region of the file to the freelist. Length is the size of the region in bytes,
which includes the free list header that needs to be added
*/
tdb->last_error = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
"tdb1_free_region: adding region beyond"
" end of file");
tdb->last_error = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
"tdb1_free_region: adding region beyond"
" end of file");
- if (tdb->methods->tdb1_read(tdb, recovery_head, &rec, sizeof(rec), TDB1_DOCONV()) == -1) {
+ if (tdb->tdb1.io->tdb1_read(tdb, recovery_head, &rec, sizeof(rec), TDB1_DOCONV()) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_wipe_all: failed to read recovery record");
return -1;
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_wipe_all: failed to read recovery record");
return -1;
if (tdb1_ofs_write(tdb, TDB1_HASH_TOP(i), &offset) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_wipe_all: failed to write hash %d", i);
if (tdb1_ofs_write(tdb, TDB1_HASH_TOP(i), &offset) == -1) {
tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
"tdb1_wipe_all: failed to write hash %d", i);
- data_len = (tdb->map_size - TDB1_DATA_START(tdb->header.hash_size));
- if (tdb1_free_region(tdb, TDB1_DATA_START(tdb->header.hash_size), data_len) != 0) {
+ data_len = (tdb->file->map_size - TDB1_DATA_START(tdb->tdb1.header.hash_size));
+ if (tdb1_free_region(tdb, TDB1_DATA_START(tdb->tdb1.header.hash_size), data_len) != 0) {
- data_len = (recovery_head - TDB1_DATA_START(tdb->header.hash_size));
- if (tdb1_free_region(tdb, TDB1_DATA_START(tdb->header.hash_size), data_len) != 0) {
+ data_len = (recovery_head - TDB1_DATA_START(tdb->tdb1.header.hash_size));
+ if (tdb1_free_region(tdb, TDB1_DATA_START(tdb->tdb1.header.hash_size), data_len) != 0) {
-static int repack_traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
+static int repack_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data)
{
struct traverse_state *state = (struct traverse_state *)private_data;
if (tdb1_store(state->dest_db, key, data, TDB_INSERT) != 0) {
{
struct traverse_state *state = (struct traverse_state *)private_data;
if (tdb1_store(state->dest_db, key, data, TDB_INSERT) != 0) {
- tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0);
+ tmp_db = tdb1_open("tmpdb", tdb1_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0, NULL);
if (tmp_db == NULL) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
__location__ " Failed to create tmp_db");
if (tmp_db == NULL) {
tdb->last_error = tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
__location__ " Failed to create tmp_db");