From 1b5368050352b74c71102a590ae5f5efe37e9155 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 18 Mar 2003 20:36:17 +0000 Subject: [PATCH] Fixed an off-by-one error in CmiPopulateHive(). Removed dead code from NtFlushKey(). Changed some debugging messages. svn path=/trunk/; revision=4340 --- reactos/ntoskrnl/cm/ntfunc.c | 198 +-------------------------------- reactos/ntoskrnl/cm/regfile.c | 30 ++--- reactos/ntoskrnl/cm/registry.c | 4 +- 3 files changed, 19 insertions(+), 213 deletions(-) diff --git a/reactos/ntoskrnl/cm/ntfunc.c b/reactos/ntoskrnl/cm/ntfunc.c index d228a1b82f2..5ed606d7256 100644 --- a/reactos/ntoskrnl/cm/ntfunc.c +++ b/reactos/ntoskrnl/cm/ntfunc.c @@ -690,18 +690,8 @@ NtFlushKey(IN HANDLE KeyHandle) NTSTATUS Status; PKEY_OBJECT KeyObject; PREGISTRY_HIVE RegistryHive; -#if 0 - WCHAR LogName[MAX_PATH]; - UNICODE_STRING TmpFileName; - HANDLE FileHandle; -// HANDLE FileHandleLog; - OBJECT_ATTRIBUTES ObjectAttributes; - LARGE_INTEGER fileOffset; - DWORD * pEntDword; - ULONG i; -#endif - DPRINT("KeyHandle %x\n", KeyHandle); + DPRINT("NtFlushKey (KeyHandle %lx) called\n", KeyHandle); /* Verify that the handle is valid and is a registry key */ Status = ObReferenceObjectByHandle(KeyHandle, @@ -733,192 +723,6 @@ NtFlushKey(IN HANDLE KeyHandle) Status = STATUS_SUCCESS; } - -#if 0 - /* Then write changed blocks in .log */ - wcscpy(LogName,RegistryHive->Filename.Buffer); - wcscat(LogName,L".log"); - RtlInitUnicodeString (&TmpFileName, LogName); - InitializeObjectAttributes(&ObjectAttributes, - &TmpFileName, - 0, - NULL, - NULL); - -/* BEGIN FIXME : actually (26 November 200) vfatfs.sys can't create new files - so we can't create log file - Status = ZwCreateFile(&FileHandleLog, - FILE_ALL_ACCESS, - &ObjectAttributes, - NULL, - 0, - FILE_ATTRIBUTE_NORMAL, - 0, - FILE_SUPERSEDE, - 0, - NULL, - 0); - - if (!NT_SUCCESS(Status)) - { - ObDereferenceObject(KeyObject); - return Status; - } - - Status = ZwWriteFile(FileHandleLog, - 0, - 0, - 0, - 0, - RegistryHive->HiveHeader, - sizeof(HIVE_HEADER), - 0, - 0); - - if (!NT_SUCCESS(Status)) - { - ZwClose(FileHandleLog); - ObDereferenceObject(KeyObject); - return Status; - } - - for (i = 0; i < RegistryHive->BlockListSize ; i++) - { - if ( RegistryHive->BlockList[i]->DateModified.dwHighDateTime - > RegistryHive->HiveHeader->DateModified.dwHighDateTime - || (RegistryHive->BlockList[i]->DateModified.dwHighDateTime - == RegistryHive->HiveHeader->DateModified.dwHighDateTime - && RegistryHive->BlockList[i]->DateModified.dwLowDateTime - > RegistryHive->HiveHeader->DateModified.dwLowDateTime - ) - ) - - Status = ZwWriteFile(FileHandleLog, - 0, - 0, - 0, - 0, - RegistryHive->BlockList[i], - RegistryHive->BlockList[i]->BlockSize , - 0, - 0); - - if (!NT_SUCCESS(Status)) - { - ZwClose(FileHandleLog); - ObDereferenceObject(KeyObject); - return Status; - } - } - ZwClose(FileHandleLog); -END FIXME*/ - - /* Update header of RegistryHive with Version >VersionOld */ - /* this allow recover if system crash while updating hove file */ - InitializeObjectAttributes(&ObjectAttributes, - &RegistryHive->Filename, - 0, - NULL, - NULL); - - Status = NtOpenFile(&FileHandle, - FILE_ALL_ACCESS, - &ObjectAttributes, - NULL, - 0, - FILE_SYNCHRONOUS_IO_NONALERT); - if (!NT_SUCCESS(Status)) - { - ExReleaseResourceLite(&KeyObject->RegistryHive->HiveResource); - ObDereferenceObject(KeyObject); - return Status; - } - - RegistryHive->HiveHeader->Version++; - - Status = ZwWriteFile(FileHandle, - 0, - 0, - 0, - 0, - RegistryHive->HiveHeader, - sizeof(HIVE_HEADER), - 0, - 0); - if (!NT_SUCCESS(Status)) - { - ZwClose(FileHandle); - ExReleaseResourceLite(&KeyObject->RegistryHive->HiveResource); - ObDereferenceObject(KeyObject); - return Status; - } - - /* Update changed blocks in file */ - fileOffset.u.HighPart = 0; - for (i = 0; i < RegistryHive->BlockListSize ; i++) - { - if (RegistryHive->BlockList[i]->DateModified.dwHighDateTime - > RegistryHive->HiveHeader->DateModified.dwHighDateTime - || (RegistryHive->BlockList[i]->DateModified.dwHighDateTime - == RegistryHive->HiveHeader->DateModified.dwHighDateTime - && RegistryHive->BlockList[i]->DateModified.dwLowDateTime - > RegistryHive->HiveHeader->DateModified.dwLowDateTime)) - { - fileOffset.u.LowPart = RegistryHive->BlockList[i]->BlockOffset+4096; - Status = NtWriteFile(FileHandle, - 0, - 0, - 0, - 0, - RegistryHive->BlockList[i], - RegistryHive->BlockList[i]->BlockSize, - &fileOffset, - 0); - if (!NT_SUCCESS(Status)) - { - ZwClose(FileHandle); - ExReleaseResourceLite(&KeyObject->RegistryHive->HiveResource); - ObDereferenceObject(KeyObject); - return(Status); - } - } - } - - /* Change version in header */ - RegistryHive->HiveHeader->VersionOld = RegistryHive->HiveHeader->Version; - ZwQuerySystemTime((PTIME) &RegistryHive->HiveHeader->DateModified); - - /* Calculate checksum */ - RegistryHive->HiveHeader->Checksum = 0; - pEntDword = (DWORD *) RegistryHive->HiveHeader; - for (i = 0; i < 127 ; i++) - { - RegistryHive->HiveHeader->Checksum ^= pEntDword[i]; - } - - /* Write new header */ - fileOffset.u.LowPart = 0; - Status = ZwWriteFile(FileHandle, - 0, - 0, - 0, - 0, - RegistryHive->HiveHeader, - sizeof(HIVE_HEADER), - &fileOffset, - 0); - - if (!NT_SUCCESS(Status)) - { - ZwClose(FileHandle); - ExReleaseResourceLite(&KeyObject->RegistryHive->HiveResource); - ObDereferenceObject(KeyObject); - return Status; - } - - ZwClose(FileHandle); -#endif - ExReleaseResourceLite(&RegistryHive->HiveResource); ObDereferenceObject(KeyObject); diff --git a/reactos/ntoskrnl/cm/regfile.c b/reactos/ntoskrnl/cm/regfile.c index b2ae84d5bb9..670e1e815b9 100644 --- a/reactos/ntoskrnl/cm/regfile.c +++ b/reactos/ntoskrnl/cm/regfile.c @@ -394,13 +394,13 @@ CmiPopulateHive(HANDLE FileHandle) // Add free blocks so we don't need to expand // the file for a while - for (i = 0; i < 50; i++) + for (i = 1; i < 50; i++) { // Block offset of this bin - BinCell->BlockOffset = (2 + i) * REG_BLOCK_SIZE; + BinCell->BlockOffset = i * REG_BLOCK_SIZE; FileOffset.u.HighPart = 0; - FileOffset.u.LowPart = (2 + i) * REG_BLOCK_SIZE; + FileOffset.u.LowPart = (i + 1) * REG_BLOCK_SIZE; Status = NtWriteFile(FileHandle, NULL, @@ -1194,7 +1194,7 @@ CmiStartLogUpdate(PREGISTRY_HIVE RegistryHive) PVOID BlockPtr; NTSTATUS Status; - DPRINT1("CmiStartLogUpdate() called\n"); + DPRINT("CmiStartLogUpdate() called\n"); BitmapSize = ROUND_UP(RegistryHive->BlockListSize, sizeof(ULONG) * 8) / 8; BufferSize = sizeof(HIVE_HEADER) + @@ -3276,7 +3276,7 @@ CmiMarkBlockDirty(PREGISTRY_HIVE RegistryHive, if (IsVolatileHive(RegistryHive)) return; - DPRINT1("CmiMarkBlockDirty(Offset 0x%lx)\n", (ULONG)BlockOffset); + DPRINT("CmiMarkBlockDirty(Offset 0x%lx)\n", (ULONG)BlockOffset); BlockNumber = (ULONG)BlockOffset / 4096; @@ -3290,11 +3290,11 @@ CmiMarkBlockDirty(PREGISTRY_HIVE RegistryHive, BlockCount = (ROUND_UP(BlockOffset + CellSize, 4096) - ROUND_DOWN(BlockOffset, 4096)) / 4096; - DPRINT1(" BlockNumber %lu Size %lu (%s) BlockCount %lu\n", - BlockNumber, - CellSize, - (Cell->CellSize < 0) ? "used" : "free", - BlockCount); + DPRINT(" BlockNumber %lu Size %lu (%s) BlockCount %lu\n", + BlockNumber, + CellSize, + (Cell->CellSize < 0) ? "used" : "free", + BlockCount); RegistryHive->HiveDirty = TRUE; RtlSetBits(&RegistryHive->DirtyBitMap, @@ -3314,7 +3314,7 @@ CmiMarkBinDirty(PREGISTRY_HIVE RegistryHive, if (IsVolatileHive(RegistryHive)) return; - DPRINT1("CmiMarkBinDirty(Offset 0x%lx)\n", (ULONG)BinOffset); + DPRINT("CmiMarkBinDirty(Offset 0x%lx)\n", (ULONG)BinOffset); BlockNumber = (ULONG)BinOffset / 4096; @@ -3322,10 +3322,10 @@ CmiMarkBinDirty(PREGISTRY_HIVE RegistryHive, BlockCount = Bin->BlockSize / 4096; - DPRINT1(" BlockNumber %lu Size %lu BlockCount %lu\n", - BlockNumber, - Bin->BlockSize, - BlockCount); + DPRINT(" BlockNumber %lu Size %lu BlockCount %lu\n", + BlockNumber, + Bin->BlockSize, + BlockCount); RegistryHive->HiveDirty = TRUE; RtlSetBits(&RegistryHive->DirtyBitMap, diff --git a/reactos/ntoskrnl/cm/registry.c b/reactos/ntoskrnl/cm/registry.c index 16a07fa8a5d..de9b2989637 100644 --- a/reactos/ntoskrnl/cm/registry.c +++ b/reactos/ntoskrnl/cm/registry.c @@ -1,4 +1,4 @@ -/* $Id: registry.c,v 1.86 2003/03/08 19:26:12 ekohl Exp $ +/* $Id: registry.c,v 1.87 2003/03/18 20:36:17 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -1106,6 +1106,8 @@ CmiHiveSyncRoutine(PVOID DeferredContext) DPRINT("DeferredContext %x\n", DeferredContext); ExFreePool(DeferredContext); + + DPRINT1("CmiHiveSyncRoutine() done\n"); }