ReactOS 0.4.15-dev-7958-gcd0bb1a
mkhive.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <typedefs.h>
#include <cmlib.h>
#include <infhost.h>
#include "reginf.h"
#include "cmi.h"
#include "registry.h"
#include "binhive.h"
Include dependency graph for mkhive.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _countof(_Array)   (sizeof(_Array) / sizeof(_Array[0]))
 
#define STATUS_SUCCESS   ((NTSTATUS)0x00000000)
 
#define STATUS_UNSUCCESSFUL   ((NTSTATUS)0xC0000001)
 
#define STATUS_OBJECT_NAME_NOT_FOUND   ((NTSTATUS)0xC0000034)
 
#define RtlFillMemoryUlong(dst, len, val)   memset(dst, val, len)
 
#define CMLIB_HOST
 
#define OBJ_NAME_PATH_SEPARATOR   ((WCHAR)L'\\')
 
#define ABS_VALUE(V)   (((V) < 0) ? -(V) : (V))
 
#define PAGED_CODE()
 

Typedefs

typedef DWORD REGSAM
 
typedef LPVOID LPSECURITY_ATTRIBUTES
 
typedef HANDLE HKEY
 
typedef HANDLEPHKEY
 

Functions

unsigned char BitScanForward (ULONG *Index, unsigned long Mask)
 
unsigned char BitScanReverse (ULONG *const Index, unsigned long Mask)
 
VOID NTAPI RtlInitUnicodeString (IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString)
 
WCHAR NTAPI RtlUpcaseUnicodeChar (IN WCHAR Source)
 
LONG WINAPI RegQueryValueExW (IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
 
LONG WINAPI RegSetValueExW (IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL, IN ULONG Reserved, IN ULONG dwType, IN const UCHAR *lpData, IN ULONG cbData)
 
LONG WINAPI RegCloseKey (IN HKEY hKey)
 
LONG WINAPI RegDeleteKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey)
 
LONG WINAPI RegDeleteValueW (IN HKEY hKey, IN LPCWSTR lpValueName OPTIONAL)
 
LONG WINAPI RegCreateKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
 
LONG WINAPI RegOpenKeyW (IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
 

Variables

LIST_ENTRY CmiHiveListHead
 

Macro Definition Documentation

◆ _countof

#define _countof (   _Array)    (sizeof(_Array) / sizeof(_Array[0]))

Definition at line 37 of file mkhive.h.

◆ ABS_VALUE

#define ABS_VALUE (   V)    (((V) < 0) ? -(V) : (V))

Definition at line 130 of file mkhive.h.

◆ CMLIB_HOST

#define CMLIB_HOST

Definition at line 119 of file mkhive.h.

◆ OBJ_NAME_PATH_SEPARATOR

#define OBJ_NAME_PATH_SEPARATOR   ((WCHAR)L'\\')

Definition at line 127 of file mkhive.h.

◆ PAGED_CODE

#define PAGED_CODE ( )

Definition at line 131 of file mkhive.h.

◆ RtlFillMemoryUlong

#define RtlFillMemoryUlong (   dst,
  len,
  val 
)    memset(dst, val, len)

Definition at line 55 of file mkhive.h.

◆ STATUS_OBJECT_NAME_NOT_FOUND

#define STATUS_OBJECT_NAME_NOT_FOUND   ((NTSTATUS)0xC0000034)

Definition at line 49 of file mkhive.h.

◆ STATUS_SUCCESS

#define STATUS_SUCCESS   ((NTSTATUS)0x00000000)

Definition at line 43 of file mkhive.h.

◆ STATUS_UNSUCCESSFUL

#define STATUS_UNSUCCESSFUL   ((NTSTATUS)0xC0000001)

Definition at line 44 of file mkhive.h.

Typedef Documentation

◆ HKEY

typedef HANDLE HKEY

Definition at line 64 of file mkhive.h.

◆ LPSECURITY_ATTRIBUTES

Definition at line 63 of file mkhive.h.

◆ PHKEY

typedef HANDLE * PHKEY

Definition at line 64 of file mkhive.h.

◆ REGSAM

typedef DWORD REGSAM

Definition at line 62 of file mkhive.h.

Function Documentation

