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

cmworker.c File Reference

#include "cmp.h"

Go to the source code of this file.

Defines

#define LAZY_FLUSH_INTERVAL_IN_SECONDS   5
#define LAZY_FLUSH_TIMEOUT_IN_SECONDS   1
#define SECOND_MULT   10*1000*1000

Functions

VOID CmpInitializeHiveList (VOID)
VOID CmpLazyFlushWorker (IN PVOID Parameter)
VOID CmpLazyFlushDpcRoutine (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
VOID CmpDiskFullWarningWorker (IN PVOID WorkItem)
VOID CmpDiskFullWarning (VOID)
VOID CmpWorker (IN PREGISTRY_COMMAND CommandArea)
VOID CmpLazyFlush (VOID)

Variables

LIST_ENTRY CmpHiveListHead
PKPROCESS CmpSystemProcess
KTIMER CmpLazyFlushTimer
KDPC CmpLazyFlushDpc
WORK_QUEUE_ITEM CmpLazyWorkItem
BOOLEAN CmpLazyFlushPending = FALSE
BOOLEAN CmpNoWrite
BOOLEAN CmpWasSetupBoot
BOOLEAN HvShutdownComplete
BOOLEAN CmpProfileLoaded
BOOLEAN CmpDiskFullWorkerPopupDisplayed
BOOLEAN CmpCannotWriteConfiguration


Define Documentation

#define LAZY_FLUSH_INTERVAL_IN_SECONDS   5
 

Definition at line 40 of file cmworker.c.

Referenced by CmpLazyFlush().

#define LAZY_FLUSH_TIMEOUT_IN_SECONDS   1
 

Definition at line 47 of file cmworker.c.

#define SECOND_MULT   10*1000*1000
 

Definition at line 49 of file cmworker.c.

Referenced by CmpLazyFlush().


Function Documentation

VOID CmpDiskFullWarning VOID   ) 
 

Referenced by CmpInitializeHiveList(), and CmpLazyFlushWorker().

VOID CmpDiskFullWarningWorker IN PVOID  WorkItem  ) 
 

Definition at line 518 of file cmworker.c.

References ExFreePool(), ExRaiseHardError(), NTSTATUS(), NULL, and Status.

Referenced by CmpDiskFullWarning().

00524 : 00525 00526 Displays hard error popup that indicates the disk is full. 00527 00528 Arguments: 00529 00530 WorkItem - Supplies pointer to the work item. This routine will 00531 free the work item. 00532 00533 Return Value: 00534 00535 None. 00536 00537 --*/ 00538 00539 { 00540 NTSTATUS Status; 00541 ULONG Response; 00542 00543 ExFreePool(WorkItem); 00544 00545 Status = ExRaiseHardError(STATUS_DISK_FULL, 00546 0, 00547 0, 00548 NULL, 00549 OptionOk, 00550 &Response); 00551 }

VOID CmpInitializeHiveList VOID   ) 
 

Referenced by CmpWorker().

VOID CmpLazyFlush VOID   ) 
 

Definition at line 368 of file cmworker.c.

References CML_FLOW, CMLOG, CmpLazyFlushDpc, CmpLazyFlushTimer, CmpNoWrite, CMS_IO, KeSetTimer(), LAZY_FLUSH_INTERVAL_IN_SECONDS, PAGED_CODE, and SECOND_MULT.

