Licensing Information

Open Source Used In Cisco FXOS 1.1(3) 859
/* convenience routine for writing a tdb_off */
static int ofs_write(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d)
{
return tdb_write(tdb, offset, (char *)d, sizeof(*d));
}
/* read a tdb_off from the store */
static int ofs_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d)
{
return tdb_read(tdb, offset, (char *)d, sizeof(*d));
}
/* read a record and check for simple errors */
static int rec_read(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
{
if (tdb_read(tdb, offset, (char *)rec, sizeof(*rec)) == -1) return -1;
if (rec->magic != TDB_MAGIC) {
#if TDB_DEBUG
printf("bad magic 0x%08x at offset %d\n",
 rec->magic, offset);
#endif
tdb->ecode = TDB_ERR_CORRUPT;
return -1;
}
if (tdb_oob(tdb, rec->next) != 0) {
return -1;
}
return 0;
}
/* expand the database at least length bytes by expanding the
underlying file and doing the mmap again if necessary */
static int tdb_expand(TDB_CONTEXT *tdb, tdb_off length)
{
struct list_struct rec;
tdb_off offset, ptr;
char b = 0;
tdb_lock(tdb,-1);
/* make sure we know about any previous expansions by another
process */
tdb_oob(tdb,tdb->map_size + 1);
/* always make room for at least 10 more records */
length *= TDB_LEN_MULTIPLIER;
/* and round the database up to a multiple of TDB_PAGE_SIZE */