◆ BitScanForward()

unsigned char BitScanForward ( ULONG Index,
unsigned long  Mask 
)

Definition at line 177 of file rtl.c.

178{
179 *Index = 0;
180 while (Mask && ((Mask & 1) == 0))
181 {
182 Mask >>= 1;
183 ++(*Index);
184 }
185 return Mask ? 1 : 0;
186}
unsigned int Mask
Definition: fpcontrol.c:82
_In_ WDFCOLLECTION _In_ ULONG Index

◆ BitScanReverse()

unsigned char BitScanReverse ( ULONG *const  Index,
unsigned long  Mask 
)

Definition at line 188 of file rtl.c.

189{
190 *Index = 0;
191 while (Mask && ((Mask & (1 << 31)) == 0))
192 {
193 Mask <<= 1;
194 ++(*Index);
195 }
196 return Mask ? 1 : 0;
197}

◆ RegCloseKey()

LONG WINAPI RegCloseKey ( IN HKEY  hKey)

Definition at line 512 of file registry.c.

514{
515 PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
516
517 /* Free the object */
518 free(Key);
519
520 return ERROR_SUCCESS;
521}
#define free
Definition: debug_ros.c:5
#define ERROR_SUCCESS
Definition: deptool.c:10
FxAutoRegKey hKey
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

◆ RegCreateKeyW()

LONG WINAPI RegCreateKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
OUT PHKEY  phkResult 
)

Definition at line 524 of file registry.c.

528{
529 return RegpCreateOrOpenKey(hKey, lpSubKey, TRUE, FALSE, phkResult);
530}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static LONG RegpCreateOrOpenKey(IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
Definition: registry.c:389

◆ RegDeleteKeyW()

LONG WINAPI RegDeleteKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey 
)

Definition at line 552 of file registry.c.

