Licensing Information
Open Source Used In Cisco FXOS 1.1(3) 872
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_delete() called with null context\n");
#endif
return -1;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
tdb_lock(tdb, BUCKET(hash));
/* find the top of the hash chain */
offset = tdb_hash_top(tdb, hash);
/* read in the hash top */
if (ofs_read(tdb, offset, &rec_ptr) == -1) {
goto fail;
}
last_ptr = 0;
/* keep looking until we find the right record */
while (rec_ptr) {
if (rec_read(tdb, rec_ptr, &rec) == -1) {
goto fail;
}
if (hash == rec.full_hash && key.dsize == rec.key_len) {
/* a very likely hit - read the record and full key */
data = tdb_alloc_read(tdb, rec_ptr + sizeof(rec),
rec.key_len);
if (!data) {
goto fail;
}
if (memcmp(key.dptr, data, key.dsize) == 0) {
/* a definite match - delete it */
if (last_ptr == 0) {
offset = tdb_hash_top(tdb, hash);
if (ofs_write(tdb, offset, &rec.next) == -1) {
goto fail;
}
} else {
lastrec.next = rec.next;
if (rec_write(tdb, last_ptr, &lastrec) == -1) {
goto fail;
}