Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

hivemap.c File Reference

#include "cmp.h"

Go to the source code of this file.

Functions

NTSTATUS HvpBuildMapAndCopy (PHHIVE Hive, PVOID Image, PHCELL_INDEX TailDisplay OPTIONAL)
NTSTATUS HvpInitMap (PHHIVE Hive)
NTSTATUS HvpEnlistBinInMap (PHHIVE Hive, ULONG Length, PHBIN Bin, ULONG Offset, PHCELL_INDEX TailDisplay OPTIONAL)
NTSTATUS HvpBuildMap (PHHIVE Hive, PVOID Image, PHCELL_INDEX TailDisplay OPTIONAL)
BOOLEAN HvpEnlistFreeCells (PHHIVE Hive, PHBIN Bin, ULONG BinOffset, PHCELL_INDEX TailDisplay OPTIONAL)
VOID HvpCleanMap (PHHIVE Hive)
VOID HvpFreeMap (PHHIVE Hive, PHMAP_DIRECTORY Dir, ULONG Start, ULONG End)
BOOLEAN HvpAllocateMap (PHHIVE Hive, PHMAP_DIRECTORY Dir, ULONG Start, ULONG End)

Variables

struct {
   PHHIVE   Hive
   ULONG   Status
   ULONG   Space
   HCELL_INDEX   MapPoint
   PHBIN   BinPoint
HvCheckHiveDebug


Function Documentation

BOOLEAN HvpAllocateMap PHHIVE  Hive,
PHMAP_DIRECTORY  Dir,
ULONG  Start,
ULONG  End
 

Definition at line 853 of file hivemap.c.

References _HHIVE::Allocate, ASSERT, _HMAP_DIRECTORY::Directory, End, FALSE, Hive, NULL, Start, t(), and TRUE.

Referenced by HvpAddBin(), HvpBuildMapAndCopy(), and HvpInitMap().

00861 : 00862 00863 Sweeps through the directory Dir points to and allocates Tables. 00864 Will allocate Start-th through End-th entries, INCLUSIVE. 00865 00866 Does NOT clean up when out of memory, call HvpFreeMap to do that. 00867 Arguments: 00868 00869 Hive - supplies pointer to hive control block of interest 00870 00871 Dir - supplies address of an HMAP_DIRECTORY structure 00872 00873 Start - index of first map table pointer to allocate for 00874 00875 End - index of last map table pointer to allocate for 00876 00877 Return Value: 00878 00879 TRUE - it worked 00880 00881 FALSE - insufficient memory 00882 00883 --*/ 00884 { 00885 ULONG i; 00886 PVOID t; 00887 00888 for (i = Start; i <= End; i++) { 00889 ASSERT(Dir->Directory[i] == NULL); 00890 t = (PVOID)((Hive->Allocate)(sizeof(HMAP_TABLE), FALSE)); 00891 if (t == NULL) { 00892 return FALSE; 00893 } 00894 RtlZeroMemory(t, sizeof(HMAP_TABLE)); 00895 Dir->Directory[i] = (PHMAP_TABLE)t; 00896 } 00897 return TRUE; 00898 } }

NTSTATUS HvpBuildMap PHHIVE  Hive,
PVOID  Image,
PHCELL_INDEX TailDisplay  OPTIONAL
 

Definition at line 536 of file hivemap.c.

References Bin, CML_FLOW, CMLOG, CMS_HIVE, ErrorExit(), _HBIN::FileOffset, HBIN_SIGNATURE, HBLOCK_SIZE, Hive, HvCheckHiveDebug, HvpCleanMap(), HvpEnlistBinInMap(), HvpInitMap(), NT_SUCCESS, NTSTATUS(), Offset, _HBIN::Signature, _HBIN::Size, Stable, and Status.

Referenced by HvInitializeHive().

