Licensing Information
Open Source Used In Cisco FXOS 1.1(3) 871
/* find which hash bucket it is in */
hash = tdb_hash(&key);
hbucket = BUCKET(hash);
tdb_lock(tdb, hbucket);
rec_ptr = tdb_find(tdb, key, hash, &rec);
if (rec_ptr) {
/* we want the next record after this one */
rec_ptr = rec.next;
}
/* not found or last in hash: look for next non-empty hash chain */
while (rec_ptr == 0) {
tdb_unlock(tdb, hbucket);
if (++hbucket >= tdb->header.hash_size - 1)
return null_data;
offset = tdb_hash_top(tdb, hbucket);
tdb_lock(tdb, hbucket);
/* read in the hash top */
if (ofs_read(tdb, offset, &rec_ptr) == -1) {
tdb_unlock(tdb, hbucket);
return null_data;
}
}
/* Read the record. */
if (rec_read(tdb, rec_ptr, &rec) == -1) {
tdb_unlock(tdb, hbucket);
return null_data;
}
/* allocate and read the key */
ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec), rec.key_len);
ret.dsize = rec.key_len;
tdb_unlock(tdb, hbucket);
return ret;
}
/* delete an entry in the database given a key */
int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key)
{
unsigned hash;
tdb_off offset, rec_ptr, last_ptr;
struct list_struct rec, lastrec;
char *data = NULL;