Licensing Information

Open Source Used In Cisco FXOS 1.1(3) 868
/* traverse the entire database - calling fn(tdb, key, data) on each element.
return -1 on error or the record count traversed
if fn is NULL then it is not called
a non-zero return value from fn() indicates that the traversal should stop
*/
int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf,
void* state), void* state)
{
int count = 0;
unsigned h;
tdb_off offset, rec_ptr;
struct list_struct rec;
char *data;
TDB_DATA key, dbuf;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_traverse() called with null context\n");
#endif
return -1;
}
/* loop over all hash chains */
for (h = 0; h < tdb->header.hash_size; h++) {
tdb_lock(tdb, BUCKET(h));
/* read in the hash top */
offset = tdb_hash_top(tdb, h);
if (ofs_read(tdb, offset, &rec_ptr) == -1) {
goto fail;
}
/* traverse all records for this hash */
while (rec_ptr) {
if (rec_read(tdb, rec_ptr, &rec) == -1) {
goto fail;
}
/* now read the full record */
data = tdb_alloc_read(tdb, rec_ptr + sizeof(rec),
 rec.key_len + rec.data_len);
if (!data) {
goto fail;
}
key.dptr = data;
key.dsize = rec.key_len;