[ros-diffs] [fireball] 31560: - Use IopOpenRegistryKeyEx() to reduce code size and improve readability.

fireball at svn.reactos.org fireball at svn.reactos.org
Wed Jan 2 14:33:41 CET 2008


Author: fireball
Date: Wed Jan  2 16:33:40 2008
New Revision: 31560

URL: http://svn.reactos.org/svn/reactos?rev=31560&view=rev
Log:
- Use IopOpenRegistryKeyEx() to reduce code size and improve readability.

Modified:
    trunk/reactos/ntoskrnl/io/iomgr/driver.c
    trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
    trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c

Modified: trunk/reactos/ntoskrnl/io/iomgr/driver.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/driver.c?rev=31560&r1=31559&r2=31560&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/driver.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/driver.c Wed Jan  2 16:33:40 2008
@@ -270,7 +270,6 @@
    ULONG ServiceStart;
    UNICODE_STRING ServiceImagePath, CCSName;
    NTSTATUS Status;
-   OBJECT_ATTRIBUTES ObjectAttributes;
    HANDLE CCSKey, ServiceKey;
 
    DPRINT("IopLoadServiceModule(%wZ, 0x%p)\n", ServiceName, ModuleObject);
@@ -282,13 +281,7 @@
    /* Open CurrentControlSet */
    RtlInitUnicodeString(&CCSName,
                         L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services");
-   InitializeObjectAttributes(&ObjectAttributes,
-       &CCSName,
-       OBJ_CASE_INSENSITIVE,
-       NULL,
-       NULL);
-   Status = ZwOpenKey(&CCSKey, KEY_READ, &ObjectAttributes);
-
+   Status = IopOpenRegistryKeyEx(&CCSKey, NULL, &CCSName, KEY_READ);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
@@ -296,12 +289,7 @@
    }
 
    /* Open service key */
-   InitializeObjectAttributes(&ObjectAttributes,
-       ServiceName,
-       OBJ_CASE_INSENSITIVE,
-       CCSKey,
-       NULL);
-   Status = ZwOpenKey(&ServiceKey, KEY_READ, &ObjectAttributes);
+   Status = IopOpenRegistryKeyEx(&ServiceKey, CCSKey, ServiceName, KEY_READ);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
@@ -572,7 +560,6 @@
    BOOLEAN Lower)
 {
    RTL_QUERY_REGISTRY_TABLE QueryTable[2] = {{0}};
-   OBJECT_ATTRIBUTES ObjectAttributes;
    UNICODE_STRING Class;
    WCHAR ClassBuffer[40];
    UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT);
@@ -580,13 +567,8 @@
    NTSTATUS Status;
 
    /* Open enumeration root key */
-   InitializeObjectAttributes(&ObjectAttributes,
-       &EnumRoot,
-       OBJ_CASE_INSENSITIVE,
-       NULL,
-       NULL);
-   Status = ZwOpenKey(&EnumRootKey, KEY_READ, &ObjectAttributes);
-
+   Status = IopOpenRegistryKeyEx(&EnumRootKey, NULL,
+       &EnumRoot, KEY_READ);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
@@ -594,12 +576,8 @@
    }
 
    /* Open subkey */
-   InitializeObjectAttributes(&ObjectAttributes,
-       &DeviceNode->InstancePath,
-       OBJ_CASE_INSENSITIVE,
-       EnumRootKey,
-       NULL);
-   Status = ZwOpenKey(&SubKey, KEY_READ, &ObjectAttributes);
+   Status = IopOpenRegistryKeyEx(&SubKey, EnumRootKey,
+       &DeviceNode->InstancePath, KEY_READ);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
@@ -649,17 +627,12 @@
    /*
     * Load the class filter driver
     */
-
    if (NT_SUCCESS(Status))
    {
        UNICODE_STRING ControlClass = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class");
-       InitializeObjectAttributes(&ObjectAttributes,
-           &ControlClass,
-           OBJ_CASE_INSENSITIVE,
-           NULL,
-           NULL);
-       Status = ZwOpenKey(&EnumRootKey, KEY_READ, &ObjectAttributes);
-
+
+       Status = IopOpenRegistryKeyEx(&EnumRootKey, NULL,
+           &ControlClass, KEY_READ);
        if (!NT_SUCCESS(Status))
        {
            DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);
@@ -667,12 +640,8 @@
        }
 
        /* Open subkey */
