Changeset 108 for trunk/lib


Ignore:
Timestamp:
04/29/08 14:17:48 (17 years ago)
Author:
tim
Message:

added least-recently-used cache structure.

set up SK records to use this instead of the linked list.

Location:
trunk/lib
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Makefile

    r98 r108  
    33################################################################################
    44
    5 FILES=regfi.o smb_deps.o void_stack.o range_list.o
     5FILES=regfi.o smb_deps.o void_stack.o range_list.o lru_cache.o
    66
    77all: $(FILES)
     
    1919        $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ range_list.c
    2020
     21lru_cache.o: lru_cache.c
     22        $(CC) $(CFLAGS) $(OPTS) $(INC) -c -o $@ lru_cache.c
     23
    2124clean:
    2225        rm -f $(FILES)
  • trunk/lib/regfi.c

    r107 r108  
    682682
    683683/*******************************************************************
    684  *******************************************************************/
    685 static REGF_SK_REC* find_sk_record_by_offset( REGF_FILE *file, uint32 offset )
    686 {
    687   REGF_SK_REC *p_sk;
    688  
    689   for ( p_sk=file->sec_desc_list; p_sk; p_sk=p_sk->next ) {
    690     if ( p_sk->sk_off == offset )
    691       return p_sk;
    692   }
    693  
    694   return NULL;
    695 }
    696 
    697 
    698 /*******************************************************************
    699  *******************************************************************/
     684
    700685static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd )
    701686{
     
    707692  }
    708693
    709   /* failure */
    710694
    711695  return NULL;
    712696}
    713 
     697 *******************************************************************/
    714698
    715699/*******************************************************************
     
    798782  /* get the security descriptor.  First look if we have already parsed it */
    799783  if((nk->sk_off!=REGF_OFFSET_NONE)
    800      && !(nk->sec_desc = find_sk_record_by_offset( file, nk->sk_off )))
     784     && !(nk->sec_desc = (REGF_SK_REC*)lru_cache_find(file->sk_recs,
     785                                                      &nk->sk_off, 4)))
    801786  {
    802787    sub_hbin = hbin;
     
    826811    nk->sec_desc->sk_off = nk->sk_off;
    827812   
    828     /* add to the list of security descriptors (ref_count has been read from the files) */
    829     /* XXX: this kind of caching needs to be re-evaluated */
    830     DLIST_ADD( file->sec_desc_list, nk->sec_desc );
     813    lru_cache_update(file->sk_recs, &nk->sk_off, 4, nk->sec_desc);
    831814  }
    832815 
     
    919902    return NULL;
    920903  }
     904 
     905  /* TODO: come up with a better secret. */
     906  rb->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
    921907
    922908  rla = true;
     
    955941    free(range_list_get(file->unalloc_cells, i)->data);
    956942  range_list_free(file->unalloc_cells);
     943
     944  lru_cache_destroy(file->sk_recs);
    957945
    958946  free(file);
Note: See TracChangeset for help on using the changeset viewer.