555{
556 LONG rc;
558 HKEY hTargetKey;
559 PMEMKEY Key; // ParentKey
560 PHHIVE Hive;
561 PCM_KEY_NODE KeyNode; // ParentNode
563 HCELL_INDEX ParentCell;
564
565 if (lpSubKey)
566 {
567 rc = RegOpenKeyW(hKey, lpSubKey, &hTargetKey);
568 if (rc != ERROR_SUCCESS)
569 return rc;
570 }
571 else
572 {
573 hTargetKey = hKey;
574 rc = ERROR_SUCCESS;
575 }
576
577 /* Don't allow deleting the root */
578 if (hTargetKey == RootKey)
579 {
580 /* Fail */
581 rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
582 goto Quit;
583 }
584
585 /* Get the hive and node */
586 Key = HKEY_TO_MEMKEY(hTargetKey);
587 Hive = &Key->RegistryHive->Hive;
588
589 /* Get the key node */
590 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
591 if (!KeyNode)
592 {
593 rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
594 goto Quit;
595 }
596
598
599 /* Check if we don't have any children */
600 if (!(KeyNode->SubKeyCounts[Stable] + KeyNode->SubKeyCounts[Volatile]) &&
601 !(KeyNode->Flags & KEY_NO_DELETE))
602 {
603 /* Get the parent and free the cell */
604 ParentCell = KeyNode->Parent;
605 Status = CmpFreeKeyByCell(Hive, Key->KeyCellOffset, TRUE);
606 if (NT_SUCCESS(Status))
607 {
608 /* Get the parent node */
609 Parent = (PCM_KEY_NODE)HvGetCell(Hive, ParentCell);
610 if (Parent)
611 {
612 /* Make sure we're dirty */
613 ASSERT(HvIsCellDirty(Hive, ParentCell));
614
615 /* Update the write time */
616 KeQuerySystemTime(&Parent->LastWriteTime);
617
618 /* Release the cell */
619 HvReleaseCell(Hive, ParentCell);
620 }
621
622 rc = ERROR_SUCCESS;
623 }
624 else
625 {
626 /* Fail */
627 rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
628 }
629 }
630 else
631 {
632 /* Fail */
633 rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
634 }
635
636 /* Release the cell */
637 HvReleaseCell(Hive, Key->KeyCellOffset);
638
639Quit:
640 if (lpSubKey)
641 RegCloseKey(hTargetKey);
642
643 return rc;
644}
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER void *Data ACPI_OBJECT_HANDLER void **Data ACPI_STRING ACPI_OBJECT_LIST ACPI_BUFFER *ReturnObjectBuffer ACPI_DEVICE_INFO **ReturnBuffer ACPI_HANDLE Parent
Definition: acpixf.h:732
LONG NTSTATUS
Definition: precomp.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
struct _CM_KEY_NODE * PCM_KEY_NODE
#define KEY_NO_DELETE
Definition: cmdata.h:33
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
NTSTATUS NTAPI CmpFreeKeyByCell(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN Unlink)
Definition: cmkeydel.c:159
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:460
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:153
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:457
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
Status
Definition: gdiplustypes.h:25
@ Volatile
Definition: hivedata.h:128
@ Stable
Definition: hivedata.h:127
ULONG HCELL_INDEX
Definition: hivedata.h:105
#define ASSERT(a)
Definition: mode.c:44
long LONG
Definition: pedump.c:60
static PMEMKEY RootKey
Definition: registry.c:55
LONG WINAPI RegOpenKeyW(IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
Definition: registry.c:647
USHORT Signature
Definition: cmdata.h:92
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
USHORT Flags
Definition: cmdata.h:93
#define ERROR_GEN_FAILURE
Definition: winerror.h:134

◆ RegDeleteValueW()

LONG WINAPI RegDeleteValueW ( IN HKEY  hKey,
IN LPCWSTR lpValueName  OPTIONAL 
)

Definition at line 901 of file registry.c.

904{
905 LONG rc;
907 PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
908 PHHIVE Hive = &Key->RegistryHive->Hive;
909 PCM_KEY_NODE KeyNode; // ParentNode
910 PCM_KEY_VALUE ValueCell;
911 HCELL_INDEX CellIndex;
912 ULONG ChildIndex;
913 UNICODE_STRING ValueNameString;
914
915 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
916 if (!KeyNode)
917 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
918
920
921 /* Initialize value name string */
922 RtlInitUnicodeString(&ValueNameString, lpValueName);
923 if (!CmpFindNameInList(Hive,
924 &KeyNode->ValueList,
925 &ValueNameString,
926 &ChildIndex,
927 &CellIndex))
928 {
929 /* Sanity check */
930 ASSERT(CellIndex == HCELL_NIL);
931 }
932 if (CellIndex == HCELL_NIL)
933 {
934 rc = ERROR_FILE_NOT_FOUND; // STATUS_OBJECT_NAME_NOT_FOUND;
935 goto Quit;
936 }
937
938 /* We found the value, mark all relevant cells dirty */
939 HvMarkCellDirty(Hive, Key->KeyCellOffset, FALSE);
940 HvMarkCellDirty(Hive, KeyNode->ValueList.List, FALSE);
941 HvMarkCellDirty(Hive, CellIndex, FALSE);
942
943 /* Get the key value */
944 ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
945 ASSERT(ValueCell);
946
947 /* Mark it and all related data as dirty */
948 if (!CmpMarkValueDataDirty(Hive, ValueCell))
949 {
950 /* Not enough log space, fail */
951 rc = ERROR_NO_LOG_SPACE; // STATUS_NO_LOG_SPACE;
952 goto Quit;
953 }
954
955 /* Sanity checks */
956 ASSERT(HvIsCellDirty(Hive, KeyNode->ValueList.List));
957 ASSERT(HvIsCellDirty(Hive, CellIndex));
958
959 /* Remove the value from the child list */
960 Status = CmpRemoveValueFromList(Hive, ChildIndex, &KeyNode->ValueList);
961 if (!NT_SUCCESS(Status))
962 {
963 /* Set known error */
964 rc = ERROR_NO_SYSTEM_RESOURCES; // STATUS_INSUFFICIENT_RESOURCES;
965 goto Quit;
966 }
967
968 /* Remove the value and its data itself */
969 if (!CmpFreeValue(Hive, CellIndex))
970 {
971 /* Failed to free the value, fail */
972 rc = ERROR_NO_SYSTEM_RESOURCES; // STATUS_INSUFFICIENT_RESOURCES;
973 goto Quit;
974 }
975
976 /* Set the last write time */
978
979 /* Sanity check */
980 ASSERT(HvIsCellDirty(Hive, Key->KeyCellOffset));
981
982 /* Check if the value list is empty now */
983 if (!KeyNode->ValueList.Count)
984 {
985 /* Then clear key node data */
986 KeyNode->MaxValueNameLen = 0;
987 KeyNode->MaxValueDataLen = 0;
988 }
989
990 /* Change default Status to success */
991 rc = ERROR_SUCCESS;
992
993Quit:
994 /* Check if we had a value */
995 if (ValueCell)
996 {
997 /* Release the child cell */
998 ASSERT(CellIndex != HCELL_NIL);
999 HvReleaseCell(Hive, CellIndex);
1000 }
1001
1002 /* Release the parent cell, if any */
1003 if (KeyNode)
1004 HvReleaseCell(Hive, Key->KeyCellOffset);
1005
1006 return rc;
1007}
struct _CM_KEY_VALUE * PCM_KEY_VALUE
BOOLEAN NTAPI CmpMarkValueDataDirty(IN PHHIVE Hive, IN PCM_KEY_VALUE Value)
Definition: cmvalue.c:19
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
NTSTATUS NTAPI CmpRemoveValueFromList(IN PHHIVE Hive, IN ULONG Index, IN OUT PCHILD_LIST ChildList)
Definition: cmvalue.c:320
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:109
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PCUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
#define HCELL_NIL
Definition: hivedata.h:110
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
HCELL_INDEX List
Definition: cmdata.h:75
ULONG Count
Definition: cmdata.h:74
ULONG MaxValueNameLen
Definition: cmdata.h:111
ULONG MaxValueDataLen
Definition: cmdata.h:112
CHILD_LIST ValueList
Definition: cmdata.h:103
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
uint32_t ULONG
Definition: typedefs.h:59
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
#define ERROR_NO_LOG_SPACE
Definition: winerror.h:598

◆ RegOpenKeyW()

LONG WINAPI RegOpenKeyW ( IN HKEY  hKey,
IN LPCWSTR  lpSubKey,
OUT PHKEY  phkResult 
)

Definition at line 647 of file registry.c.

651{
652 return RegpCreateOrOpenKey(hKey, lpSubKey, FALSE, FALSE, phkResult);
653}

◆ RegQueryValueExW()

LONG WINAPI RegQueryValueExW ( IN HKEY  hKey,
IN LPCWSTR  lpValueName,
IN PULONG  lpReserved,
OUT PULONG lpType  OPTIONAL,
OUT PUCHAR lpData  OPTIONAL,
IN OUT PULONG lpcbData  OPTIONAL 
)

Definition at line 862 of file registry.c.

869{
871 PHHIVE Hive = &ParentKey->RegistryHive->Hive;
872 PCM_KEY_NODE KeyNode;
873 PCM_KEY_VALUE ValueCell;
874 HCELL_INDEX CellIndex;
875 UNICODE_STRING ValueNameString;
876
877 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, ParentKey->KeyCellOffset);
878 if (!KeyNode)
879 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
880
882
883 /* Initialize value name string */
884 RtlInitUnicodeString(&ValueNameString, lpValueName);
885 CellIndex = CmpFindValueByName(Hive, KeyNode, &ValueNameString);
886 if (CellIndex == HCELL_NIL)
887 return ERROR_FILE_NOT_FOUND; // STATUS_OBJECT_NAME_NOT_FOUND;
888
889 /* Get the value cell */
890 ValueCell = (PCM_KEY_VALUE)HvGetCell(Hive, CellIndex);
891 ASSERT(ValueCell != NULL);
892
893 RepGetValueData(Hive, ValueCell, lpType, lpData, lpcbData);
894
895 HvReleaseCell(Hive, CellIndex);
896
897 return ERROR_SUCCESS;
898}
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PCUNICODE_STRING Name)
Definition: cmvalue.c:99
#define NULL
Definition: types.h:112
static VOID RepGetValueData(IN PHHIVE Hive, IN PCM_KEY_VALUE ValueCell, OUT PULONG Type OPTIONAL, OUT PUCHAR Data OPTIONAL, IN OUT PULONG DataSize OPTIONAL)
Definition: registry.c:824
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69

