Changeset 109 for trunk/lib


Ignore:
Timestamp:
04/29/08 16:38:27 (17 years ago)
Author:
tim
Message:

reworked SK record caching to prevent unnecessary loads.

SK records now cached in iterators on an as-needed basis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r108 r109  
    681681
    682682
     683
    683684/*******************************************************************
    684 
    685 static REGF_SK_REC* find_sk_record_by_sec_desc( REGF_FILE *file, SEC_DESC *sd )
    686 {
    687   REGF_SK_REC *p;
    688 
    689   for ( p=file->sec_desc_list; p; p=p->next ) {
    690     if ( sec_desc_equal( p->sec_desc, sd ) )
    691       return p;
    692   }
    693 
    694 
    695   return NULL;
    696 }
    697  *******************************************************************/
    698 
    699 /*******************************************************************
    700  * TODO: Need to add full key and SK record caching using a
     685 * TODO: Need to add full key caching using a
    701686 *       custom cache structure.
    702687 *******************************************************************/
    703 REGF_NK_REC* regfi_load_key(REGF_FILE *file, uint32 offset, bool strict)
     688REGF_NK_REC* regfi_load_key(REGF_FILE* file, uint32 offset, bool strict)
    704689{
    705690  REGF_HBIN* hbin;
     
    780765  }
    781766
    782   /* get the security descriptor.  First look if we have already parsed it */
    783   if((nk->sk_off!=REGF_OFFSET_NONE)
    784      && !(nk->sec_desc = (REGF_SK_REC*)lru_cache_find(file->sk_recs,
    785                                                       &nk->sk_off, 4)))
    786   {
    787     sub_hbin = hbin;
    788     if(!regfi_offset_in_hbin(hbin, nk->sk_off))
    789       sub_hbin = regfi_lookup_hbin(file, nk->sk_off);
    790 
    791     if(sub_hbin == NULL)
    792     {
    793       free(nk);
    794       /* TODO: need convenient way to free nk->values and nk->subkeys deeply
    795        *       in all cases.
    796        */
    797       return NULL;
    798     }
    799 
    800     off = nk->sk_off + REGF_BLOCKSIZE;
    801     max_length = sub_hbin->block_size + sub_hbin->file_off - off;
    802     nk->sec_desc = regfi_parse_sk(file, off, max_length, true);
    803     if(strict && nk->sec_desc == NULL)
    804     {
    805       free(nk);
    806       /* TODO: need convenient way to free nk->values and nk->subkeys deeply
    807        *       in all cases.
    808        */
    809       return NULL;
    810     }
    811     nk->sec_desc->sk_off = nk->sk_off;
    812    
    813     lru_cache_update(file->sk_recs, &nk->sk_off, 4, nk->sec_desc);
    814   }
    815  
    816767  return nk;
    817768}
     
    903854  }
    904855 
    905   /* TODO: come up with a better secret. */
    906   rb->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
    907 
    908856  rla = true;
    909857  hbin_off = REGF_BLOCKSIZE;
     
    942890  range_list_free(file->unalloc_cells);
    943891
    944   lru_cache_destroy(file->sk_recs);
    945 
    946892  free(file);
    947893
     
    1038984  }
    1039985
     986  /* TODO: come up with a better secret. */
     987  ret_val->sk_recs = lru_cache_create(127, 0xDEADBEEF, true);
     988
    1040989  ret_val->f = fh;
    1041990  ret_val->cur_key = root;
     
    10621011  }
    10631012 
     1013  lru_cache_destroy(i->sk_recs);
     1014
    10641015  free(i);
    10651016}
     
    12011152  return i->cur_key;
    12021153}
     1154
     1155
     1156/******************************************************************************
     1157 *****************************************************************************/
     1158const REGF_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
     1159{
     1160  REGF_SK_REC* ret_val;
     1161  REGF_HBIN* hbin;
     1162  uint32 max_length, off;
     1163
     1164  if(i->cur_key == NULL)
     1165    return NULL;
     1166 
     1167  /* First look if we have already parsed it */
     1168  if((i->cur_key->sk_off!=REGF_OFFSET_NONE)
     1169     && !(ret_val =(REGF_SK_REC*)lru_cache_find(i->sk_recs,
     1170                                                &i->cur_key->sk_off, 4)))
     1171  {
     1172    hbin = regfi_lookup_hbin(i->f, i->cur_key->sk_off);
     1173
     1174    if(hbin == NULL)
     1175      return NULL;
     1176
     1177    off = i->cur_key->sk_off + REGF_BLOCKSIZE;
     1178    max_length = hbin->block_size + hbin->file_off - off;
     1179    ret_val = regfi_parse_sk(i->f, off, max_length, true);
     1180    if(ret_val == NULL)
     1181      return NULL;
     1182
     1183    ret_val->sk_off = i->cur_key->sk_off;
     1184    lru_cache_update(i->sk_recs, &i->cur_key->sk_off, 4, ret_val);
     1185  }
     1186
     1187  return ret_val;
     1188}
     1189
    12031190
    12041191
Note: See TracChangeset for help on using the changeset viewer.