ReactOS  0.4.14-dev-41-g31d7680
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 }
static const UCHAR Index[8]
Definition: usbohci.c:18

◆ 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 }
static const UCHAR Index[8]
Definition: usbohci.c:18

◆ 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 ERROR_SUCCESS
Definition: deptool.c:10
#define free
Definition: debug_ros.c:5
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by check_user_privs(), CopyKey(), CreateUserHive(), delete_key(), fetch_machine_component(), fetch_machine_product(), fetch_user_component(), fetch_user_product(), get_key_value(), msi_check_product_patches(), MSI_EnumComponentQualifiers(), msi_get_patch_state(), msi_reg_set_subkey_val(), MsiEnumClientsW(), MsiEnumFeaturesW(), MsiEnumPatchesW(), MsiEnumRelatedProductsW(), MSIREG_DeleteClassesUpgradeCodesKey(), MSIREG_DeleteLocalClassesFeaturesKey(), MSIREG_DeleteLocalClassesProductKey(), MSIREG_DeleteProductKey(), MSIREG_DeleteUpgradeCodesKey(), MSIREG_DeleteUserDataComponentKey(), MSIREG_DeleteUserDataPatchKey(), MSIREG_DeleteUserDataProductKey(), RegDeleteKeyW(), RegInitializeRegistry(), registry_read_filelist(), registry_read_formatopts(), registry_read_maximized(), registry_read_options(), registry_read_winrect(), registry_set_filelist(), registry_set_formatopts(), registry_set_options(), test_classesroot(), test_classesroot_enum(), test_classesroot_mask(), test_delete_key_value(), test_deleted_key(), test_enum_value(), test_perflib_key(), test_redirection(), test_reg_close_key(), test_reg_copy_tree(), test_reg_create_key(), test_reg_delete_key(), test_reg_delete_tree(), test_reg_load_key(), test_reg_open_key(), test_reg_query_info(), test_reg_query_value(), test_regconnectregistry(), test_RegNotifyChangeKeyValue(), test_RegOpenCurrentUser(), test_RegQueryValueExPerformanceData(), test_set_value(), test_string_termination(), and test_symlinks().

