From 8eef55e4c9f6fcb5ec925a49accdb9c86030030f Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Wed, 2 Jan 2008 13:33:40 +0000 Subject: [PATCH] - Use IopOpenRegistryKeyEx() to reduce code size and improve readability. svn path=/trunk/; revision=31560 --- reactos/ntoskrnl/io/iomgr/driver.c | 51 ++++++---------------------- reactos/ntoskrnl/io/pnpmgr/pnpmgr.c | 45 +++++++----------------- reactos/ntoskrnl/io/pnpmgr/pnproot.c | 32 ++++------------- 3 files changed, 29 insertions(+), 99 deletions(-) diff --git a/reactos/ntoskrnl/io/iomgr/driver.c b/reactos/ntoskrnl/io/iomgr/driver.c index c733acf3326..e6afac5766f 100644 --- a/reactos/ntoskrnl/io/iomgr/driver.c +++ b/reactos/ntoskrnl/io/iomgr/driver.c @@ -270,7 +270,6 @@ IopLoadServiceModule( 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 @@ IopLoadServiceModule( /* 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 @@ IopLoadServiceModule( } /* 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 @@ IopAttachFilterDrivers( 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 @@ IopAttachFilterDrivers( 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 @@ IopAttachFilterDrivers( } /* 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 @@ IopAttachFilterDrivers( /* * 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 @@ IopAttachFilterDrivers( } /* 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); diff --git a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c index 5a70dacaeef..c77c5c073e5 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -408,7 +408,6 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, 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 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, 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 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, } /* 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 @@ IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, /* * 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 @@ IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, *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 @@ IopGetParentIdPrefix(PDEVICE_NODE DeviceNode, UNICODE_STRING KeyName; UNICODE_STRING KeyValue; UNICODE_STRING ValueName; - OBJECT_ATTRIBUTES ObjectAttributes; HANDLE hKey = NULL; ULONG crc32; NTSTATUS Status; @@ -1643,8 +1629,7 @@ IopGetParentIdPrefix(PDEVICE_NODE DeviceNode, 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 @@ IopEnumerateDetectedDevices( 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 @@ IopEnumerateDetectedDevices( /* 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 @@ IopUpdateRootKey(VOID) } 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 */ diff --git a/reactos/ntoskrnl/io/pnpmgr/pnproot.c b/reactos/ntoskrnl/io/pnpmgr/pnproot.c index cd3bfb83857..a19b30415a9 100644 --- a/reactos/ntoskrnl/io/pnpmgr/pnproot.c +++ b/reactos/ntoskrnl/io/pnpmgr/pnproot.c @@ -280,7 +280,6 @@ EnumerateDevices( 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 @@ EnumerateDevices( 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 @@ EnumerateDevices( } /* 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 @@ EnumerateDevices( } /* 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; }