struct datahead *
cache_search (request_type type, const void *key, size_t len,
struct database_dyn *table, uid_t owner)
{
unsigned long int hash = __nss_hash (key, len) % table->head->module;
unsigned long int nsearched = 0;
struct datahead *result = NULL;
ref_t work = table->head->array[hash];
while (work != ENDREF)
{
++nsearched;
struct hashentry *here = (struct hashentry *) (table->data + work);
if (type == here->type && len == here->len
&& memcmp (key, table->data + here->key, len) == 0
&& here->owner == owner)
{
struct datahead *dh
= (struct datahead *) (table->data + here->packet);
if (dh->usable)
{
if (dh->notfound)
++table->head->neghit;
else
{
++table->head->poshit;
if (dh->nreloads != 0)
dh->nreloads = 0;
}
result = dh;
break;
}
}
work = here->next;
}
if (nsearched > table->head->maxnsearched)
table->head->maxnsearched = nsearched;
return result;
}