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

cmtredel.c File Reference

#include "cmp.h"

Go to the source code of this file.

Functions

VOID CmpDeleteTree (PHHIVE Hive, HCELL_INDEX Cell)
NTSTATUS CmpFreeKeyByCell (PHHIVE Hive, HCELL_INDEX Cell, BOOLEAN Unlink)
BOOLEAN CmpMarkKeyDirty (PHHIVE Hive, HCELL_INDEX Cell)


Function Documentation

VOID CmpDeleteTree PHHIVE  Hive,
HCELL_INDEX  Cell
 

Definition at line 34 of file cmtredel.c.

References Cell, CML_MAJOR, CMLOG, CmpFindSubKeyByNumber(), CmpFreeKeyByCell(), CMS_SAVRES, HCELL_INDEX, Hive, HvGetCell, _CM_KEY_NODE::Parent, Stable, _CM_KEY_NODE::SubKeyCounts, TRUE, and Volatile.

Referenced by CmpSyncSubKeysAfterDelete(), and CmRestoreKey().

00040 : 00041 00042 Delete all child subkeys, recursively, of Hive.Cell. Delete all 00043 value entries of Hive.Cell. Do NOT delete Hive.Cell itself. 00044 00045 NOTE: If this call fails part way through, it will NOT undo 00046 any successfully completed deletes. 00047 00048 NOTE: This algorithm can deal with a hive of any depth, at the 00049 cost of some "redundent" scaning and mapping. 00050 00051 Arguments: 00052 00053 Hive - pointer to hive control structure for hive to delete from 00054 00055 Cell - index of cell at root of tree to delete 00056 00057 Return Value: 00058 00059 BOOLEAN - Result code from call, among the following: 00060 TRUE - it worked 00061 FALSE - the tree delete was not completed (though more than 0 00062 keys may have been deleted) 00063 00064 --*/ 00065 { 00066 ULONG count; 00067 HCELL_INDEX ptr1; 00068 HCELL_INDEX ptr2; 00069 HCELL_INDEX parent; 00070 PCM_KEY_NODE Node; 00071 00072 CMLOG(CML_MAJOR, CMS_SAVRES) { 00073 KdPrint(("CmpDeleteTree:\n")); 00074 KdPrint(("\tHive=%08lx Cell=%08lx\n",Hive,Cell)); 00075 } 00076 00077 ptr1 = Cell; 00078 00079 while(TRUE) { 00080 00081 Node = (PCM_KEY_NODE)HvGetCell(Hive, ptr1); 00082 count = Node->SubKeyCounts[Stable] + 00083 Node->SubKeyCounts[Volatile]; 00084 parent = Node->Parent; 00085 00086 if (count > 0) { // ptr1->count > 0? 00087 00088 // 00089 // subkeys exist, find and delete them 00090 // 00091 ptr2 = CmpFindSubKeyByNumber(Hive, Node, 0); 00092 00093 Node = (PCM_KEY_NODE)HvGetCell(Hive, ptr2); 00094 count = Node->SubKeyCounts[Stable] + 00095 Node->SubKeyCounts[Volatile]; 00096 00097 if (count > 0) { // ptr2->count > 0? 00098 00099 // 00100 // subkey has subkeys, descend to next level 00101 // 00102 ptr1 = ptr2; 00103 continue; 00104 00105 } else { 00106 00107 // 00108 // have found leaf, delete it 00109 // 00110 CmpFreeKeyByCell(Hive, ptr2, TRUE); 00111 continue; 00112 } 00113 00114 } else { 00115 00116 // 00117 // no more subkeys at this level, we are now a leaf. 00118 // 00119 if (ptr1 != Cell) { 00120 00121 // 00122 // we are not at the root cell, so ascend to parent 00123 // 00124 ptr1 = parent; // ptr1 = ptr1->parent 00125 continue; 00126 00127 } else { 00128 00129 // 00130 // we are at the root cell, we are done 00131 // 00132 return; 00133 } 00134 } // outer if 00135 } // while 00136 }

NTSTATUS CmpFreeKeyByCell PHHIVE  Hive,
HCELL_INDEX  Cell,
BOOLEAN  Unlink
 

Definition at line 140 of file cmtredel.c.

References ASSERT, Cell, CmpFreeKeyBody(), CmpFreeSecurityDescriptor(), CmpFreeValue(), CmpMarkKeyDirty(), CmpRemoveSubKey(), _CHILD_LIST::Count, _CM_KEY_NODE::Flags, Hive, HvFreeCell(), HvGetCell, KEY_HIVE_EXIT, KEY_PREDEF_HANDLE, _CELL_DATA::_u::KeyList, _CELL_DATA::_u::KeyNode, _CHILD_LIST::List, _CM_KEY_NODE::MaxClassLen, _CM_KEY_NODE::MaxNameLen, _CM_KEY_NODE::Parent, Stable, _CM_KEY_NODE::SubKeyCounts, TRUE, _CELL_DATA::u, _CM_KEY_NODE::ValueList, and Volatile.

Referenced by CmDeleteKey(), CmpDeleteTree(), CmpDestroyHive(), CmpDoCreate(), CmpSyncSubKeysAfterDelete(), CmRestoreKey(), and EhCreateChild().

00147 : 00148 00149 Actually free the storage for the specified cell. We will first 00150 remove it from its parent's child key list, then free all of its 00151 values, then the key body itself. 00152 00153 Arguments: 00154 00155 Hive - pointer to hive control structure for hive of interest 00156 00157 Cell - index for cell to free storage for (the target) 00158 00159 Unlink - if TRUE, target cell will be removed from parent cell's 00160 subkeylist, if FALSE, it will NOT be. 00161 00162 Return Value: 00163 00164 NONE. 00165 00166 --*/ 00167 { 00168 PCELL_DATA ptarget; 00169 PCELL_DATA pparent; 00170 PCELL_DATA plist; 00171 ULONG i; 00172 00173 // 00174 // Mark dirty everything that we might touch 00175 // 00176 if (! CmpMarkKeyDirty(Hive, Cell)) { 00177 return STATUS_NO_LOG_SPACE; 00178 } 00179 00180 // 00181 // Map in the target 00182 // 00183 ptarget = HvGetCell(Hive, Cell); 00184 ASSERT((ptarget->u.KeyNode.SubKeyCounts[Stable] + 00185 ptarget->u.KeyNode.SubKeyCounts[Volatile]) == 0); 00186 00187 00188 if (Unlink == TRUE) { 00189 BOOLEAN Success; 00190 00191 Success = CmpRemoveSubKey(Hive, ptarget->u.KeyNode.Parent, Cell); 00192 if (!Success) { 00193 return STATUS_INSUFFICIENT_RESOURCES; 00194 } 00195 pparent = HvGetCell(Hive, ptarget->u.KeyNode.Parent); 00196 if ( (pparent->u.KeyNode.SubKeyCounts[Stable] + 00197 pparent->u.KeyNode.SubKeyCounts[Volatile]) == 0) 00198 { 00199 pparent->u.KeyNode.MaxNameLen = 0; 00200 pparent->u.KeyNode.MaxClassLen = 0; 00201 } 00202 } 00203 00204 // 00205 // Target is now an unreferenced key, free it's actual storage 00206 // 00207 00208 // 00209 // Free misc stuff 00210 // 00211 if (!(ptarget->u.KeyNode.Flags & KEY_HIVE_EXIT) && 00212 !(ptarget->u.KeyNode.Flags & KEY_PREDEF_HANDLE) ) { 00213 00214 // 00215 // First, free the value entries 00216 // 00217 if (ptarget->u.KeyNode.ValueList.Count > 0) { 00218 00219 // target list 00220 plist = HvGetCell(Hive, ptarget->u.KeyNode.ValueList.List); 00221 00222 for (i = 0; i < ptarget->u.KeyNode.ValueList.Count; i++) { 00223 CmpFreeValue(Hive, plist->u.KeyList[i]); 00224 } 00225 00226 HvFreeCell(Hive, ptarget->u.KeyNode.ValueList.List); 00227 } 00228 00229 // 00230 // Free the security descriptor 00231 // 00232 CmpFreeSecurityDescriptor(Hive, Cell); 00233 } 00234 00235 // 00236 // Free the key body itself, and Class data. 00237 // 00238 CmpFreeKeyBody(Hive, Cell); 00239 00240 return STATUS_SUCCESS; 00241 }

BOOLEAN CmpMarkKeyDirty PHHIVE  Hive,
HCELL_INDEX  Cell
 

Definition at line 245 of file cmtredel.c.

References ASSERT, _CM_KEY_SECURITY::Blink, Cell, _CM_KEY_NODE::Class, CmpIsHKeyValueSmall, CmpMarkIndexDirty(), _CHILD_LIST::Count, _CM_KEY_VALUE::Data, _CM_KEY_VALUE::DataLength, FALSE, _CM_KEY_NODE::Flags, _CM_KEY_SECURITY::Flink, HCELL_NIL, Hive, HvGetCell, HvMarkCellDirty(), KEY_HIVE_ENTRY, KEY_HIVE_EXIT, KEY_PREDEF_HANDLE, _CELL_DATA::_u::KeyList, _CELL_DATA::_u::KeyNode, _CELL_DATA::_u::KeySecurity, _CELL_DATA::_u::KeyValue, _CHILD_LIST::List, _CM_KEY_NODE::Parent, _CM_KEY_NODE::Security, Stable, _CM_KEY_NODE::SubKeyCounts, TRUE, _CELL_DATA::u, _CM_KEY_NODE::ValueList, and Volatile.

Referenced by CmpFreeKeyByCell().

00251 : 00252 00253 Mark all of the cells related to a key being deleted dirty. 00254 Includes the parent, the parent's child list, the key body, 00255 class, security, all value entry bodies, and all of their data cells. 00256 00257 Arguments: 00258 00259 Hive - pointer to hive control structure for hive of interest 00260 00261 Cell - index for cell holding keybody to make dirty 00262 00263 Return Value: 00264 00265 TRUE - it worked 00266 00267 FALSE - some error, most likely cannot get log space 00268 00269 --*/ 00270 { 00271 PCELL_DATA ptarget; 00272 PCELL_DATA plist; 00273 PCELL_DATA security; 00274 PCELL_DATA pvalue; 00275 ULONG i; 00276 ULONG realsize; 00277 00278 00279 // 00280 // Map in the target 00281 // 00282 ptarget = HvGetCell(Hive, Cell); 00283 ASSERT(ptarget->u.KeyNode.SubKeyCounts[Stable] == 0); 00284 ASSERT(ptarget->u.KeyNode.SubKeyCounts[Volatile] == 0); 00285 00286 if (ptarget->u.KeyNode.Flags & KEY_HIVE_EXIT) { 00287 00288 // 00289 // If this is a link node, we are done. Link nodes never have 00290 // classes, values, subkeys, or security descriptors. Since 00291 // they always reside in the master hive, they're always volatile. 00292 // 00293 return(TRUE); 00294 } 00295 00296 // 00297 // mark cell itself 00298 // 00299 if (! HvMarkCellDirty(Hive, Cell)) { 00300 return FALSE; 00301 } 00302 00303 // 00304 // Mark the class 00305 // 00306 if (ptarget->u.KeyNode.Class != HCELL_NIL) { 00307 if (! HvMarkCellDirty(Hive, ptarget->u.KeyNode.Class)) { 00308 return FALSE; 00309 } 00310 } 00311 00312 // 00313 // Mark security 00314 // 00315 if (ptarget->u.KeyNode.Security != HCELL_NIL) { 00316 if (! HvMarkCellDirty(Hive, ptarget->u.KeyNode.Security)) { 00317 return FALSE; 00318 } 00319 00320 security = HvGetCell(Hive, ptarget->u.KeyNode.Security); 00321 if (! (HvMarkCellDirty(Hive, security->u.KeySecurity.Flink) && 00322 HvMarkCellDirty(Hive, security->u.KeySecurity.Blink))) 00323 { 00324 return FALSE; 00325 } 00326 } 00327 00328 // 00329 // Mark the value entries and their data 00330 // 00331 if ( !(ptarget->u.KeyNode.Flags & KEY_PREDEF_HANDLE) && 00332 (ptarget->u.KeyNode.ValueList.Count > 0) 00333 ) { 00334 00335 // target list 00336 if (! HvMarkCellDirty(Hive, ptarget->u.KeyNode.ValueList.List)) { 00337 return FALSE; 00338 } 00339 plist = HvGetCell(Hive, ptarget->u.KeyNode.ValueList.List); 00340 00341 for (i = 0; i < ptarget->u.KeyNode.ValueList.Count; i++) { 00342 if (! HvMarkCellDirty(Hive, plist->u.KeyList[i])) { 00343 return FALSE; 00344 } 00345 00346 pvalue = HvGetCell(Hive, plist->u.KeyList[i]); 00347 00348 if (!CmpIsHKeyValueSmall(realsize, pvalue->u.KeyValue.DataLength)) { 00349 if (! HvMarkCellDirty(Hive, pvalue->u.KeyValue.Data)) { 00350 return(FALSE); 00351 } 00352 } 00353 } 00354 } 00355 00356 if (ptarget->u.KeyNode.Flags & KEY_HIVE_ENTRY) { 00357 00358 // 00359 // if this is an entry node, we are done. our parent will 00360 // be in the master hive (and thus volatile) 00361 // 00362 return TRUE; 00363 } 00364 00365 // 00366 // Mark the parent's Subkey list 00367 // 00368 if (! CmpMarkIndexDirty(Hive, ptarget->u.KeyNode.Parent, Cell)) { 00369 return FALSE; 00370 } 00371 00372 // 00373 // Mark the parent 00374 // 00375 if (! HvMarkCellDirty(Hive, ptarget->u.KeyNode.Parent)) { 00376 return FALSE; 00377 } 00378 00379 00380 return TRUE; 00381 } }


Generated on Sat May 15 19:43:12 2004 for test by doxygen 1.3.7