00374 : 00375 00376 This routine resets the registry timer to go off at a specified interval 00377 in the future (LAZY_FLUSH_INTERVAL_IN_SECONDS). 00378 00379 Arguments: 00380 00381 None 00382 00383 Return Value: 00384 00385 None. 00386 00387 --*/ 00388 00389 { 00390 LARGE_INTEGER DueTime; 00391 00392 PAGED_CODE(); 00393 CMLOG(CML_FLOW, CMS_IO) { 00394 KdPrint(("CmpLazyFlush: setting lazy flush timer\n")); 00395 } 00396 if (!CmpNoWrite) { 00397 00398 DueTime.QuadPart = Int32x32To64(LAZY_FLUSH_INTERVAL_IN_SECONDS, 00399 - SECOND_MULT); 00400 00401 // 00402 // Indicate relative time 00403 // 00404 00405 KeSetTimer(&CmpLazyFlushTimer, 00406 DueTime, 00407 &CmpLazyFlushDpc); 00408 00409 } 00410 00411 00412 }

VOID CmpLazyFlushDpcRoutine IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2
 

Definition at line 416 of file cmworker.c.

References CML_FLOW, CMLOG, CmpLazyFlushPending, CmpLazyWorkItem, CMS_IO, DelayedWorkQueue, ExQueueWorkItem(), and TRUE.

Referenced by CmpWorker().

00425 : 00426 00427 This is the DPC routine triggered by the lazy flush timer. All it does 00428 is queue a work item to an executive worker thread. The work item will 00429 do the actual lazy flush to disk. 00430 00431 Arguments: 00432 00433 Dpc - Supplies a pointer to the DPC object. 00434 00435 DeferredContext - not used 00436 00437 SystemArgument1 - not used 00438 00439 SystemArgument2 - not used 00440 00441 Return Value: 00442 00443 None. 00444 00445 --*/ 00446 00447 { 00448 CMLOG(CML_FLOW, CMS_IO) { 00449 KdPrint(("CmpLazyFlushDpc: queuing lazy flush work item\n")); 00450 } 00451 00452 if (!CmpLazyFlushPending) { 00453 CmpLazyFlushPending = TRUE; 00454 ExQueueWorkItem(&CmpLazyWorkItem, DelayedWorkQueue); 00455 } 00456 00457 }

VOID CmpLazyFlushWorker IN PVOID  Parameter  ) 
 

Definition at line 461 of file cmworker.c.

References CML_FLOW, CMLOG, CmpCannotWriteConfiguration, CmpDiskFullWarning(), CmpDoFlushAll(), CmpLazyFlush(), CmpLazyFlushPending, CmpLockRegistry(), CmpUnlockRegistry(), CMS_IO, FALSE, HvShutdownComplete, PAGED_CODE, and TRUE.

Referenced by CmpWorker().

00467 : 00468 00469 Worker routine called to do a lazy flush. Called by an executive worker 00470 thread in the system process. 00471 00472 Arguments: 00473 00474 Parameter - not used. 00475 00476 Return Value: 00477 00478 None. 00479 00480 --*/ 00481 00482 { 00483 BOOLEAN Result = TRUE; 00484 00485 PAGED_CODE(); 00486 00487 CMLOG(CML_FLOW, CMS_IO) { 00488 KdPrint(("CmpLazyFlushWorker: flushing hives\n")); 00489 } 00490 00491 CmpLockRegistry(); 00492 if (!HvShutdownComplete) { 00493 Result = CmpDoFlushAll(); 00494 } 00495 CmpLazyFlushPending = FALSE; 00496 CmpUnlockRegistry(); 00497 00498 if( CmpCannotWriteConfiguration ) { 00499 // 00500 // Disk full; system hive haven't been save at initialization 00501 // 00502 if(Result) { 00503 // 00504 // All hives were saved; No need for disk full warning anymore 00505 // 00506 CmpCannotWriteConfiguration = FALSE; 00507 } else { 00508 // 00509 // Issue another hard error (if not already displayed) and postpone a lazy flush operation 00510 // 00511 CmpDiskFullWarning(); 00512 CmpLazyFlush(); 00513 } 00514 } 00515 }

VOID CmpWorker IN PREGISTRY_COMMAND  CommandArea  ) 
 

Definition at line 115 of file cmworker.c.

References _REGISTRY_COMMAND::Allocate, ASSERT_PASSIVE_LEVEL, _REGISTRY_COMMAND::Buffer, _REGISTRY_COMMAND::Cell, CmFlushKey(), _REGISTRY_COMMAND::CmHive, CmpAddToHiveFileList(), CmpDoFileSetSize(), CmpDoFlushAll(), CmpFileRead(), CmpHiveListHead, CmpInitHiveFromFile(), CmpInitializeHiveList(), CmpLazyFlushDpc, CmpLazyFlushDpcRoutine(), CmpLazyFlushTimer, CmpLazyFlushWorker(), CmpLazyWorkItem, CmpNoWrite, CmpRemoveFromHiveFileList(), CmpWasSetupBoot, _REGISTRY_COMMAND::Command, CommandArea, ExAllocatePool, ExFreePool(), ExInitializeWorkItem, FALSE, _REGISTRY_COMMAND::FileAttributes, _CMHIVE::FileHandles, FileName, _REGISTRY_COMMAND::FileSize, _REGISTRY_COMMAND::FileType, Handle, HFILE_TYPE_MAX, HFILE_TYPE_PRIMARY, _REGISTRY_COMMAND::Hive, HiveList, HvRefreshHive(), _REGISTRY_COMMAND::ImpersonationContext, KeBugCheckEx(), KeInitializeDpc(), KeInitializeTimer(), _REGISTRY_COMMAND::NameInfoLength, _REGISTRY_COMMAND::NewName, NT_SUCCESS, NTSTATUS(), NULL, _REGISTRY_COMMAND::Offset, _REGISTRY_COMMAND::OldName, PAGED_CODE, PagedPool, PsRevertToSelf(), REG_CMD_ADD_HIVE_LIST, REG_CMD_FILE_SET_SIZE, REG_CMD_FLUSH_KEY, REG_CMD_HIVE_CLOSE, REG_CMD_HIVE_OPEN, REG_CMD_HIVE_READ, REG_CMD_INIT, REG_CMD_REFRESH_HIVE, REG_CMD_REMOVE_HIVE_LIST, REG_CMD_RENAME_HIVE, REG_CMD_SHUTDOWN, _REGISTRY_COMMAND::RegistryLockAquired, SeImpersonateClientEx(), _REGISTRY_COMMAND::SetupBoot, _REGISTRY_COMMAND::Status, Status, and ZwSetInformationFile().

Referenced by CmLoadKey(), CmpFileSetSize(), CmpLoadHiveVolatile(), CmpRefreshHive(), CmpSaveKeyByFileCopy(), CmReplaceKey(), CmShutdownSystem(), CmUnloadKey(), NtFlushKey(), and NtInitializeRegistry().

00120 : 00121 00122 Actually execute the command specified in CommandArea, and 00123 report its completion. 00124 00125 Arguments: 00126 00127 Parameter - supplies a pointer to the REGISTRY_COMMAND structure to 00128 be executed. 00129 00130 Return Value: 00131 00132 --*/ 00133 { 00134 NTSTATUS Status; 00135 PCMHIVE CmHive; 00136 IO_STATUS_BLOCK IoStatusBlock; 00137 PUNICODE_STRING FileName; 00138 ULONG i; 00139 HANDLE Handle; 00140 PFILE_RENAME_INFORMATION RenameInfo; 00141 PLIST_ENTRY p; 00142 BOOLEAN result; 00143 HANDLE NullHandle; 00144 00145 PAGED_CODE(); 00146 00147 switch (CommandArea->Command) { 00148 00149 case REG_CMD_INIT: 00150 // 00151 // Initialize lazy flush timer and DPC 00152 // 00153 KeInitializeDpc(&CmpLazyFlushDpc, 00154 CmpLazyFlushDpcRoutine, 00155 NULL); 00156 00157 KeInitializeTimer(&CmpLazyFlushTimer); 00158 00159 ExInitializeWorkItem(&CmpLazyWorkItem, CmpLazyFlushWorker, NULL); 00160 00161 CmpNoWrite = FALSE; 00162 00163 CmpWasSetupBoot = CommandArea->SetupBoot; 00164 if (CommandArea->SetupBoot == FALSE) { 00165 CmpInitializeHiveList(); 00166 } 00167 00168 // 00169 // flush dirty data to disk 00170 // 00171 CmpDoFlushAll(); 00172 break; 00173 00174 case REG_CMD_FLUSH_KEY: 00175 CommandArea->Status = 00176 CmFlushKey(CommandArea->Hive, CommandArea->Cell); 00177 break; 00178 00179 case REG_CMD_REFRESH_HIVE: 00180 // 00181 // Refresh hive to match last flushed version 00182 // 00183 HvRefreshHive(CommandArea->Hive); 00184 break; 00185 00186 case REG_CMD_FILE_SET_SIZE: 00187 CommandArea->Status = CmpDoFileSetSize( 00188 CommandArea->Hive, 00189 CommandArea->FileType, 00190 CommandArea->FileSize 00191 ); 00192 break; 00193 00194 case REG_CMD_HIVE_OPEN: 00195 00196 // 00197 // Open the file. 00198 // 00199 FileName = CommandArea->FileAttributes->ObjectName; 00200 00201 CommandArea->Status = CmpInitHiveFromFile(FileName, 00202 0, 00203 &CommandArea->CmHive, 00204 &CommandArea->Allocate, 00205 &CommandArea->RegistryLockAquired); 00206 // 00207 // NT Servers will return STATUS_ACCESS_DENIED. Netware 3.1x 00208 // servers could return any of the other error codes if the GUEST 00209 // account is disabled. 00210 // 00211 if (((CommandArea->Status == STATUS_ACCESS_DENIED) || 00212 (CommandArea->Status == STATUS_NO_SUCH_USER) || 00213 (CommandArea->Status == STATUS_WRONG_PASSWORD) || 00214 (CommandArea->Status == STATUS_ACCOUNT_EXPIRED) || 00215 (CommandArea->Status == STATUS_ACCOUNT_DISABLED) || 00216 (CommandArea->Status == STATUS_ACCOUNT_RESTRICTION)) && 00217 (CommandArea->ImpersonationContext != NULL)) { 00218 // 00219 // Impersonate the caller and try it again. This 00220 // lets us open hives on a remote machine. 00221 // 00222 Status = SeImpersonateClientEx( 00223 CommandArea->ImpersonationContext, 00224 NULL); 00225 00226 if ( NT_SUCCESS( Status ) ) { 00227 00228 CommandArea->Status = CmpInitHiveFromFile(FileName, 00229 0, 00230 &CommandArea->CmHive, 00231 &CommandArea->Allocate, 00232 &CommandArea->RegistryLockAquired); 00233 NullHandle = NULL; 00234 00235 PsRevertToSelf(); 00236 } 00237 } 00238 00239 break; 00240 00241 case REG_CMD_HIVE_CLOSE: 00242 00243 // 00244 // Close the files associated with this hive. 00245 // 00246 CmHive = CommandArea->CmHive; 00247 00248 for (i=0; i<HFILE_TYPE_MAX; i++) { 00249 if (CmHive->FileHandles[i] != NULL) { 00250 ZwClose(CmHive->FileHandles[i]); 00251 CmHive->FileHandles[i] = NULL; 00252 } 00253 } 00254 CommandArea->Status = STATUS_SUCCESS; 00255 break; 00256 00257 case REG_CMD_HIVE_READ: 00258 00259 // 00260 // Used by special case of savekey, just do a read 00261 // 00262 result = CmpFileRead( 00263 (PHHIVE)CommandArea->CmHive, 00264 CommandArea->FileType, 00265 CommandArea->Offset, 00266 CommandArea->Buffer, 00267 CommandArea->FileSize // read length 00268 ); 00269 if (result) { 00270 CommandArea->Status = STATUS_SUCCESS; 00271 } else { 00272 CommandArea->Status = STATUS_REGISTRY_IO_FAILED; 00273 } 00274 break; 00275 00276 case REG_CMD_SHUTDOWN: 00277 00278 // 00279 // shut down the registry 00280 // 00281 CmpDoFlushAll(); 00282 00283 // 00284 // close all the hive files 00285 // 00286 p=CmpHiveListHead.Flink; 00287 while (p!=&CmpHiveListHead) { 00288 CmHive = CONTAINING_RECORD(p, CMHIVE, HiveList); 00289 for (i=0; i<HFILE_TYPE_MAX; i++) { 00290 if (CmHive->FileHandles[i] != NULL) { 00291 ZwClose(CmHive->FileHandles[i]); 00292 CmHive->FileHandles[i] = NULL; 00293 } 00294 } 00295 p=p->Flink; 00296 } 00297 00298 break; 00299 00300 case REG_CMD_RENAME_HIVE: 00301 // 00302 // Rename a CmHive's primary handle 00303 // 00304 Handle = CommandArea->CmHive->FileHandles[HFILE_TYPE_PRIMARY]; 00305 if (CommandArea->OldName != NULL) { 00306 ASSERT_PASSIVE_LEVEL(); 00307 Status = ZwQueryObject(Handle, 00308 ObjectNameInformation, 00309 CommandArea->OldName, 00310 CommandArea->NameInfoLength, 00311 &CommandArea->NameInfoLength); 00312 if (!NT_SUCCESS(Status)) { 00313 CommandArea->Status = Status; 00314 break; 00315 } 00316 } 00317 00318 RenameInfo = ExAllocatePool(PagedPool, 00319 sizeof(FILE_RENAME_INFORMATION) + 00320 CommandArea->NewName->Length); 00321 if (RenameInfo == NULL) { 00322 CommandArea->Status = STATUS_INSUFFICIENT_RESOURCES; 00323 break; 00324 } 00325 RenameInfo->ReplaceIfExists = FALSE; 00326 RenameInfo->RootDirectory = NULL; 00327 RenameInfo->FileNameLength = CommandArea->NewName->Length; 00328 RtlMoveMemory(RenameInfo->FileName, 00329 CommandArea->NewName->Buffer, 00330 CommandArea->NewName->Length); 00331 00332 Status = ZwSetInformationFile(Handle, 00333 &IoStatusBlock, 00334 (PVOID)RenameInfo, 00335 sizeof(FILE_RENAME_INFORMATION) + 00336 CommandArea->NewName->Length, 00337 FileRenameInformation); 00338 ExFreePool(RenameInfo); 00339 CommandArea->Status = Status; 00340 break; 00341 00342 case REG_CMD_ADD_HIVE_LIST: 00343 // 00344 // Add a hive to the hive file list 00345 // 00346 Status = CmpAddToHiveFileList(CommandArea->CmHive); 00347 CommandArea->Status = Status; 00348 break; 00349 00350 case REG_CMD_REMOVE_HIVE_LIST: 00351 // 00352 // Remove a hive from the hive file list 00353 // 00354 CmpRemoveFromHiveFileList(CommandArea->CmHive); 00355 CommandArea->Status = STATUS_SUCCESS; 00356 break; 00357 00358 default: 00359 KeBugCheckEx(REGISTRY_ERROR,6,1,0,0); 00360 00361 } // switch 00362 00363 return; 00364 }


Variable Documentation

BOOLEAN CmpCannotWriteConfiguration
 

Definition at line 71 of file cmworker.c.

Referenced by CmpDiskFullWarning(), CmpInitializeHiveList(), and CmpLazyFlushWorker().

BOOLEAN CmpDiskFullWorkerPopupDisplayed
 

Definition at line 66 of file cmworker.c.

Referenced by CmpDiskFullWarning().

LIST_ENTRY CmpHiveListHead
 

Definition at line 26 of file cmworker.c.

KDPC CmpLazyFlushDpc
 

Definition at line 53 of file cmworker.c.

Referenced by CmpLazyFlush(), and CmpWorker().

BOOLEAN CmpLazyFlushPending = FALSE
 

Definition at line 56 of file cmworker.c.

Referenced by CmpLazyFlushDpcRoutine(), and CmpLazyFlushWorker().

KTIMER CmpLazyFlushTimer
 

Definition at line 52 of file cmworker.c.

Referenced by CmpLazyFlush(), and CmpWorker().

WORK_QUEUE_ITEM CmpLazyWorkItem
 

Definition at line 54 of file cmworker.c.

Referenced by CmpLazyFlushDpcRoutine(), and CmpWorker().

BOOLEAN CmpNoWrite
 

Definition at line 58 of file cmworker.c.

BOOLEAN CmpProfileLoaded
 

Definition at line 61 of file cmworker.c.

PKPROCESS CmpSystemProcess
 

Definition at line 51 of file cmworker.c.

Referenced by CmInitSystem1().

BOOLEAN CmpWasSetupBoot
 

Definition at line 59 of file cmworker.c.

BOOLEAN HvShutdownComplete
 

Definition at line 60 of file cmworker.c.


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