Licensing Information

Open Source Used In Cisco FXOS 1.1(4) 955
This is based on the hash agorithm from gdbm */
static unsigned tdb_hash(TDB_DATA *key)
{
unsigned value;/* Used to compute the hash value. */
unsigned i;/* Used to cycle through random values. */
/* Set the initial value from the key size. */
value = 0x238F13AF * key->dsize;
for (i=0; i < key->dsize; i++) {
value = (value + (key->dptr[i] << (i*5 % 24)));
}
value = (1103515243 * value + 12345);
return value;
}
/* find the top of the hash chain for an open database */
static tdb_off tdb_hash_top(TDB_CONTEXT *tdb, unsigned hash)
{
tdb_off ret;
hash = BUCKET(hash);
ret = FREELIST_TOP + (hash+1)*sizeof(tdb_off);
return ret;
}
/* check for an out of bounds access - if it is out of bounds then
see if the database has been expanded by someone else and expand
if necessary */
static int tdb_oob(TDB_CONTEXT *tdb, tdb_off offset)
{
struct stat st;
if ((offset <= tdb->map_size) || (tdb->fd == -1)) return 0;
fstat(tdb->fd, &st);
if (st.st_size <= (ssize_t)offset) {
tdb->ecode = TDB_ERR_IO;
return -1;
}
#if HAVE_MMAP
if (tdb->map_ptr) {
munmap(tdb->map_ptr, tdb->map_size);
tdb->map_ptr = NULL;
}
#endif