◆ RegSetValueExW()

LONG WINAPI RegSetValueExW ( IN HKEY  hKey,
IN LPCWSTR lpValueName  OPTIONAL,
IN ULONG  Reserved,
IN ULONG  dwType,
IN const UCHAR lpData,
IN ULONG  cbData 
)

Definition at line 656 of file registry.c.

663{
664 PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
665 PHHIVE Hive;
666 PCM_KEY_NODE KeyNode; // ParentNode
667 PCM_KEY_VALUE ValueCell;
668 ULONG ChildIndex;
669 HCELL_INDEX CellIndex;
670 UNICODE_STRING ValueNameString;
671
672 PVOID DataCell;
673 ULONG DataCellSize;
675
676 if (dwType == REG_LINK)
677 {
678 PMEMKEY DestKey;
679
680 /* Special handling of registry links */
681 if (cbData != sizeof(PVOID))
682 return ERROR_INVALID_PARAMETER; // STATUS_INVALID_PARAMETER;
683
684 DestKey = HKEY_TO_MEMKEY(*(PHKEY)lpData);
685
686 // FIXME: Add additional checks for the validity of DestKey
687
688 /* Create the link in registry hive (if applicable) */
689 if (Key->RegistryHive != DestKey->RegistryHive)
690 return ERROR_SUCCESS;
691
692 DPRINT1("Save link to registry\n");
693 return ERROR_INVALID_FUNCTION; // STATUS_NOT_IMPLEMENTED;
694 }
695
696 if ((cbData & ~CM_KEY_VALUE_SPECIAL_SIZE) != cbData)
697 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
698
699 Hive = &Key->RegistryHive->Hive;
700
701 KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
702 if (!KeyNode)
703 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
704
706
707 /* Mark the parent as dirty since we are going to create a new value in it */
708 HvMarkCellDirty(Hive, Key->KeyCellOffset, FALSE);
709
710 /* Initialize value name string */
711 RtlInitUnicodeString(&ValueNameString, lpValueName);
712 if (!CmpFindNameInList(Hive,
713 &KeyNode->ValueList,
714 &ValueNameString,
715 &ChildIndex,
716 &CellIndex))
717 {
718 /* Sanity check */
719 ASSERT(CellIndex == HCELL_NIL);
720 /* Fail */
722 }
723 if (CellIndex == HCELL_NIL)
724 {
725 /* The value doesn't exist, create a new one */
726 Status = CmiAddValueKey(Key->RegistryHive,
727 KeyNode,
728 ChildIndex,
729 &ValueNameString,
730 &ValueCell,
731 &CellIndex);
732 }
733 else
734 {
735 /* The value already exists, use it. Get the value cell. */
736 ValueCell = (PCM_KEY_VALUE)HvGetCell(&Key->RegistryHive->Hive, CellIndex);
737 ASSERT(ValueCell != NULL);
739 }
740
741 // /**/HvReleaseCell(Hive, CellIndex);/**/
742
743 if (!NT_SUCCESS(Status))
744 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
745
746 /* Get size of the allocated cell (if any) */
747 if (!(ValueCell->DataLength & CM_KEY_VALUE_SPECIAL_SIZE) &&
748 (ValueCell->DataLength & ~CM_KEY_VALUE_SPECIAL_SIZE) != 0)
749 {
750 DataCell = HvGetCell(Hive, ValueCell->Data);
751 if (!DataCell)
752 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
753
754 DataCellSize = (ULONG)(-HvGetCellSize(Hive, DataCell));
755 }
756 else
757 {
758 DataCell = NULL;
759 DataCellSize = 0;
760 }
761
762 if (cbData <= sizeof(HCELL_INDEX))
763 {
764 /* If data size <= sizeof(HCELL_INDEX) then store data in the data offset */
765 DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
766 if (DataCell)
767 HvFreeCell(Hive, ValueCell->Data);
768
769 RtlCopyMemory(&ValueCell->Data, lpData, cbData);
770 ValueCell->DataLength = (cbData | CM_KEY_VALUE_SPECIAL_SIZE);
771 ValueCell->Type = dwType;
772 }
773 else
774 {
775 if (cbData > DataCellSize)
776 {
777 /* New data size is larger than the current, destroy current
778 * data block and allocate a new one. */
779 HCELL_INDEX NewOffset;
780
781 DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
782
783 NewOffset = HvAllocateCell(Hive, cbData, Stable, HCELL_NIL);
784 if (NewOffset == HCELL_NIL)
785 {
786 DPRINT("HvAllocateCell() has failed!\n");
787 return ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
788 }
789
790 if (DataCell)
791 HvFreeCell(Hive, ValueCell->Data);
792
793 ValueCell->Data = NewOffset;
794 DataCell = (PVOID)HvGetCell(Hive, NewOffset);
795 }
796
797 /* Copy new contents to cell */
798 RtlCopyMemory(DataCell, lpData, cbData);
799 ValueCell->DataLength = (cbData & ~CM_KEY_VALUE_SPECIAL_SIZE);
800 ValueCell->Type = dwType;
801 HvMarkCellDirty(Hive, ValueCell->Data, FALSE);
802 }
803
804 HvMarkCellDirty(Hive, CellIndex, FALSE);
805
806 /* Check if the maximum value name length changed, update it if so */
807 if (KeyNode->MaxValueNameLen < ValueNameString.Length)
808 KeyNode->MaxValueNameLen = ValueNameString.Length;
809
810 /* Check if the maximum data length changed, update it if so */
811 if (KeyNode->MaxValueDataLen < cbData)
812 KeyNode->MaxValueDataLen = cbData;
813
814 /* Save the write time */
816
817 return ERROR_SUCCESS;
818}
#define DPRINT1
Definition: precomp.h:8
#define CM_KEY_VALUE_SPECIAL_SIZE
Definition: cmdata.h:51
NTSTATUS CmiAddValueKey(IN PCMHIVE RegistryHive, IN PCM_KEY_NODE Parent, IN ULONG ChildIndex, IN PCUNICODE_STRING ValueName, OUT PCM_KEY_VALUE *pValueCell, OUT HCELL_INDEX *pValueCellOffset)
Definition: cmi.c:348
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:468
LONG CMAPI HvGetCellSize(PHHIVE RegistryHive, PVOID Cell)
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define REG_LINK
Definition: nt_native.h:1500
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
ULONG Type
Definition: cmdata.h:128
HCELL_INDEX Data
Definition: cmdata.h:127
ULONG DataLength
Definition: cmdata.h:126
PCMHIVE RegistryHive
Definition: registry.c:48
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

