Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 958
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 */
length = ((tdb->map_size + length + TDB_PAGE_SIZE) & ~(TDB_PAGE_SIZE - 1)) - tdb->map_size;
/* expand the file itself */
if (tdb->fd != -1) {
lseek(tdb->fd, tdb->map_size + length - 1, SEEK_SET);
if (write(tdb->fd, &b, 1) != 1) goto fail;
}
/* form a new freelist record */
offset = FREELIST_TOP;
rec.rec_len = length - sizeof(rec);
rec.magic = TDB_FREE_MAGIC;
if (ofs_read(tdb, offset, &rec.next) == -1) {
goto fail;
}
#if HAVE_MMAP
if (tdb->fd != -1 && tdb->map_ptr) {
munmap(tdb->map_ptr, tdb->map_size);