reactos/sdk/lib/cmlib/hivewrt.c

294 lines
7.5 KiB
C
Raw Normal View History

/*
* PROJECT: Registry manipulation library
* LICENSE: GPL - See COPYING in the top level directory
* COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
* Copyright 2001 - 2005 Eric Kohl
*/
#include "cmlib.h"
#define NDEBUG
#include <debug.h>
static BOOLEAN CMAPI
HvpWriteLog(
PHHIVE RegistryHive)
{
[0.4.9][PARPORT] Fix I/O port length check, [REACTOS] Logging & formatting, e.g. CORE-14388 CORE-19105 Ports back a real fix: 0.4.15-dev-1173-g ba09834c5ebdaf8d3e2a518c7fb78eaa7d89bb50 [PARPORT] Fix I/O port length check Ports back logging and formatting: 0.4.15-dev-6794-g 4eace8d762426e9ca7de0b357eb92d17299d9a9b [IPHLPAPI] Silence obsolete FIXME in GetAdaptersAddresses (#5834) CORE-14388 0.4.15-dev-6438-g b12ab486d83905275b906a800f3f8d5394df23be [MUP] Mute DPRINT1's that slow down shared folder accesses (#5545) CORE-19105 And mutes some other loggings as well for stuff, that I either never want to port back, e.g. the IMM-implementations, or which is not really helpful in the older branches: fixme:(win32ss/user/user32/misc/imm.c:446) WINNLSEnableIME is UNIMPLEMENTED! fixme:(../dll/win32/iphlpapi/address.c:290) GetAdaptersAddresses - Semi Stub: Family 2, Flags 0x0000002e, Reserved 00000000, pAdapterAddress 00000000, pOutBufLen 0143EBD4. when browsing the startmenu: fixme:(dll/win32/comctl32/toolbar.c:394) [00080086] TBSTYLE_REGISTERDROP not implemented fixme:(dll/win32/comctl32/toolbar.c:5636) [00080086] response 2045774661 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5673) [00080086] response 3225142 not handled to NM_CUSTOMDRAW (CDDS_POSTERASE) fixme:(dll/win32/comctl32/toolbar.c:5636) [000200BA] response 9 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5636) [00080086] response 2288892 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5673) [00080086] response 3291448 not handled to NM_CUSTOMDRAW (CDDS_POSTERASE) and a bigger block regarding the parallel port during booting: (drivers/parallel/parport/parport.c:127) Parport DriverEntry (drivers/parallel/parport/fdo.c:391) AddDevice(B0B50548 B0FED980) (drivers/parallel/parport/fdo.c:25) AddDeviceInternal() (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:582) IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:546) IRP_MJ_PNP / IRP_MN_START_DEVICE (drivers/parallel/parport/misc.c:42) Calling lower device B0FED980 (drivers/parallel/parport/fdo.c:116) FdoStartDevice () (drivers/parallel/parport/fdo.c:160) Port: BaseAddress 0x378 Length 8 (drivers/parallel/parport/fdo.c:160) Port: BaseAddress 0x778 Length 8 (drivers/parallel/parport/fdo.c:174) Interrupt: Level 20 Vector 55 (drivers/parallel/parport/fdo.c:195) New LPT port: Base 0x378 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:586) Unknown minor function 0x9 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:586) Unknown minor function 0x14 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:564) IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations (drivers/parallel/parport/fdo.c:351) FdoQueryBusRelations() (drivers/parallel/parport/fdo.c:233) FdoCreateRawParallelPdo() (drivers/parallel/parport/fdo.c:378) Done (drivers/parallel/parport/pdo.c:165) PdoPnp()
2023-11-05 12:37:22 +00:00
#if 0 // UNIMPLEMENTED
ULONG FileOffset;
UINT32 BufferSize;
UINT32 BitmapSize;
PUCHAR Buffer;
PUCHAR Ptr;
ULONG BlockIndex;
ULONG LastIndex;
PVOID BlockPtr;
BOOLEAN Success;
ASSERT(RegistryHive->ReadOnly == FALSE);
ASSERT(RegistryHive->BaseBlock->Length ==
RegistryHive->Storage[Stable].Length * HBLOCK_SIZE);
DPRINT("HvpWriteLog called\n");
if (RegistryHive->BaseBlock->Sequence1 !=
RegistryHive->BaseBlock->Sequence2)
{
return FALSE;
}
BitmapSize = RegistryHive->DirtyVector.SizeOfBitMap;
BufferSize = HV_LOG_HEADER_SIZE + sizeof(ULONG) + BitmapSize;
BufferSize = ROUND_UP(BufferSize, HBLOCK_SIZE);
DPRINT("Bitmap size %u buffer size: %u\n", BitmapSize, BufferSize);
Buffer = RegistryHive->Allocate(BufferSize, TRUE, TAG_CM);
if (Buffer == NULL)
{
return FALSE;
}
/* Update first update counter and CheckSum */
RegistryHive->BaseBlock->Type = HFILE_TYPE_LOG;
RegistryHive->BaseBlock->Sequence1++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Copy hive header */
RtlCopyMemory(Buffer, RegistryHive->BaseBlock, HV_LOG_HEADER_SIZE);
Ptr = Buffer + HV_LOG_HEADER_SIZE;
RtlCopyMemory(Ptr, "DIRT", 4);
Ptr += 4;
RtlCopyMemory(Ptr, RegistryHive->DirtyVector.Buffer, BitmapSize);
/* Write hive block and block bitmap */
FileOffset = 0;
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG,
&FileOffset, Buffer, BufferSize);
RegistryHive->Free(Buffer, 0);
if (!Success)
{
return FALSE;
}
/* Write dirty blocks */
FileOffset = BufferSize;
BlockIndex = 0;
while (BlockIndex < RegistryHive->Storage[Stable].Length)
{
LastIndex = BlockIndex;
BlockIndex = RtlFindSetBits(&RegistryHive->DirtyVector, 1, BlockIndex);
if (BlockIndex == ~0U || BlockIndex < LastIndex)
{
break;
}
BlockPtr = (PVOID)RegistryHive->Storage[Stable].BlockList[BlockIndex].BlockAddress;
/* Write hive block */
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG,
&FileOffset, BlockPtr, HBLOCK_SIZE);
if (!Success)
{
return FALSE;
}
BlockIndex++;
FileOffset += HBLOCK_SIZE;
}
Success = RegistryHive->FileSetSize(RegistryHive, HFILE_TYPE_LOG, FileOffset, FileOffset);
if (!Success)
{
DPRINT("FileSetSize failed\n");
return FALSE;
}
/* Flush the log file */
Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_LOG, NULL, 0);
if (!Success)
{
DPRINT("FileFlush failed\n");
}
/* Update second update counter and CheckSum */
RegistryHive->BaseBlock->Sequence2++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive header again with updated sequence counter. */
FileOffset = 0;
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_LOG,
&FileOffset, RegistryHive->BaseBlock,
HV_LOG_HEADER_SIZE);
if (!Success)
{
return FALSE;
}
/* Flush the log file */
Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_LOG, NULL, 0);
if (!Success)
{
DPRINT("FileFlush failed\n");
}
[0.4.9][PARPORT] Fix I/O port length check, [REACTOS] Logging & formatting, e.g. CORE-14388 CORE-19105 Ports back a real fix: 0.4.15-dev-1173-g ba09834c5ebdaf8d3e2a518c7fb78eaa7d89bb50 [PARPORT] Fix I/O port length check Ports back logging and formatting: 0.4.15-dev-6794-g 4eace8d762426e9ca7de0b357eb92d17299d9a9b [IPHLPAPI] Silence obsolete FIXME in GetAdaptersAddresses (#5834) CORE-14388 0.4.15-dev-6438-g b12ab486d83905275b906a800f3f8d5394df23be [MUP] Mute DPRINT1's that slow down shared folder accesses (#5545) CORE-19105 And mutes some other loggings as well for stuff, that I either never want to port back, e.g. the IMM-implementations, or which is not really helpful in the older branches: fixme:(win32ss/user/user32/misc/imm.c:446) WINNLSEnableIME is UNIMPLEMENTED! fixme:(../dll/win32/iphlpapi/address.c:290) GetAdaptersAddresses - Semi Stub: Family 2, Flags 0x0000002e, Reserved 00000000, pAdapterAddress 00000000, pOutBufLen 0143EBD4. when browsing the startmenu: fixme:(dll/win32/comctl32/toolbar.c:394) [00080086] TBSTYLE_REGISTERDROP not implemented fixme:(dll/win32/comctl32/toolbar.c:5636) [00080086] response 2045774661 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5673) [00080086] response 3225142 not handled to NM_CUSTOMDRAW (CDDS_POSTERASE) fixme:(dll/win32/comctl32/toolbar.c:5636) [000200BA] response 9 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5636) [00080086] response 2288892 not handled to NM_CUSTOMDRAW (CDDS_PREERASE) fixme:(dll/win32/comctl32/toolbar.c:5673) [00080086] response 3291448 not handled to NM_CUSTOMDRAW (CDDS_POSTERASE) and a bigger block regarding the parallel port during booting: (drivers/parallel/parport/parport.c:127) Parport DriverEntry (drivers/parallel/parport/fdo.c:391) AddDevice(B0B50548 B0FED980) (drivers/parallel/parport/fdo.c:25) AddDeviceInternal() (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:582) IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:546) IRP_MJ_PNP / IRP_MN_START_DEVICE (drivers/parallel/parport/misc.c:42) Calling lower device B0FED980 (drivers/parallel/parport/fdo.c:116) FdoStartDevice () (drivers/parallel/parport/fdo.c:160) Port: BaseAddress 0x378 Length 8 (drivers/parallel/parport/fdo.c:160) Port: BaseAddress 0x778 Length 8 (drivers/parallel/parport/fdo.c:174) Interrupt: Level 20 Vector 55 (drivers/parallel/parport/fdo.c:195) New LPT port: Base 0x378 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:586) Unknown minor function 0x9 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:586) Unknown minor function 0x14 (drivers/parallel/parport/fdo.c:513) FdoPnp() (drivers/parallel/parport/fdo.c:564) IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations (drivers/parallel/parport/fdo.c:351) FdoQueryBusRelations() (drivers/parallel/parport/fdo.c:233) FdoCreateRawParallelPdo() (drivers/parallel/parport/fdo.c:378) Done (drivers/parallel/parport/pdo.c:165) PdoPnp()
2023-11-05 12:37:22 +00:00
#endif // UNIMPLEMENTED
return TRUE;
}
static BOOLEAN CMAPI
HvpWriteHive(
PHHIVE RegistryHive,
BOOLEAN OnlyDirty)
{
ULONG FileOffset;
ULONG BlockIndex;
ULONG LastIndex;
PVOID BlockPtr;
BOOLEAN Success;
ASSERT(RegistryHive->ReadOnly == FALSE);
ASSERT(RegistryHive->BaseBlock->Length ==
RegistryHive->Storage[Stable].Length * HBLOCK_SIZE);
DPRINT("HvpWriteHive called\n");
if (RegistryHive->BaseBlock->Sequence1 !=
RegistryHive->BaseBlock->Sequence2)
{
return FALSE;
}
/* Update first update counter and CheckSum */
RegistryHive->BaseBlock->Type = HFILE_TYPE_PRIMARY;
RegistryHive->BaseBlock->Sequence1++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive block */
FileOffset = 0;
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY,
&FileOffset, RegistryHive->BaseBlock,
sizeof(HBASE_BLOCK));
if (!Success)
{
return FALSE;
}
BlockIndex = 0;
while (BlockIndex < RegistryHive->Storage[Stable].Length)
{
if (OnlyDirty)
{
LastIndex = BlockIndex;
BlockIndex = RtlFindSetBits(&RegistryHive->DirtyVector, 1, BlockIndex);
if (BlockIndex == ~0U || BlockIndex < LastIndex)
{
break;
}
}
BlockPtr = (PVOID)RegistryHive->Storage[Stable].BlockList[BlockIndex].BlockAddress;
FileOffset = (BlockIndex + 1) * HBLOCK_SIZE;
/* Write hive block */
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY,
&FileOffset, BlockPtr, HBLOCK_SIZE);
if (!Success)
{
return FALSE;
}
BlockIndex++;
}
Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_PRIMARY, NULL, 0);
if (!Success)
{
DPRINT("FileFlush failed\n");
}
/* Update second update counter and CheckSum */
RegistryHive->BaseBlock->Sequence2++;
RegistryHive->BaseBlock->CheckSum =
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
/* Write hive block */
FileOffset = 0;
Success = RegistryHive->FileWrite(RegistryHive, HFILE_TYPE_PRIMARY,
&FileOffset, RegistryHive->BaseBlock,
sizeof(HBASE_BLOCK));
if (!Success)
{
return FALSE;
}
Success = RegistryHive->FileFlush(RegistryHive, HFILE_TYPE_PRIMARY, NULL, 0);
if (!Success)
{
DPRINT("FileFlush failed\n");
}
return TRUE;
}
BOOLEAN CMAPI
HvSyncHive(
PHHIVE RegistryHive)
{
ASSERT(RegistryHive->ReadOnly == FALSE);
if (RtlFindSetBits(&RegistryHive->DirtyVector, 1, 0) == ~0U)
{
return TRUE;
}
/* Update hive header modification time */
KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp);
/* Update log file */
if (!HvpWriteLog(RegistryHive))
{
return FALSE;
}
/* Update hive file */
if (!HvpWriteHive(RegistryHive, TRUE))
{
return FALSE;
}
/* Clear dirty bitmap. */
RtlClearAllBits(&RegistryHive->DirtyVector);
RegistryHive->DirtyCount = 0;
return TRUE;
}
[NTOSKRNL/CONFIG] - Flusher lock fixes: wrong kind of lock,total mess (and the wrong kind of lock). Properly fixed throughout cmapi.c, but still missing in many other places. - Add support for detecting loading of an already loaded hive. - Start adding calls to CmpReportNotify to support registry callbacks. - Do work needed to flush notifications for a deleted node (but CmpFlushNotify not yet implemented). - Add support for adding each newly loaded hive to the HiveList key in the registry (but CmpAddHiveToFileList not yet implemented). - Add some ViewLock acquire/releases where needed. - Load the key in a faster way (Ob vs Zw) - Add checks everywhere for HvMarkCellDirty success. In future (when log/backup file is enabled), it can return FALSE (e.g. when we are out of space). - Change logic in CmpDoFlushAll to only flush a hive if it won't shrink (in the future, flushing may lead to hive shrinkage for efficiency). - Add SEH2 protection to all CmApis that may deal with user-mode data. - Add HvTrackCellRef/HvReleaseCellRef for tracking cell references in scenarios where we might need many GetCell/ReleaseCell calls. For now stubbed to only work with up to 4 static references. - Properly unlock/free in some failure paths in some of the CM APIs. - Add some missing HvReleaseCell in paths where it was missing. - Try to fix hack in enumerate key. - Fix wrong usage of KeQuerySystemTime. It was called twice to save it in 2 different places. Instead, there should be only one call, and then duplicate the value across. - Fix logic in CmpSetValueExistingData/Key. Tested with winetests and .NET framework 1.1 installation which fully completes. svn path=/trunk/; revision=46702
2010-04-03 20:22:32 +00:00
BOOLEAN
CMAPI
HvHiveWillShrink(IN PHHIVE RegistryHive)
{
/* No shrinking yet */
return FALSE;
}
BOOLEAN CMAPI
HvWriteHive(
PHHIVE RegistryHive)
{
ASSERT(RegistryHive->ReadOnly == FALSE);
/* Update hive header modification time */
KeQuerySystemTime(&RegistryHive->BaseBlock->TimeStamp);
/* Update hive file */
if (!HvpWriteHive(RegistryHive, FALSE))
{
return FALSE;
}
return TRUE;
}