◆ RtlInitUnicodeString()

VOID NTAPI RtlInitUnicodeString ( IN OUT PUNICODE_STRING  DestinationString,
IN PCWSTR  SourceString 
)

Definition at line 641 of file unicode.c.

644{
645 SIZE_T Size;
646 CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(UNICODE_NULL); // an even number
647
648 if (SourceString)
649 {
650 Size = wcslen(SourceString) * sizeof(WCHAR);
651 __analysis_assume(Size <= MaxSize);
652
653 if (Size > MaxSize)
654 Size = MaxSize;
657 }
658 else
659 {
662 }
663
665}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define __analysis_assume(expr)
Definition: ms_sal.h:2893
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1910
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1909
#define UNICODE_NULL
#define CONST
Definition: pedump.c:81
unsigned short USHORT
Definition: pedump.c:61
unsigned short Length
Definition: sprintf.c:451
void * Buffer
Definition: sprintf.c:453
unsigned short MaximumLength
Definition: sprintf.c:452
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define MAXUSHORT
Definition: typedefs.h:83
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by RtlAppendUnicodeToString().

◆ RtlUpcaseUnicodeChar()

WCHAR NTAPI RtlUpcaseUnicodeChar ( IN WCHAR  Source)

Definition at line 721 of file nls.c.

722{
724
726}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define PAGED_CODE_RTL()
Definition: rtlp.h:16
WCHAR NTAPI RtlpUpcaseUnicodeChar(IN WCHAR Source)
Definition: nls.c:695

Referenced by RtlCompareUnicodeString().

Variable Documentation

◆ CmiHiveListHead

LIST_ENTRY CmiHiveListHead
extern

Definition at line 385 of file registry.c.

Referenced by CmiInitializeHive(), and RegInitializeRegistry().