- for (i = tdb_find_nonzero_off(tdb, hash_off(tdb, 0), num);
- i != num && !finish;
- i += tdb_find_nonzero_off(tdb, hash_off(tdb, i), num - i)) {
- if (tdb_lock_list(tdb, i, ltype, TDB_LOCK_WAIT) != i)
- goto fail;
-
- off = tdb_read_off(tdb, hash_off(tdb, i));
- if (off == TDB_OFF_ERR) {
- tdb_unlock_list(tdb, i, ltype);
- goto fail;
- }
-
- /* This race can happen, but look again. */
- if (off == 0) {
- tdb_unlock_list(tdb, i, ltype);
- continue;
- }
-
- /* Drop previous lock. */
- tdb_unlock_list(tdb, prev_bucket, ltype);
- prev_bucket = i;
-
- if (tdb_read_convert(tdb, off, &rec, sizeof(rec)) != 0)
- goto fail;
-
- k.dsize = rec_key_length(&rec);
- d.dsize = rec_data_length(&rec);
- if (ltype == F_RDLCK) {
- /* Read traverses can keep the lock. */
- k.dptr = (void *)tdb_access_read(tdb,
- off + sizeof(rec),
- k.dsize + d.dsize,
- false);
- } else {
- k.dptr = tdb_alloc_read(tdb, off + sizeof(rec),
- k.dsize + d.dsize);
- }
- if (!k.dptr)
- goto fail;
+ k.dptr = NULL;
+ for (ecode = first_in_hash(tdb, &tinfo, &k, &d.dsize);
+ ecode == TDB_SUCCESS;
+ ecode = next_in_hash(tdb, &tinfo, &k, &d.dsize)) {