Licensing Information
Open Source Used In Cisco FXOS 1.1(3) 861
fail:
tdb_unlock(tdb,-1);
return -1;
}
/* allocate some space from the free list. The offset returned points
to a unconnected list_struct within the database with room for at
least length bytes of total data
0 is returned if the space could not be allocated
*/
static tdb_off tdb_allocate(TDB_CONTEXT *tdb, tdb_len length)
{
tdb_off offset, rec_ptr, last_ptr;
struct list_struct rec, lastrec, newrec;
tdb_lock(tdb, -1);
again:
last_ptr = 0;
offset = FREELIST_TOP;
/* read in the freelist top */
if (ofs_read(tdb, offset, &rec_ptr) == -1) {
goto fail;
}
/* keep looking until we find a freelist record that is big
enough */
while (rec_ptr) {
if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec)) == -1) {
goto fail;
}
if (rec.magic != TDB_FREE_MAGIC) {
#if TDB_DEBUG
printf("bad magic 0x%08x in free list\n", rec.magic);
#endif
goto fail;
}
if (rec.rec_len >= length) {
/* found it - now possibly split it up */
if (rec.rec_len > length + MIN_REC_SIZE) {
length = (length + TDB_ALIGN) & ~(TDB_ALIGN-1);
newrec.rec_len = rec.rec_len - (sizeof(rec) + length);