ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

static LONG RegpOpenOrCreateKey ( IN HKEY  hParentKey,
IN PCWSTR  KeyName,
IN BOOL  AllowCreation,
OUT PHKEY  Key 
) [static]

Definition at line 96 of file registry.c.

Referenced by RegCreateKeyW(), and RegOpenKeyW().

{
    PWSTR LocalKeyName;
    PWSTR End;
    UNICODE_STRING KeyString;
    NTSTATUS Status;
    MEMKEY ParentKey;
    MEMKEY CurrentKey;
    PLIST_ENTRY Ptr;
    PCM_KEY_NODE SubKeyCell;
    HCELL_INDEX BlockOffset;

    DPRINT("RegpCreateOpenKey('%S')\n", KeyName);

    if (*KeyName == L'\\')
    {
        KeyName++;
        ParentKey = RootKey;
    }
    else if (hParentKey == NULL)
    {
        ParentKey = RootKey;
    }
    else
    {
        ParentKey = HKEY_TO_MEMKEY(RootKey);
    }

    LocalKeyName = (PWSTR)KeyName;
    for (;;)
    {
        End = (PWSTR)strchrW(LocalKeyName, '\\');
        if (End)
        {
            KeyString.Buffer = LocalKeyName;
            KeyString.Length = KeyString.MaximumLength =
                (USHORT)((ULONG_PTR)End - (ULONG_PTR)LocalKeyName);
        }
        else
            RtlInitUnicodeString(&KeyString, LocalKeyName);

        /* Redirect from 'CurrentControlSet' to 'ControlSet001' */
        if (!strncmpW(LocalKeyName, L"CurrentControlSet", 17) &&
            ParentKey->NameSize == 12 &&
            !memcmp(ParentKey->Name, L"SYSTEM", 12))
            RtlInitUnicodeString(&KeyString, L"ControlSet001");

        /* Check subkey in memory structure */
        Ptr = ParentKey->SubKeyList.Flink;
        while (Ptr != &ParentKey->SubKeyList)
        {
            CurrentKey = CONTAINING_RECORD(Ptr, KEY, KeyList);
            if (CurrentKey->NameSize == KeyString.Length
             && memcmp(CurrentKey->Name, KeyString.Buffer, KeyString.Length) == 0)
            {
                goto nextsubkey;
            }

            Ptr = Ptr->Flink;
        }

        Status = CmiScanForSubKey(
            ParentKey->RegistryHive,
            ParentKey->KeyCell,
            &KeyString,
            OBJ_CASE_INSENSITIVE,
            &SubKeyCell,
            &BlockOffset);
        if (AllowCreation && Status == STATUS_OBJECT_NAME_NOT_FOUND)
        {
            Status = CmiAddSubKey(
                ParentKey->RegistryHive,
                ParentKey->KeyCell,
                ParentKey->KeyCellOffset,
                &KeyString,
                0,
                &SubKeyCell,
                &BlockOffset);
        }
        if (!NT_SUCCESS(Status))
            return ERROR_UNSUCCESSFUL;

        /* Now, SubKeyCell/BlockOffset are valid */
        CurrentKey = CreateInMemoryStructure(
            ParentKey->RegistryHive,
            BlockOffset,
            &KeyString);
        if (!CurrentKey)
            return ERROR_OUTOFMEMORY;

        /* Add CurrentKey in ParentKey */
        InsertTailList(&ParentKey->SubKeyList, &CurrentKey->KeyList);
        ParentKey->SubKeyCount++;

nextsubkey:
        ParentKey = CurrentKey;
        if (End)
            LocalKeyName = End + 1;
        else
            break;
    }

    *Key = MEMKEY_TO_HKEY(ParentKey);

    return ERROR_SUCCESS;
}

Generated on Mon May 28 2012 04:41:57 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.