Lines Matching refs:ch
43 struct cachekey_header *ch; member
108 static struct cachekey_header *remap_cache_file_ch(struct cachekey_header *ch,
111 static struct cachekey_header *cache_insert_ch(struct cachekey_header *ch,
117 static struct cachekey3_list *cache_retrieve_ch(struct cachekey_header *ch,
122 static int cache_remove_ch(struct cachekey_header *ch,
161 static struct cachekey3_list * copy_cl_item(struct cachekey_header *ch,
204 struct cachekey_header *ch; in create_cache_file_ch() local
283 if ((ch = (void *)mmap(0, sizeof (struct cachekey_header), in create_cache_file_ch()
292 if (ch->version != CACHEKEY_HEADER_VERSION || in create_cache_file_ch()
293 ch->headerlength != sizeof (struct cachekey_header) || in create_cache_file_ch()
294 ch->keylen != keylen || in create_cache_file_ch()
295 ch->algtype != algtype || in create_cache_file_ch()
296 ch->reclength != reclength || in create_cache_file_ch()
297 ch->length < sizeof (struct cachekey_header) || in create_cache_file_ch()
298 ch->maxsize < ch->length || in create_cache_file_ch()
299 INVALID_ADDRESS(ch->inuse, ch) || in create_cache_file_ch()
300 INVALID_ADDRESS(ch->free, ch)) { in create_cache_file_ch()
304 munmap((caddr_t)ch, sizeof (struct cachekey_header)); in create_cache_file_ch()
308 oldbase = (void *)ch->address; in create_cache_file_ch()
309 length = ch->length; in create_cache_file_ch()
310 if (munmap((caddr_t)ch, sizeof (struct cachekey_header)) < 0) { in create_cache_file_ch()
320 if ((ch = (void *)mmap((caddr_t)oldbase, length, in create_cache_file_ch()
329 ch->fd = fd; in create_cache_file_ch()
330 ch->maxsize = maxsize; in create_cache_file_ch()
333 ch->version = CACHEKEY_HEADER_VERSION; in create_cache_file_ch()
334 ch->headerlength = sizeof (struct cachekey_header); in create_cache_file_ch()
335 ch->keylen = keylen; in create_cache_file_ch()
336 ch->algtype = algtype; in create_cache_file_ch()
337 ch->reclength = reclength; in create_cache_file_ch()
338 ch->length = length; in create_cache_file_ch()
339 ch->address = (caddr_t)ch; in create_cache_file_ch()
340 ch->inuse_count = 0; in create_cache_file_ch()
341 ch->inuse = 0; in create_cache_file_ch()
342 ch->inuse_end = 0; in create_cache_file_ch()
343 ch->free = 0; in create_cache_file_ch()
344 ch->free_count = 0; in create_cache_file_ch()
346 ch->bucket[i] = 0; in create_cache_file_ch()
349 cd = &(ch->array[0]); in create_cache_file_ch()
350 for (i = 0; i < MAPRECS(ch); in create_cache_file_ch()
351 i++, cd = MOVE_ADDR(cd, ch->reclength)) { in create_cache_file_ch()
353 cd->prev = MOVE_ADDR(cd, -(ch->reclength)); in create_cache_file_ch()
354 cd->next = MOVE_ADDR(cd, +(ch->reclength)); in create_cache_file_ch()
362 cd = MOVE_ADDR(cd, -(ch->reclength)); in create_cache_file_ch()
364 cd = &(ch->array[0]); in create_cache_file_ch()
367 ch->free_count = MAPRECS(ch); in create_cache_file_ch()
368 ch->free = &(ch->array[0]); in create_cache_file_ch()
370 (void) msync((caddr_t)ch, ch->length, MS_SYNC); in create_cache_file_ch()
372 } else if (ch->length > maxsize) { in create_cache_file_ch()
374 if ((ch = remap_cache_file_ch(ch, MAXRECS(ch))) == 0) { in create_cache_file_ch()
387 cache_remap_addresses_ch(ch) == 0) { in create_cache_file_ch()
390 (void) munmap((caddr_t)ch, ch->length); in create_cache_file_ch()
395 (void) msync((caddr_t)ch, ch->length, MS_SYNC); in create_cache_file_ch()
397 return (ch); in create_cache_file_ch()
402 cache_remap_addresses_ch(struct cachekey_header *ch) in cache_remap_addresses_ch() argument
408 offset = (u_long)ch - (u_long)ch->address; in cache_remap_addresses_ch()
410 if (INVALID_ADDRESS(ch->inuse, ch) || in cache_remap_addresses_ch()
411 INVALID_ADDRESS(ch->inuse_end, ch) || in cache_remap_addresses_ch()
412 INVALID_ADDRESS(ch->free, ch)) { in cache_remap_addresses_ch()
416 ch->inuse = MOVE_ADDR(ch->inuse, offset); in cache_remap_addresses_ch()
417 ch->inuse_end = MOVE_ADDR(ch->inuse_end, offset); in cache_remap_addresses_ch()
418 ch->free = MOVE_ADDR(ch->free, offset); in cache_remap_addresses_ch()
420 cd = &(ch->array[0]); in cache_remap_addresses_ch()
421 for (i = 0; i < NUMRECS(ch); i++) { in cache_remap_addresses_ch()
422 if (INVALID_ADDRESS(cd->prev, ch) || in cache_remap_addresses_ch()
423 INVALID_ADDRESS(cd->next, ch) || in cache_remap_addresses_ch()
424 INVALID_ADDRESS(cd->prevhash, ch) || in cache_remap_addresses_ch()
425 INVALID_ADDRESS(cd->nexthash, ch)) { in cache_remap_addresses_ch()
432 cd = MOVE_ADDR(cd, ch->reclength); in cache_remap_addresses_ch()
436 if (INVALID_ADDRESS(ch->bucket[i], ch)) { in cache_remap_addresses_ch()
439 ch->bucket[i] = MOVE_ADDR(ch->bucket[i], offset); in cache_remap_addresses_ch()
447 ch->address = (caddr_t)ch; in cache_remap_addresses_ch()
458 remap_cache_file_ch(struct cachekey_header *ch, u_int newrecs) in remap_cache_file_ch() argument
467 if (ch == 0) in remap_cache_file_ch()
479 (ch->reclength)*newrecs; in remap_cache_file_ch()
480 currecs = NUMRECS(ch); in remap_cache_file_ch()
482 if (newsize > ch->maxsize) { in remap_cache_file_ch()
484 newsize = ch->maxsize; in remap_cache_file_ch()
488 oldsize = ch->length; in remap_cache_file_ch()
489 oldaddr = (caddr_t)ch; in remap_cache_file_ch()
490 fd = ch->fd; in remap_cache_file_ch()
492 if (newsize > ch->length) { in remap_cache_file_ch()
494 cd = &(ch->array[0]); in remap_cache_file_ch()
495 } else if (newsize == ch->length) { in remap_cache_file_ch()
497 return (ch); in remap_cache_file_ch()
506 if (cache_remap_addresses_ch(ch) == 0) { in remap_cache_file_ch()
508 ch->keylen, ch->algtype); in remap_cache_file_ch()
509 close(ch->fd); in remap_cache_file_ch()
510 munmap((caddr_t)ch, ch->length); in remap_cache_file_ch()
513 fcd = MOVE_ADDR(&(ch->array[0]), in remap_cache_file_ch()
514 ch->reclength*(MAPRECS(ch)-1)); in remap_cache_file_ch()
515 tmpsize = (u_long)fcd - (u_long)ch + ch->reclength; in remap_cache_file_ch()
516 while (tmpsize > newsize && fcd > &(ch->array[0])) { in remap_cache_file_ch()
518 list_remove(fcd, &(ch->free), 0, in remap_cache_file_ch()
519 &(ch->free_count)); in remap_cache_file_ch()
522 &(ch->bucket[hashval(fcd->uid)]), 0, 0); in remap_cache_file_ch()
523 list_remove(fcd, &(ch->inuse), &(ch->inuse_end), in remap_cache_file_ch()
524 &(ch->inuse_count)); in remap_cache_file_ch()
526 tmpsize -= ch->reclength; in remap_cache_file_ch()
527 fcd = MOVE_ADDR(fcd, -(ch->reclength)); in remap_cache_file_ch()
529 ch->length = newsize; in remap_cache_file_ch()
530 (void) msync((caddr_t)ch, ch->length, MS_SYNC); in remap_cache_file_ch()
537 ch = 0; in remap_cache_file_ch()
582 print_cache_ch(struct cachekey_header *ch) in print_cache_ch() argument
590 ch->keylen, ch->algtype, ch->version, ch->headerlength, in print_cache_ch()
591 ch->reclength); in print_cache_ch()
593 ch->fd, ch->address, ch->length, ch->maxsize); in print_cache_ch()
594 printf("inuse = %d, free = %d\n", ch->inuse_count, ch->free_count); in print_cache_ch()
599 cd = ch->bucket[i]; in print_cache_ch()
621 cd = ch->inuse; in print_cache_ch()
633 cd = ch->free; in print_cache_ch()
656 if (c->ch == 0) { in print_cache()
661 print_cache_ch(c->ch); in print_cache()
800 find_cache_item(struct cachekey_header **ch, uid_t uid, struct dhkey *public) in find_cache_item() argument
807 if ((ch == NULL) || ((*ch) == NULL)) { in find_cache_item()
810 for (cd = (*ch)->bucket[hash]; cd != 0; cd = cd->nexthash) { in find_cache_item()
815 list_remove_hash(cd, &((*ch)->bucket[hash]), 0, 0); in find_cache_item()
816 list_remove(cd, &((*ch)->inuse), &((*ch)->inuse_end), in find_cache_item()
817 &((*ch)->inuse_count)); in find_cache_item()
822 if ((cd = (*ch)->free) != 0) { in find_cache_item()
823 list_remove(cd, &((*ch)->free), 0, &((*ch)->free_count)); in find_cache_item()
828 if (((*ch) = remap_cache_file_ch(*ch, NUMRECS(*ch)+CHUNK_NUMREC)) == 0) in find_cache_item()
832 if ((cd = (*ch)->free) != 0) { in find_cache_item()
833 list_remove(cd, &((*ch)->free), 0, &((*ch)->free_count)); in find_cache_item()
838 if ((cd = (*ch)->inuse) == 0) in find_cache_item()
842 list_remove_hash(cd, &((*ch)->bucket[hashval(cd->uid)]), 0, 0); in find_cache_item()
844 list_remove(cd, &((*ch)->inuse), &((*ch)->inuse_end), in find_cache_item()
845 &((*ch)->inuse_count)); in find_cache_item()
853 struct cachekey_header *ch, in cache_insert_ch() argument
869 if (ch == 0 || uid == (uid_t)-1) { in cache_insert_ch()
879 newch = ch; in cache_insert_ch()
923 copy_cl_item(struct cachekey_header *ch, struct cachekey_disklist *cd, in copy_cl_item() argument
932 if ((cl = malloc(CACHEKEY3_LIST_SIZE(ch->keylen))) == 0) { in copy_cl_item()
937 if ((skck = malloc(SKCK_LEN(ch->keylen))) == 0) { in copy_cl_item()
944 memcpy(skck, skck_cd, SKCK_LEN(ch->keylen)); in copy_cl_item()
946 err = cbc_crypt(key.c, (char *)skck, SKCK_LEN(ch->keylen), in copy_cl_item()
963 ALIGN4(2*KEYLEN(ch->keylen)+1)); in copy_cl_item()
967 ALIGN4(2*KEYLEN(ch->keylen)+1)); in copy_cl_item()
991 cache_retrieve_ch(struct cachekey_header *ch, uid_t uid, keybuf3 *public, in cache_retrieve_ch() argument
1006 for (cd = ch->bucket[hash]; cd != 0; cd = cd->nexthash) { in cache_retrieve_ch()
1015 cl = copy_cl_item(ch, cd, key); in cache_retrieve_ch()
1019 *cltmp = copy_cl_item(ch, cd, key); in cache_retrieve_ch()
1041 cache_remove_ch(struct cachekey_header *ch, uid_t uid, keybuf3 *public) { in cache_remove_ch() argument
1055 for (cd = ch->bucket[hash]; cd != 0; ) { in cache_remove_ch()
1065 list_remove_hash(cd, &(ch->bucket[hash]), 0, 0); in cache_remove_ch()
1066 list_remove(cd, &(ch->inuse), &(ch->inuse_end), in cache_remove_ch()
1067 &(ch->inuse_count)); in cache_remove_ch()
1069 list_insert(cd, &(ch->free), 0, in cache_remove_ch()
1070 &(ch->free_count)); in cache_remove_ch()
1082 list_remove_hash(cd, &(ch->bucket[hash]), 0, 0); in cache_remove_ch()
1083 list_remove(cd, &(ch->inuse), &(ch->inuse_end), in cache_remove_ch()
1084 &(ch->inuse_count)); in cache_remove_ch()
1086 list_insert(cd, &(ch->free), 0, in cache_remove_ch()
1087 &(ch->free_count)); in cache_remove_ch()
1145 c->ch = 0; in get_cache_header()
1189 if (c->ch != 0) { in create_cache_file()
1195 ret = (c->ch = create_cache_file_ch(keylen, algtype, sizespec)) != 0; in create_cache_file()
1218 if (c->ch == 0) { in cache_insert()
1223 ret = (c->ch = in cache_insert()
1224 cache_insert_ch(c->ch, uid, common, key, public, secret)) != 0; in cache_insert()
1246 if (c->ch == 0) { in cache_retrieve()
1251 cl = cache_retrieve_ch(c->ch, uid, public, key); in cache_retrieve()
1267 if (c->ch == 0) { in cache_remove()
1272 ret = cache_remove_ch(c->ch, uid, public); in cache_remove()