◆ 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
static LONG RegpCreateOrOpenKey(IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
Definition: registry.c:389

Referenced by msi_reg_set_subkey_val(), MSIREG_OpenUserComponentsKey(), MSIREG_OpenUserPatchesKey(), MSIREG_OpenUserUpgradeCodesKey(), and RegInitializeRegistry().

◆ 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 
639 Quit:
640  if (lpSubKey)
641  RegCloseKey(hTargetKey);
642 
643  return rc;
644 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
LONG WINAPI RegCloseKey(IN HKEY hKey)
Definition: registry.c:512
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG Key
Definition: fatprocs.h:2697
static PMEMKEY RootKey
Definition: registry.c:55
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical 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:722
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
LONG WINAPI RegOpenKeyW(IN HKEY hKey, IN LPCWSTR lpSubKey, OUT PHKEY phkResult)
Definition: registry.c:647
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HCELL_INDEX Parent
Definition: cmdata.h:96
ULONG HCELL_INDEX
Definition: hivedata.h:80
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
USHORT Signature
Definition: cmdata.h:92
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KEY_NO_DELETE
Definition: cmdata.h:33
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI CmpFreeKeyByCell(IN PHHIVE Hive, IN HCELL_INDEX Cell, IN BOOLEAN Unlink)
Definition: cmkeydel.c:159
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
USHORT Flags
Definition: cmdata.h:93
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by do_reg_operation().

◆ 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 */
977  KeQuerySystemTime(&KeyNode->LastWriteTime);
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 
993 Quit:
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 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
BOOLEAN CMAPI HvIsCellDirty(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: hivecell.c:126
HCELL_INDEX List
Definition: cmdata.h:75
#define ERROR_SUCCESS
Definition: deptool.c:10
ULONG MaxValueNameLen
Definition: cmdata.h:111
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
#define ERROR_NO_SYSTEM_RESOURCES
Definition: winerror.h:931
NTSTATUS NTAPI CmpRemoveValueFromList(IN PHHIVE Hive, IN ULONG Index, IN OUT PCHILD_LIST ChildList)
Definition: cmvalue.c:320
BOOLEAN NTAPI CmpFreeValue(IN PHHIVE Hive, IN HCELL_INDEX Cell)
Definition: cmvalue.c:73
long LONG
Definition: pedump.c:60
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
struct _CM_KEY_NODE * PCM_KEY_NODE
#define ERROR_NO_LOG_SPACE
Definition: winerror.h:598
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
CHILD_LIST ValueList
Definition: cmdata.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
ULONG Count
Definition: cmdata.h:74
Status
Definition: gdiplustypes.h:24
struct _CM_KEY_VALUE * PCM_KEY_VALUE
ULONG MaxValueDataLen
Definition: cmdata.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51
BOOLEAN NTAPI CmpMarkValueDataDirty(IN PHHIVE Hive, IN PCM_KEY_VALUE Value)
Definition: cmvalue.c:19

Referenced by do_reg_operation().

◆ 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 }
static LONG RegpCreateOrOpenKey(IN HKEY hParentKey, IN PCWSTR KeyName, IN BOOL AllowCreation, IN BOOL Volatile, OUT PHKEY Key)
Definition: registry.c:389

Referenced by MSIREG_OpenUserComponentsKey(), MSIREG_OpenUserPatchesKey(), MSIREG_OpenUserUpgradeCodesKey(), and RegDeleteKeyW().

◆ 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 {
870  PMEMKEY ParentKey = HKEY_TO_MEMKEY(hKey);
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 = 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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define HvReleaseCell(h, c)
Definition: cmlib.h:390
#define HCELL_NIL
Definition: hivedata.h:85
HCELL_INDEX KeyCellOffset
Definition: registry.c:47
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
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
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
HHIVE Hive
Definition: cm.h:393
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
HCELL_INDEX NTAPI CmpFindValueByName(IN PHHIVE Hive, IN PCM_KEY_NODE KeyNode, IN PUNICODE_STRING Name)
Definition: cmvalue.c:99
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
PCMHIVE RegistryHive
Definition: registry.c:48
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by _test_hkey_main_Value_W(), do_reg_operation(), msi_reg_get_val_dword(), msi_reg_get_val_str(), QueryRegistryValue(), registry_read_filelist(), registry_read_formatopts(), registry_read_maximized(), registry_read_winrect(), RegQueryDword(), RegQueryValueWithAlloc(), test_RegQueryValueExPerformanceData(), and test_set_value().

◆ 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 = 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 */
815  KeQuerySystemTime(&KeyNode->LastWriteTime);
816 
817  return ERROR_SUCCESS;
818 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
HCELL_INDEX Data
Definition: cmdata.h:127
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
ULONG MaxValueNameLen
Definition: cmdata.h:111
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
LONG NTSTATUS
Definition: precomp.h:26
#define HCELL_NIL
Definition: hivedata.h:85
static PVOID
Definition: registry.c:44
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define CM_KEY_VALUE_SPECIAL_SIZE
Definition: cm.h:73
ULONG DataLength
Definition: cmdata.h:126
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
PVOID CMAPI HvGetCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:67
smooth NULL
Definition: ftsmooth.c:416
struct _CM_KEY_NODE * PCM_KEY_NODE
void DPRINT(...)
Definition: polytest.cpp:61
CHILD_LIST ValueList
Definition: cmdata.h:103
#define REG_LINK
Definition: nt_native.h:1500
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG HCELL_INDEX
Definition: hivedata.h:80
USHORT Signature
Definition: cmdata.h:92
PCMHIVE RegistryHive
Definition: registry.c:48
BOOLEAN CMAPI HvMarkCellDirty(PHHIVE RegistryHive, HCELL_INDEX CellOffset, BOOLEAN HoldingLock)
Definition: hivecell.c:100
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CMAPI HvFreeCell(PHHIVE RegistryHive, HCELL_INDEX CellOffset)
Definition: hivecell.c:441
LONG CMAPI HvGetCellSize(PHHIVE RegistryHive, PVOID Cell)
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
Status
Definition: gdiplustypes.h:24
ULONG Type
Definition: cmdata.h:128
ULONG MaxValueDataLen
Definition: cmdata.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define HKEY_TO_MEMKEY(hKey)
Definition: registry.c:51

Referenced by CopyKey(), msi_reg_set_val_dword(), msi_reg_set_val_multi_str(), msi_reg_set_val_str(), registry_set_filelist(), registry_set_formatopts(), registry_set_options(), test_enum_value(), and test_set_value().

◆ RtlInitUnicodeString()

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

Definition at line 630 of file unicode.c.

633 {
634  SIZE_T Size;
635  CONST SIZE_T MaxSize = (MAXUSHORT & ~1) - sizeof(UNICODE_NULL); // an even number
636 
637  if (SourceString)
638  {
639  Size = wcslen(SourceString) * sizeof(WCHAR);
640  __analysis_assume(Size <= MaxSize);
641 
642  if (Size > MaxSize)
643  Size = MaxSize;
646  }
647  else
648  {
651  }
652 
654 }
unsigned short Length
Definition: sprintf.c:451
uint16_t * PWCHAR
Definition: typedefs.h:54
void * Buffer
Definition: sprintf.c:453
#define UNICODE_NULL
#define __analysis_assume(expr)
Definition: sal.h:2893
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1869
__wchar_t WCHAR
Definition: xmlstorage.h:180
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1869
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned short USHORT
Definition: pedump.c:61
#define MAXUSHORT
Definition: typedefs.h:81
unsigned short MaximumLength
Definition: sprintf.c:452
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define CONST
Definition: pedump.c:81

Referenced by RtlAppendUnicodeToString(), and WdmlibRtlIsNtDdiVersionAvailable().

◆ RtlUpcaseUnicodeChar()

WCHAR NTAPI RtlUpcaseUnicodeChar ( IN WCHAR  Source)

Definition at line 741 of file nls.c.

742 {
743  PAGED_CODE_RTL();
744 
746 }
#define PAGED_CODE_RTL()
Definition: rtlp.h:16
WCHAR NTAPI RtlpUpcaseUnicodeChar(IN WCHAR Source)
Definition: nls.c:715
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by RtlCompareUnicodeString().

Variable Documentation

◆ CmiHiveListHead

LIST_ENTRY CmiHiveListHead

Definition at line 385 of file registry.c.

Referenced by CmiInitializeHive(), and RegInitializeRegistry().