-       InitializeObjectAttributes(&ObjectAttributes,
-           &Class,
-           OBJ_CASE_INSENSITIVE,
-           EnumRootKey,
-           NULL);
-       Status = ZwOpenKey(&SubKey, KEY_READ, &ObjectAttributes);
+       Status = IopOpenRegistryKeyEx(&SubKey, EnumRootKey,
+           &Class, KEY_READ);
        if (!NT_SUCCESS(Status))
        {
            DPRINT1("ZwOpenKey() failed with Status %08X\n", Status);

Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c?rev=31560&r1=31559&r2=31560&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c Wed Jan  2 16:33:40 2008
@@ -408,7 +408,6 @@
             LPCWSTR RegistryPropertyName;
             UNICODE_STRING EnumRoot = RTL_CONSTANT_STRING(ENUM_ROOT);
             UNICODE_STRING ValueName;
-            OBJECT_ATTRIBUTES ObjectAttributes;
             KEY_VALUE_PARTIAL_INFORMATION *ValueInformation;
             ULONG ValueInformationLength;
             HANDLE KeyHandle, EnumRootHandle;
@@ -445,9 +444,8 @@
             DPRINT("Registry property %S\n", RegistryPropertyName);
 
             /* Open Enum key */
-            InitializeObjectAttributes(&ObjectAttributes, &EnumRoot,
-                OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
-            Status = ZwOpenKey(&EnumRootHandle, 0, &ObjectAttributes);
+            Status = IopOpenRegistryKeyEx(&EnumRootHandle, NULL,
+                &EnumRoot, KEY_READ);
             if (!NT_SUCCESS(Status))
             {
                 DPRINT1("Error opening ENUM_ROOT, Status=0x%08x\n", Status);
@@ -455,13 +453,12 @@
             }
 
             /* Open instance key */
-            InitializeObjectAttributes(&ObjectAttributes, &DeviceNode->InstancePath,
-                OBJ_CASE_INSENSITIVE, EnumRootHandle, NULL);
-
-            Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
+            Status = IopOpenRegistryKeyEx(&KeyHandle, EnumRootHandle,
+                &DeviceNode->InstancePath, KEY_READ);
             if (!NT_SUCCESS(Status))
             {
                 DPRINT1("Error opening InstancePath, Status=0x%08x\n", Status);
+                ZwClose(EnumRootHandle);
                 return Status;
             }
 
@@ -686,10 +683,7 @@
    /*
     * Open the base key.
     */
-
-   InitializeObjectAttributes(&ObjectAttributes, &KeyName,
-                              OBJ_CASE_INSENSITIVE, NULL, NULL);
-   Status = ZwOpenKey(DevInstRegKey, DesiredAccess, &ObjectAttributes);
+   Status = IopOpenRegistryKeyEx(DevInstRegKey, NULL, &KeyName, DesiredAccess);
    if (!NT_SUCCESS(Status))
    {
       DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
@@ -1100,14 +1094,7 @@
     *Handle = NULL;
 
     /* Open root key for device instances */
-    InitializeObjectAttributes(&ObjectAttributes,
-                               &EnumU,
-                               OBJ_CASE_INSENSITIVE,
-                               NULL,
-                               NULL);
-    Status = ZwOpenKey(&hParent,
-                       KEY_CREATE_SUB_KEY,
-                       &ObjectAttributes);
+    Status = IopOpenRegistryKeyEx(&hParent, NULL, &EnumU, KEY_CREATE_SUB_KEY);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
@@ -1611,7 +1598,6 @@
    UNICODE_STRING KeyName;
    UNICODE_STRING KeyValue;
    UNICODE_STRING ValueName;
-   OBJECT_ATTRIBUTES ObjectAttributes;
    HANDLE hKey = NULL;
    ULONG crc32;
    NTSTATUS Status;
@@ -1643,8 +1629,7 @@
    wcscpy(KeyNameBuffer, L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum\\");
    wcscat(KeyNameBuffer, DeviceNode->Parent->InstancePath.Buffer);
    RtlInitUnicodeString(&KeyName, KeyNameBuffer);
-   InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
-   Status = ZwOpenKey(&hKey, KEY_QUERY_VALUE | KEY_SET_VALUE, &ObjectAttributes);
+   Status = IopOpenRegistryKeyEx(&hKey, NULL, &KeyName, KEY_QUERY_VALUE | KEY_SET_VALUE);
    if (!NT_SUCCESS(Status))
       goto cleanup;
    RtlInitUnicodeString(&ValueName, L"ParentIdPrefix");
@@ -2704,8 +2689,7 @@
 
     if (RelativePath)
     {
-        InitializeObjectAttributes(&ObjectAttributes, RelativePath, OBJ_KERNEL_HANDLE, hBaseKey, NULL);
-        Status = ZwOpenKey(&hDevicesKey, KEY_ENUMERATE_SUB_KEYS, &ObjectAttributes);
+        Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS);
         if (!NT_SUCCESS(Status))
         {
             DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
@@ -2759,11 +2743,9 @@
       /* Open device key */
       DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength;
       DeviceName.Buffer = pDeviceInformation->Name;
-      InitializeObjectAttributes(&ObjectAttributes, &DeviceName, OBJ_KERNEL_HANDLE, hDevicesKey, NULL);
-      Status = ZwOpenKey(
-         &hDeviceKey,
-         KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0),
-         &ObjectAttributes);
+
+      Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName,
+          KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0));
       if (!NT_SUCCESS(Status))
       {
          DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
@@ -3281,8 +3263,7 @@
    }
    else
    {
-        InitializeObjectAttributes(&ObjectAttributes, &MultiKeyPathU, OBJ_KERNEL_HANDLE, NULL, NULL);
-        Status = ZwOpenKey(&hEnum, KEY_ENUMERATE_SUB_KEYS, &ObjectAttributes);
+        Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS);
         if (!NT_SUCCESS(Status))
         {
             /* Nothing to do, don't return with an error status */

Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c?rev=31560&r1=31559&r2=31560&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnproot.c Wed Jan  2 16:33:40 2008
@@ -280,7 +280,6 @@
     IN PDEVICE_OBJECT DeviceObject)
 {
     PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
-    OBJECT_ATTRIBUTES ObjectAttributes;
     PKEY_BASIC_INFORMATION KeyInfo = NULL, SubKeyInfo = NULL;
     UNICODE_STRING LegacyU = RTL_CONSTANT_STRING(L"LEGACY_");
     UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\" REGSTR_PATH_SYSTEMENUM L"\\" REGSTR_KEY_ROOTENUM);
@@ -318,17 +317,10 @@
         goto cleanup;
     }
 
-    InitializeObjectAttributes(
-        &ObjectAttributes,
-        &KeyName,
-        OBJ_CASE_INSENSITIVE,
-        NULL,
-        NULL);
-
-    Status = ZwOpenKey(&KeyHandle, KEY_ENUMERATE_SUB_KEYS, &ObjectAttributes);
+    Status = IopOpenRegistryKeyEx(&KeyHandle, NULL, &KeyName, KEY_ENUMERATE_SUB_KEYS);
     if (!NT_SUCCESS(Status))
     {
-        DPRINT("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyName, Status);
+        DPRINT("IopOpenRegistryKeyEx(%wZ) failed with status 0x%08lx\n", &KeyName, Status);
         goto cleanup;
     }
 
@@ -370,16 +362,10 @@
         }
 
         /* Open the key */
-        InitializeObjectAttributes(
-            &ObjectAttributes,
-            &SubKeyName,
-            0, /* Attributes */
-            KeyHandle,
-            NULL); /* Security descriptor */
-        Status = ZwOpenKey(&SubKeyHandle, KEY_ENUMERATE_SUB_KEYS, &ObjectAttributes);
+        Status = IopOpenRegistryKeyEx(&SubKeyHandle, KeyHandle, &SubKeyName, KEY_ENUMERATE_SUB_KEYS);
         if (!NT_SUCCESS(Status))
         {
-            DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
+            DPRINT("IopOpenRegistryKeyEx() failed with status 0x%08lx\n", Status);
             break;
         }
 
@@ -438,16 +424,10 @@
                 }
 
                 /* Open registry key to fill other informations */
-                InitializeObjectAttributes(
-                    &ObjectAttributes,
-                    &Device->InstanceID,
-                    0, /* Attributes */
-                    SubKeyHandle,
-                    NULL); /* Security descriptor */
-                Status = ZwOpenKey(&DeviceKeyHandle, KEY_READ, &ObjectAttributes);
+                Status = IopOpenRegistryKeyEx(&DeviceKeyHandle, SubKeyHandle, &Device->InstanceID, KEY_READ);
                 if (!NT_SUCCESS(Status))
                 {
-                    DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
+                    DPRINT("IopOpenRegistryKeyEx() failed with status 0x%08lx\n", Status);
                     break;
                 }
 




More information about the Ros-diffs mailing list