[MKHIVE] Simplify CmiAddValueKey() by using CmpAddValueToList().

This commit is contained in:
Hermès Bélusca-Maïto 2018-10-14 15:14:52 +02:00
parent a965cf6e04
commit ec3c61c233
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 49 additions and 59 deletions

View file

@ -21,7 +21,8 @@
* PROJECT: ReactOS hive maker * PROJECT: ReactOS hive maker
* FILE: tools/mkhive/cmi.c * FILE: tools/mkhive/cmi.c
* PURPOSE: Registry file manipulation routines * PURPOSE: Registry file manipulation routines
* PROGRAMMER: Hervé Poussineau * PROGRAMMERS: Hervé Poussineau
* Hermès Bélusca-Maïto
*/ */
#define NDEBUG #define NDEBUG
@ -343,62 +344,17 @@ NTSTATUS
CmiAddValueKey( CmiAddValueKey(
IN PCMHIVE RegistryHive, IN PCMHIVE RegistryHive,
IN PCM_KEY_NODE Parent, IN PCM_KEY_NODE Parent,
IN ULONG ChildIndex,
IN PCUNICODE_STRING ValueName, IN PCUNICODE_STRING ValueName,
OUT PCM_KEY_VALUE *pValueCell, OUT PCM_KEY_VALUE *pValueCell,
OUT HCELL_INDEX *pValueCellOffset) OUT HCELL_INDEX *pValueCellOffset)
{ {
PCELL_DATA ValueListCell; NTSTATUS Status;
PCM_KEY_VALUE NewValueCell;
HCELL_INDEX ValueListCellOffset;
HCELL_INDEX NewValueCellOffset;
ULONG CellSize;
HSTORAGE_TYPE Storage; HSTORAGE_TYPE Storage;
PCM_KEY_VALUE NewValueCell;
#ifndef FIELD_SIZE HCELL_INDEX NewValueCellOffset;
#define FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
#endif
Storage = (Parent->Flags & KEY_IS_VOLATILE) ? Volatile : Stable; Storage = (Parent->Flags & KEY_IS_VOLATILE) ? Volatile : Stable;
if (Parent->ValueList.List == HCELL_NIL)
{
/* Allocate some room for the value list */
CellSize = FIELD_SIZE(CELL_DATA, u.KeyList) + (3 * sizeof(HCELL_INDEX));
ValueListCellOffset = HvAllocateCell(&RegistryHive->Hive, CellSize, Storage, HCELL_NIL);
if (ValueListCellOffset == HCELL_NIL)
return STATUS_INSUFFICIENT_RESOURCES;
ValueListCell = (PCELL_DATA)HvGetCell(&RegistryHive->Hive, ValueListCellOffset);
if (!ValueListCell)
{
HvFreeCell(&RegistryHive->Hive, ValueListCellOffset);
return STATUS_UNSUCCESSFUL;
}
Parent->ValueList.List = ValueListCellOffset;
}
else
{
ValueListCell = (PCELL_DATA)HvGetCell(&RegistryHive->Hive, Parent->ValueList.List);
if (!ValueListCell)
return STATUS_UNSUCCESSFUL;
CellSize = ABS_VALUE(HvGetCellSize(&RegistryHive->Hive, ValueListCell));
if (Parent->ValueList.Count >= CellSize / sizeof(HCELL_INDEX))
{
CellSize *= 2;
ValueListCellOffset = HvReallocateCell(&RegistryHive->Hive, Parent->ValueList.List, CellSize);
if (ValueListCellOffset == HCELL_NIL)
return STATUS_INSUFFICIENT_RESOURCES;
ValueListCell = (PCELL_DATA)HvGetCell(&RegistryHive->Hive, ValueListCellOffset);
if (!ValueListCell)
return STATUS_UNSUCCESSFUL;
Parent->ValueList.List = ValueListCellOffset;
}
}
NewValueCellOffset = HvAllocateCell(&RegistryHive->Hive, NewValueCellOffset = HvAllocateCell(&RegistryHive->Hive,
FIELD_OFFSET(CM_KEY_VALUE, Name) + FIELD_OFFSET(CM_KEY_VALUE, Name) +
@ -438,15 +394,35 @@ CmiAddValueKey(
NewValueCell->DataLength = 0; NewValueCell->DataLength = 0;
NewValueCell->Data = HCELL_NIL; NewValueCell->Data = HCELL_NIL;
ValueListCell->u.KeyList[Parent->ValueList.Count] = NewValueCellOffset;
Parent->ValueList.Count++;
HvMarkCellDirty(&RegistryHive->Hive, Parent->ValueList.List, FALSE);
HvMarkCellDirty(&RegistryHive->Hive, NewValueCellOffset, FALSE); HvMarkCellDirty(&RegistryHive->Hive, NewValueCellOffset, FALSE);
*pValueCell = NewValueCell; /* Check if we already have a value list */
*pValueCellOffset = NewValueCellOffset; if (Parent->ValueList.Count)
{
/* Then make sure it's valid and dirty it */
ASSERT(Parent->ValueList.List != HCELL_NIL);
HvMarkCellDirty(&RegistryHive->Hive, Parent->ValueList.List, FALSE);
}
return STATUS_SUCCESS; /* Add this value cell to the child list */
Status = CmpAddValueToList(&RegistryHive->Hive,
NewValueCellOffset,
ChildIndex,
Storage,
&Parent->ValueList);
/* If we failed, free the entire cell, including the data */
if (!NT_SUCCESS(Status))
{
/* Overwrite the status with a known one */
CmpFreeValue(&RegistryHive->Hive, NewValueCellOffset);
Status = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
*pValueCell = NewValueCell;
*pValueCellOffset = NewValueCellOffset;
}
return Status;
} }

View file

@ -50,6 +50,7 @@ NTSTATUS
CmiAddValueKey( CmiAddValueKey(
IN PCMHIVE RegistryHive, IN PCMHIVE RegistryHive,
IN PCM_KEY_NODE Parent, IN PCM_KEY_NODE Parent,
IN ULONG ChildIndex,
IN PCUNICODE_STRING ValueName, IN PCUNICODE_STRING ValueName,
OUT PCM_KEY_VALUE *pValueCell, OUT PCM_KEY_VALUE *pValueCell,
OUT HCELL_INDEX *pValueCellOffset); OUT HCELL_INDEX *pValueCellOffset);

View file

@ -557,6 +557,7 @@ RegSetValueExW(
PHHIVE Hive; PHHIVE Hive;
PCM_KEY_NODE KeyNode; // ParentNode PCM_KEY_NODE KeyNode; // ParentNode
PCM_KEY_VALUE ValueCell; PCM_KEY_VALUE ValueCell;
ULONG ChildIndex;
HCELL_INDEX CellIndex; HCELL_INDEX CellIndex;
UNICODE_STRING ValueNameString; UNICODE_STRING ValueNameString;
@ -600,12 +601,24 @@ RegSetValueExW(
/* Initialize value name string */ /* Initialize value name string */
RtlInitUnicodeString(&ValueNameString, lpValueName); RtlInitUnicodeString(&ValueNameString, lpValueName);
CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString); if (!CmpFindNameInList(Hive,
&KeyNode->ValueList,
&ValueNameString,
&ChildIndex,
&CellIndex))
{
/* Sanity check */
ASSERT(CellIndex == HCELL_NIL);
/* Fail */
// Status = STATUS_INSUFFICIENT_RESOURCES;
return ERROR_UNSUCCESSFUL;
}
if (CellIndex == HCELL_NIL) if (CellIndex == HCELL_NIL)
{ {
/* The value doesn't exist, create a new one */ /* The value doesn't exist, create a new one */
Status = CmiAddValueKey(Key->RegistryHive, Status = CmiAddValueKey(Key->RegistryHive,
KeyNode, KeyNode,
ChildIndex,
&ValueNameString, &ValueNameString,
&ValueCell, &ValueCell,
&CellIndex); &CellIndex);