00543 : 00544 00545 Creates the map for the Stable storage of the hive, and inits 00546 the map for the volatile storage. 00547 00548 Following fields in hive must already be filled in: 00549 00550 Allocate, Free 00551 00552 Will initialize Storage structure of HHIVE. 00553 00554 Arguments: 00555 00556 Hive - Pointer to hive control structure to build map for. 00557 00558 Image - pointer to in memory image of the hive 00559 00560 Return Value: 00561 00562 TRUE - it worked 00563 FALSE - either hive is corrupt or no memory for map 00564 00565 --*/ 00566 { 00567 PHBIN Bin; 00568 ULONG Offset; 00569 NTSTATUS Status; 00570 ULONG Length; 00571 00572 00573 CMLOG(CML_FLOW, CMS_HIVE) { 00574 KdPrint(("HvpBuildMap:\n")); 00575 KdPrint(("\tHive=%08lx",Hive)); 00576 } 00577 00578 // 00579 // Init the map 00580 // 00581 Status = HvpInitMap(Hive); 00582 00583 if( !NT_SUCCESS(Status) ) { 00584 // 00585 // just return failure; HvpInitMap took care of cleanup 00586 // 00587 return Status; 00588 } 00589 00590 // 00591 // Fill in the map 00592 // 00593 Offset = 0; 00594 Bin = (PHBIN)Image; 00595 Length = Hive->Storage[Stable].Length; 00596 00597 while (Bin < (PHBIN)((PUCHAR)(Image) + Length)) { 00598 00599 // 00600 // Check the validity of the bin header 00601 // 00602 if ( (Bin->Size > Length) || 00603 (Bin->Size < HBLOCK_SIZE) || 00604 (Bin->Signature != HBIN_SIGNATURE) || 00605 (Bin->FileOffset != Offset)) { 00606 // 00607 // Bin is bogus 00608 // 00609 Status = STATUS_REGISTRY_CORRUPT; 00610 HvCheckHiveDebug.Hive = Hive; 00611 HvCheckHiveDebug.Status = 0xA001; 00612 HvCheckHiveDebug.Space = Length; 00613 HvCheckHiveDebug.MapPoint = Offset; 00614 HvCheckHiveDebug.BinPoint = Bin; 00615 goto ErrorExit; 00616 } 00617 00618 // 00619 // enlist this bin 00620 // 00621 Status = HvpEnlistBinInMap(Hive, Length, Bin, Offset, TailDisplay); 00622 00623 if( !NT_SUCCESS(Status) ) { 00624 goto ErrorExit; 00625 } 00626 00627 // 00628 // the next bin 00629 // 00630 Offset += Bin->Size; 00631 00632 Bin = (PHBIN)((ULONG_PTR)Bin + Bin->Size); 00633 } 00634 00635 return STATUS_SUCCESS; 00636 00637 00638 ErrorExit: 00639 // 00640 // Clean up the directory table 00641 // 00642 HvpCleanMap( Hive ); 00643 00644 return Status; 00645 }

NTSTATUS HvpBuildMapAndCopy PHHIVE  Hive,
PVOID  Image,
PHCELL_INDEX TailDisplay  OPTIONAL
 

Definition at line 47 of file hivemap.c.

References _HHIVE::Allocate, _HHIVE::BaseBlock, Bin, _HMAP_ENTRY::BinAddress, _HMAP_ENTRY::BlockAddress, CML_FLOW, CMLOG, CMS_HIVE, _HHIVE::DirtyAlloc, _HHIVE::DirtyVector, FALSE, _HBIN::FileOffset, _HHIVE::Free, HBIN_SIGNATURE, HBLOCK_SIZE, Hive, HMAP_NEWALLOC, HSECTOR_SIZE, HTABLE_SLOTS, HvpAllocateMap(), HvpEnlistFreeCells(), HvpFreeMap(), HvpGetCellMap(), _HBASE_BLOCK::Length, _HBIN::MemAlloc, NTSTATUS(), NULL, Offset, PAGE_SIZE, _HHIVE::ReadOnly, ROUND_UP, RtlInitializeBitMap(), _HBIN::Signature, _HBIN::Size, Size, Stable, Status, t(), TRUE, and VALIDATE_CELL_MAP.

Referenced by HvInitializeHive().

00054 : 00055 00056 Creates the map for the Stable storage of the hive, and inits 00057 the map for the volatile storage. 00058 00059 Following fields in hive must already be filled in: 00060 00061 Allocate, Free 00062 00063 Will initialize Storage structure of HHIVE. 00064 00065 The difference between this routine and HvpBuildMapAndCopy is that 00066 this routine will create a "sparse" map. As it copies the SourceImage 00067 to the newly allocated memory for the destination, it will avoid 00068 allocating space for HBINs that contain nothing but free space. The 00069 HBLOCKs in these HBINs will be marked as discarded, and HvGetCell 00070 will allocate memory for them if necessary. 00071 00072 Arguments: 00073 00074 Hive - Pointer to hive control structure to build map for. 00075 00076 Image - pointer to flat memory image of original hive. 00077 00078 Return Value: 00079 00080 TRUE - it worked 00081 FALSE - either hive is corrupt or no memory for map 00082 00083 --*/ 00084 { 00085 PHBASE_BLOCK BaseBlock; 00086 ULONG Length; 00087 ULONG MapSlots; 00088 ULONG Tables; 00089 PHMAP_TABLE t = NULL; 00090 PHMAP_DIRECTORY d = NULL; 00091 PHBIN Bin; 00092 PHBIN NewBins; 00093 PHBIN CurrentBin; 00094 ULONG Offset; 00095 ULONG_PTR Address; 00096 PHMAP_ENTRY Me; 00097 NTSTATUS Status; 00098 PULONG Vector; 00099 ULONG Size; 00100 00101 00102 CMLOG(CML_FLOW, CMS_HIVE) { 00103 KdPrint(("HvpBuildMap:\n")); 00104 KdPrint(("\tHive=%08lx",Hive)); 00105 } 00106 00107 00108 // 00109 // Compute size of data region to be mapped 00110 // 00111 BaseBlock = Hive->BaseBlock; 00112 Length = BaseBlock->Length; 00113 if ((Length % HBLOCK_SIZE) != 0 ) { 00114 Status = STATUS_REGISTRY_CORRUPT; 00115 goto ErrorExit1; 00116 } 00117 MapSlots = Length / HBLOCK_SIZE; 00118 if( MapSlots > 0 ) { 00119 Tables = (MapSlots-1) / HTABLE_SLOTS; 00120 } else { 00121 Tables = 0; 00122 } 00123 00124 Hive->Storage[Stable].Length = Length; 00125 00126 // 00127 // allocate dirty vector if one is not already present (from HvpRecoverData) 00128 // 00129 00130 if (Hive->DirtyVector.Buffer == NULL) { 00131 Vector = (PULONG)((Hive->Allocate)(ROUND_UP(Length/HSECTOR_SIZE/8,sizeof(ULONG)), TRUE)); 00132 if (Vector == NULL) { 00133 Status = STATUS_NO_MEMORY; 00134 goto ErrorExit1; 00135 } 00136 RtlZeroMemory(Vector, Length / HSECTOR_SIZE / 8); 00137 RtlInitializeBitMap(&Hive->DirtyVector, Vector, Length / HSECTOR_SIZE); 00138 Hive->DirtyAlloc = (Length/HSECTOR_SIZE/8); 00139 } 00140 00141 // 00142 // allocate and build structure for map 00143 // 00144 if (Tables == 0) { 00145 00146 // 00147 // Just 1 table, no need for directory 00148 // 00149 t = (Hive->Allocate)(sizeof(HMAP_TABLE), FALSE); 00150 if (t == NULL) { 00151 Status = STATUS_INSUFFICIENT_RESOURCES; 00152 goto ErrorExit1; 00153 } 00154 RtlZeroMemory(t, sizeof(HMAP_TABLE)); 00155 Hive->Storage[Stable].Map = 00156 (PHMAP_DIRECTORY)&(Hive->Storage[Stable].SmallDir); 00157 Hive->Storage[Stable].SmallDir = t; 00158 00159 } else { 00160 00161 // 00162 // Need directory and multiple tables 00163 // 00164 d = (PHMAP_DIRECTORY)(Hive->Allocate)(sizeof(HMAP_DIRECTORY), FALSE); 00165 if (d == NULL) { 00166 Status = STATUS_INSUFFICIENT_RESOURCES; 00167 goto ErrorExit1; 00168 } 00169 RtlZeroMemory(d, sizeof(HMAP_DIRECTORY)); 00170 00171 // 00172 // Allocate tables and fill in dir 00173 // 00174 if (HvpAllocateMap(Hive, d, 0, Tables) == FALSE) { 00175 Status = STATUS_INSUFFICIENT_RESOURCES; 00176 goto ErrorExit2; 00177 } 00178 Hive->Storage[Stable].Map = d; 00179 Hive->Storage[Stable].SmallDir = 0; 00180 } 00181 00182 // 00183 // Now we have to allocate the memory for the HBINs and fill in 00184 // the map appropriately. We are careful never to allocate less 00185 // than a page to avoid fragmenting pool. As long as the page 00186 // size is a multiple of HBLOCK_SIZE (a fairly good assumption as 00187 // long as HBLOCK_SIZE is 4k) this strategy will prevent pool 00188 // fragmentation. 00189 // 00190 // If we come across an HBIN that is entirely composed of a freed 00191 // HCELL, then we do not allocate memory, but mark its HBLOCKs in 00192 // the map as not present. HvAllocateCell will allocate memory for 00193 // the bin when it is needed. 00194 // 00195 Offset = 0; 00196 Size = 0; 00197 Bin = (PHBIN)Image; 00198 00199 while (Bin < (PHBIN)((PUCHAR)(Image) + Length)) { 00200 00201 if ( (Bin->Size > (Length-Offset)) || 00202 (Bin->Signature != HBIN_SIGNATURE) || 00203 (Bin->FileOffset != (Offset+Size)) 00204 ) 00205 { 00206 // 00207 // Bin is bogus 00208 // 00209 Status = STATUS_REGISTRY_CORRUPT; 00210 goto ErrorExit2; 00211 } 00212 00213 Size += Bin->Size; 00214 if ((Size < PAGE_SIZE) && 00215 (Size + Length - Offset > PAGE_SIZE)) { 00216 00217 // 00218 // We haven't accumulated enough bins to fill up a page 00219 // yet, and there are still bins left, so group this one 00220 // in with the next one. 00221 // 00222 Bin = (PHBIN)((ULONG_PTR)Bin + Bin->Size); 00223 00224 continue; 00225 00226 } 00227 00228 // 00229 // We now have a series of HBINs to group together in one 00230 // chunk of memory. 00231 // 00232 NewBins = (PHBIN)(Hive->Allocate)(Size, FALSE); 00233 if (NewBins==NULL) { 00234 Status = STATUS_INSUFFICIENT_RESOURCES; 00235 goto ErrorExit2; //fixfix 00236 } 00237 RtlCopyMemory(NewBins, 00238 (PUCHAR)Image+Offset, 00239 Size); 00240 NewBins->MemAlloc = Size; 00241 00242 // 00243 // create map entries for each block/page in bin 00244 // 00245 Address = (ULONG_PTR)NewBins; 00246 do { 00247 CurrentBin = (PHBIN)Address; 00248 do { 00249 Me = HvpGetCellMap(Hive, Offset); 00250 VALIDATE_CELL_MAP(__LINE__,Me,Hive,Offset); 00251 Me->BlockAddress = Address; 00252 Me->BinAddress = (ULONG_PTR)CurrentBin; 00253 00254 if (CurrentBin == NewBins) { 00255 Me->BinAddress |= HMAP_NEWALLOC; 00256 } else { 00257 CurrentBin->MemAlloc = 0; 00258 } 00259 Address += HBLOCK_SIZE; 00260 Offset += HBLOCK_SIZE; 00261 } while ( Address < ((ULONG_PTR)CurrentBin + CurrentBin->Size )); 00262 00263 if (Hive->ReadOnly == FALSE) { 00264 00265 // 00266 // add free cells in the bin to the appropriate free lists 00267 // 00268 if ( ! HvpEnlistFreeCells(Hive, 00269 CurrentBin, 00270 CurrentBin->FileOffset, 00271 TailDisplay 00272 )) { 00273 Status = STATUS_REGISTRY_CORRUPT; 00274 goto ErrorExit2; 00275 } 00276 00277 } 00278 00279 } while ( Address < (ULONG_PTR)NewBins + Size ); 00280 00281 Bin = (PHBIN)((ULONG_PTR)Bin + Bin->Size); 00282 Size = 0; 00283 } 00284 00285 return STATUS_SUCCESS; 00286 00287 00288 ErrorExit2: 00289 if (d != NULL) { 00290 00291 // 00292 // directory was built and allocated, so clean it up 00293 // 00294 00295 HvpFreeMap(Hive, d, 0, Tables); 00296 (Hive->Free)(d, sizeof(HMAP_DIRECTORY)); 00297 } 00298 00299 ErrorExit1: 00300 return Status; 00301 }

VOID HvpCleanMap PHHIVE  Hive  ) 
 

Definition at line 751 of file hivemap.c.

References _HHIVE::Free, HBLOCK_SIZE, Hive, HTABLE_SLOTS, HvpFreeMap(), NULL, and Stable.

Referenced by HvLoadHive(), HvpBuildMap(), and HvpReadFileImageAndBuildMap().

00756 : 00757 00758 Cleans all the map allocations for the stable storage 00759 00760 Arguments: 00761 00762 Hive - Pointer to hive control structure to build map for. 00763 00764 Return Value: 00765 00766 None 00767 --*/ 00768 { 00769 ULONG Length; 00770 ULONG MapSlots; 00771 ULONG Tables; 00772 PHMAP_DIRECTORY d = NULL; 00773 00774 // 00775 // Compute MapSlots and Tables based on the Length 00776 // 00777 Length = Hive->Storage[Stable].Length; 00778 MapSlots = Length / HBLOCK_SIZE; 00779 if( MapSlots > 0 ) { 00780 Tables = (MapSlots-1) / HTABLE_SLOTS; 00781 } else { 00782 Tables = 0; 00783 } 00784 00785 if( Hive->Storage[Stable].SmallDir == 0 ) { 00786 // 00787 // directory was built and allocated, so clean it up 00788 // 00789 00790 d = Hive->Storage[Stable].Map; 00791 if( d != NULL ) { 00792 HvpFreeMap(Hive, d, 0, Tables); 00793 (Hive->Free)(d, sizeof(HMAP_DIRECTORY)); 00794 } 00795 } else { 00796 // 00797 // no directory, just a smalldir 00798 // 00799 (Hive->Free)(Hive->Storage[Stable].SmallDir, sizeof(HMAP_TABLE)); 00800 } 00801 00802 Hive->Storage[Stable].SmallDir = NULL; 00803 Hive->Storage[Stable].Map = NULL; 00804 }

NTSTATUS HvpEnlistBinInMap PHHIVE  Hive,
ULONG  Length,
PHBIN  Bin,
ULONG  Offset,
PHCELL_INDEX TailDisplay  OPTIONAL
 

Definition at line 437 of file hivemap.c.

References ASSERT, Bin, _HMAP_ENTRY::BinAddress, _HMAP_ENTRY::BlockAddress, CML_BIN, CML_FLOW, CMLOG, CMS_BIN_MAP, CMS_HIVE, ErrorExit(), FALSE, HBLOCK_SIZE, Hive, HMAP_NEWALLOC, HvCheckHiveDebug, HvpEnlistFreeCells(), HvpGetCellMap(), _HBIN::MemAlloc, NTSTATUS(), Offset, _HHIVE::ReadOnly, _HBIN::Size, Status, and VALIDATE_CELL_MAP.

Referenced by HvpBuildMap(), HvpReadFileImageAndBuildMap(), and HvpRecoverData().

00446 : 00447 00448 Creates map entries and enlist free cells for the specified bin 00449 00450 Arguments: 00451 00452 Hive - Pointer to hive control structure containing the target map 00453 00454 Length - the Length of the hive image 00455 00456 Bin - the bin to be enlisted 00457 00458 Offset - the offset within the hive file 00459 00460 TailDisplay - array containing the tail ends of the free cell lists - optional 00461 00462 Return Value: 00463 00464 STATUS_SUCCESS - it worked 00465 STATUS_REGISTRY_CORRUPT - the bin is inconsistent 00466 00467 --*/ 00468 { 00469 NTSTATUS Status; 00470 ULONG BinOffset; 00471 ULONG_PTR Address; 00472 PHMAP_ENTRY Me; 00473 00474 CMLOG(CML_FLOW, CMS_HIVE) { 00475 KdPrint(("HvpEnlistBinInMap:\n")); 00476 KdPrint(("\tHive=%08lx\t Offset=%08lx",Hive,Offset)); 00477 } 00478 00479 // 00480 // memory was allocated for this bin 00481 // 00482 Bin->MemAlloc = Bin->Size; 00483 00484 CMLOG(CML_BIN, CMS_BIN_MAP) { 00485 KdPrint(("HvpEnlistBinInMap: BinAddress = 0x%08lx\t Size = 0x%lx\n", Bin, Bin->Size)); 00486 } 00487 00488 // 00489 // create map entries for each block/page in bin 00490 // 00491 BinOffset = Offset; 00492 for (Address = (ULONG_PTR)Bin; 00493 Address < ((ULONG_PTR)Bin + Bin->Size); 00494 Address += HBLOCK_SIZE 00495 ) 00496 { 00497 Me = HvpGetCellMap(Hive, Offset); 00498 VALIDATE_CELL_MAP(__LINE__,Me,Hive,Offset); 00499 Me->BlockAddress = Address; 00500 Me->BinAddress = (ULONG_PTR)Bin; 00501 if (Offset == BinOffset) { 00502 Me->BinAddress |= HMAP_NEWALLOC; 00503 } 00504 Offset += HBLOCK_SIZE; 00505 } 00506 00507 if (Hive->ReadOnly == FALSE) { 00508 00509 // 00510 // add free cells in the bin to the appropriate free lists 00511 // 00512 if ( ! HvpEnlistFreeCells(Hive, Bin, BinOffset,TailDisplay)) { 00513 HvCheckHiveDebug.Hive = Hive; 00514 HvCheckHiveDebug.Status = 0xA002; 00515 HvCheckHiveDebug.Space = Length; 00516 HvCheckHiveDebug.MapPoint = BinOffset; 00517 HvCheckHiveDebug.BinPoint = Bin; 00518 Status = STATUS_REGISTRY_CORRUPT; 00519 goto ErrorExit; 00520 } 00521 00522 } 00523 00524 // 00525 // logical consistency check 00526 // 00527 ASSERT(Offset == (BinOffset + Bin->Size)); 00528 00529 return STATUS_SUCCESS; 00530 00531 ErrorExit: 00532 return Status; 00533 }

BOOLEAN HvpEnlistFreeCells PHHIVE  Hive,
PHBIN  Bin,
ULONG  BinOffset,
PHCELL_INDEX TailDisplay  OPTIONAL
 

Definition at line 649 of file hivemap.c.

References ASSERT, Bin, FALSE, HCELL_INDEX, HCELL_PAD, Hive, HvpEnlistFreeCell(), _HCELL::Size, _HBIN::Size, Stable, and TRUE.

Referenced by HvpBuildMapAndCopy(), HvpEnlistBinInMap(), HvpRecoverData(), and HvRefreshHive().

00657 : 00658 00659 Scan through the cells in the bin, locating the free ones. 00660 Enlist them in the hive's free list set. 00661 00662 N.B. Bin MUST already be mapped when this is called. 00663 00664 Arguments: 00665 00666 Hive - pointer to hive control structure map is being built for 00667 00668 Bin - pointer to bin to enlist cells from 00669 00670 BinOffset - offset of Bin in image 00671 00672 Return Value: 00673 00674 FALSE - registry is corrupt 00675 00676 TRUE - it worked 00677 00678 --*/ 00679 { 00680 PHCELL p; 00681 ULONG celloffset; 00682 ULONG size; 00683 HCELL_INDEX cellindex; 00684 00685 // PERFNOTE -- Keep this in mind as a possible optimization for NT6. 00686 // Since now the hive is loaded in chunks of bins, we can drop the 00687 // bins that are entirely free!!!!!! 00688 // 00689 00690 // 00691 // Scan all the cells in the bin, total free and allocated, check 00692 // for impossible pointers. 00693 // 00694 celloffset = sizeof(HBIN); 00695 p = (PHCELL)((PUCHAR)Bin + sizeof(HBIN)); 00696 00697 while (p < (PHCELL)((PUCHAR)Bin + Bin->Size)) { 00698 00699 // 00700 // if free cell, check it out, add it to free list for hive 00701 // 00702 if (p->Size >= 0) { 00703 00704 size = (ULONG)p->Size; 00705 00706 if ( (size > Bin->Size) || 00707 ( (PHCELL)(size + (PUCHAR)p) > 00708 (PHCELL)((PUCHAR)Bin + Bin->Size) ) || 00709 ((size % HCELL_PAD(Hive)) != 0) || 00710 (size == 0) ) 00711 { 00712 return FALSE; 00713 } 00714 00715 00716 // 00717 // cell is free, and is not obviously corrupt, add to free list 00718 // 00719 celloffset = (ULONG)((PUCHAR)p - (PUCHAR)Bin); 00720 cellindex = BinOffset + celloffset; 00721 00722 // 00723 // Enlist this free cell, but do not coalesce with the next free cell 00724 // as we haven't gotten that far yet. 00725 // 00726 HvpEnlistFreeCell(Hive, cellindex, size, Stable, FALSE,TailDisplay); 00727 00728 } else { 00729 00730 size = (ULONG)(p->Size * -1); 00731 00732 if ( (size > Bin->Size) || 00733 ( (PHCELL)(size + (PUCHAR)p) > 00734 (PHCELL)((PUCHAR)Bin + Bin->Size) ) || 00735 ((size % HCELL_PAD(Hive)) != 0) || 00736 (size == 0) ) 00737 { 00738 return FALSE; 00739 } 00740 00741 } 00742 00743 ASSERT(size >= 0); 00744 p = (PHCELL)((PUCHAR)p + size); 00745 } 00746 00747 return TRUE; 00748 }

VOID HvpFreeMap PHHIVE  Hive,
PHMAP_DIRECTORY  Dir,
ULONG  Start,
ULONG  End
 

Definition at line 807 of file hivemap.c.

References _HMAP_DIRECTORY::Directory, End, _HHIVE::Free, HDIRECTORY_SLOTS, Hive, NULL, and Start.

Referenced by HvFreeHive(), HvFreeHivePartial(), HvpAddBin(), HvpBuildMapAndCopy(), HvpCleanMap(), and HvpInitMap().

00815 : 00816 00817 Sweeps through the directory Dir points to and frees Tables. 00818 Will free Start-th through End-th entries, INCLUSIVE. 00819 00820 Arguments: 00821 00822 Hive - supplies pointer to hive control block of interest 00823 00824 Dir - supplies address of an HMAP_DIRECTORY structure 00825 00826 Start - index of first map table pointer to clean up 00827 00828 End - index of last map table pointer to clean up 00829 00830 Return Value: 00831 00832 NONE. 00833 00834 --*/ 00835 { 00836 ULONG i; 00837 00838 if (End >= HDIRECTORY_SLOTS) { 00839 End = HDIRECTORY_SLOTS - 1; 00840 } 00841 00842 for (i = Start; i <= End; i++) { 00843 if (Dir->Directory[i] != NULL) { 00844 (Hive->Free)(Dir->Directory[i], sizeof(HMAP_TABLE)); 00845 Dir->Directory[i] = NULL; 00846 } 00847 } 00848 return; 00849 }

NTSTATUS HvpInitMap PHHIVE  Hive  ) 
 

Definition at line 304 of file hivemap.c.

References _HHIVE::Allocate, _HHIVE::BaseBlock, CML_FLOW, CMLOG, CMS_HIVE, _HHIVE::DirtyAlloc, _HHIVE::DirtyVector, FALSE, _HHIVE::Free, HBLOCK_SIZE, Hive, HSECTOR_SIZE, HTABLE_SLOTS, HvpAllocateMap(), HvpFreeMap(), _HBASE_BLOCK::Length, NTSTATUS(), NULL, ROUND_UP, RtlInitializeBitMap(), Stable, Status, t(), and TRUE.

Referenced by HvpBuildMap(), and HvpReadFileImageAndBuildMap().

00309 : 00310 00311 Initialize the map for the Stable Volatile storage of the hive. 00312 00313 Following fields in hive must already be filled in: 00314 00315 Allocate, Free 00316 00317 Will initialize Storage structure of HHIVE. 00318 00319 Arguments: 00320 00321 Hive - Pointer to hive control structure to build map for. 00322 00323 Return Value: 00324 00325 STATUS_SUCCESS - it worked 00326 STATUS_xxx - the errorneous status 00327 00328 --*/ 00329 { 00330 PHBASE_BLOCK BaseBlock; 00331 ULONG Length; 00332 ULONG MapSlots; 00333 ULONG Tables; 00334 PHMAP_TABLE t = NULL; 00335 PHMAP_DIRECTORY d = NULL; 00336 NTSTATUS Status; 00337 PULONG Vector; 00338 00339 00340 CMLOG(CML_FLOW, CMS_HIVE) { 00341 KdPrint(("HvpInitMap:\n")); 00342 KdPrint(("\tHive=%08lx",Hive)); 00343 } 00344 00345 // 00346 // Compute size of data region to be mapped 00347 // 00348 BaseBlock = Hive->BaseBlock; 00349 Length = BaseBlock->Length; 00350 if ((Length % HBLOCK_SIZE) != 0) { 00351 Status = STATUS_REGISTRY_CORRUPT; 00352 goto ErrorExit1; 00353 } 00354 MapSlots = Length / HBLOCK_SIZE; 00355 if( MapSlots > 0 ) { 00356 Tables = (MapSlots-1) / HTABLE_SLOTS; 00357 } else { 00358 Tables = 0; 00359 } 00360 00361 Hive->Storage[Stable].Length = Length; 00362 00363 // 00364 // allocate dirty vector if one is not already present (from HvpRecoverData) 00365 // 00366 00367 if (Hive->DirtyVector.Buffer == NULL) { 00368 Vector = (PULONG)((Hive->Allocate)(ROUND_UP(Length/HSECTOR_SIZE/8,sizeof(ULONG)), TRUE)); 00369 if (Vector == NULL) { 00370 Status = STATUS_NO_MEMORY; 00371 goto ErrorExit1; 00372 } 00373 RtlZeroMemory(Vector, Length / HSECTOR_SIZE / 8); 00374 RtlInitializeBitMap(&Hive->DirtyVector, Vector, Length / HSECTOR_SIZE); 00375 Hive->DirtyAlloc = (Length/HSECTOR_SIZE/8); 00376 } 00377 00378 // 00379 // allocate and build structure for map 00380 // 00381 if (Tables == 0) { 00382 00383 // 00384 // Just 1 table, no need for directory 00385 // 00386 t = (Hive->Allocate)(sizeof(HMAP_TABLE), FALSE); 00387 if (t == NULL) { 00388 Status = STATUS_INSUFFICIENT_RESOURCES; 00389 goto ErrorExit1; 00390 } 00391 RtlZeroMemory(t, sizeof(HMAP_TABLE)); 00392 Hive->Storage[Stable].Map = 00393 (PHMAP_DIRECTORY)&(Hive->Storage[Stable].SmallDir); 00394 Hive->Storage[Stable].SmallDir = t; 00395 00396 } else { 00397 00398 // 00399 // Need directory and multiple tables 00400 // 00401 d = (PHMAP_DIRECTORY)(Hive->Allocate)(sizeof(HMAP_DIRECTORY), FALSE); 00402 if (d == NULL) { 00403 Status = STATUS_INSUFFICIENT_RESOURCES; 00404 goto ErrorExit1; 00405 } 00406 RtlZeroMemory(d, sizeof(HMAP_DIRECTORY)); 00407 00408 // 00409 // Allocate tables and fill in dir 00410 // 00411 if (HvpAllocateMap(Hive, d, 0, Tables) == FALSE) { 00412 Status = STATUS_INSUFFICIENT_RESOURCES; 00413 goto ErrorExit2; 00414 } 00415 Hive->Storage[Stable].Map = d; 00416 Hive->Storage[Stable].SmallDir = 0; 00417 } 00418 00419 return STATUS_SUCCESS; 00420 00421 ErrorExit2: 00422 if (d != NULL) { 00423 00424 // 00425 // directory was built and allocated, so clean it up 00426 // 00427 00428 HvpFreeMap(Hive, d, 0, Tables); 00429 (Hive->Free)(d, sizeof(HMAP_DIRECTORY)); 00430 } 00431 00432 ErrorExit1: 00433 return Status; 00434 }


Variable Documentation

PHBIN BinPoint
 

Definition at line 43 of file hivemap.c.

PHHIVE Hive
 

Definition at line 39 of file hivemap.c.

struct { ... } HvCheckHiveDebug
 

HCELL_INDEX MapPoint
 

Definition at line 42 of file hivemap.c.

ULONG Space
 

Definition at line 41 of file hivemap.c.

ULONG Status
 

Definition at line 40 of file hivemap.c.


Generated on Sat May 15 19:44:05 2004 for test by doxygen 1.3.7