[NTOS:IO]
authorHervé Poussineau <hpoussin@reactos.org>
Wed, 10 Sep 2014 16:05:44 +0000 (16:05 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Wed, 10 Sep 2014 16:05:44 +0000 (16:05 +0000)
- Support creating new registry keys when registering new interfaces
- IoSetDeviceInterfaceState: do not try to parse symbolic link name, as symbolic link name is enough to open the right object
- IoSetDeviceInterfaceState: send the notification on the right interface when registering interfaces on devices already having an interface

svn path=/trunk/; revision=64108

reactos/ntoskrnl/io/iomgr/deviface.c

index f43d70f..73b87ea 100644 (file)
@@ -95,9 +95,13 @@ OpenRegistryHandlesFromSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                                ClassesKey,
                                NULL);
-    Status = ZwOpenKey(GuidKeyRealP,
-                       DesiredAccess | KEY_ENUMERATE_SUB_KEYS,
-                       &ObjectAttributes);
+    Status = ZwCreateKey(GuidKeyRealP,
+                         DesiredAccess | KEY_ENUMERATE_SUB_KEYS,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         REG_OPTION_NON_VOLATILE,
+                         NULL);
     ZwClose(ClassesKey);
     if (!NT_SUCCESS(Status))
     {
@@ -142,9 +146,13 @@ OpenRegistryHandlesFromSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                                *GuidKeyRealP,
                                NULL);
-    Status = ZwOpenKey(DeviceKeyRealP,
-                       DesiredAccess | KEY_ENUMERATE_SUB_KEYS,
-                       &ObjectAttributes);
+    Status = ZwCreateKey(DeviceKeyRealP,
+                         DesiredAccess | KEY_ENUMERATE_SUB_KEYS,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         REG_OPTION_NON_VOLATILE,
+                         NULL);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to open %wZ%wZ\\%wZ\n", &BaseKeyU, &GuidString, &SubKeyName);
@@ -156,9 +164,13 @@ OpenRegistryHandlesFromSymbolicLink(IN PUNICODE_STRING SymbolicLinkName,
                                OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
                                *DeviceKeyRealP,
                                NULL);
-    Status = ZwOpenKey(InstanceKeyRealP,
-                       DesiredAccess,
-                       &ObjectAttributes);
+    Status = ZwCreateKey(InstanceKeyRealP,
+                         DesiredAccess,
+                         &ObjectAttributes,
+                         0,
+                         NULL,
+                         REG_OPTION_NON_VOLATILE,
+                         NULL);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Failed to open %wZ%wZ\\%wZ%\\%wZ (%x)\n", &BaseKeyU, &GuidString, &SubKeyName, &ReferenceString, Status);
@@ -1237,7 +1249,6 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
     PDEVICE_OBJECT PhysicalDeviceObject;
     PFILE_OBJECT FileObject;
     UNICODE_STRING GuidString;
-    UNICODE_STRING SymLink;
     PWCHAR StartPosition;
     PWCHAR EndPosition;
     NTSTATUS Status;
@@ -1255,8 +1266,8 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
 
     /* Symbolic link name is \??\ACPI#PNP0501#1#{GUID}\ReferenceString */
     /* Get GUID from SymbolicLinkName */
-    StartPosition = wcschr(SymbolicLinkName->Buffer, L'{');
-    EndPosition = wcschr(SymbolicLinkName->Buffer, L'}');
+    StartPosition = wcsrchr(SymbolicLinkName->Buffer, L'{');
+    EndPosition = wcsrchr(SymbolicLinkName->Buffer, L'}');
     if (!StartPosition ||!EndPosition || StartPosition > EndPosition)
     {
         DPRINT1("IoSetDeviceInterfaceState() returning STATUS_INVALID_PARAMETER_1\n");
@@ -1265,10 +1276,6 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
     GuidString.Buffer = StartPosition;
     GuidString.MaximumLength = GuidString.Length = (USHORT)((ULONG_PTR)(EndPosition + 1) - (ULONG_PTR)StartPosition);
 
-    SymLink.Buffer = SymbolicLinkName->Buffer;
-    SymLink.MaximumLength = SymLink.Length = (USHORT)((ULONG_PTR)(EndPosition + 1) - (ULONG_PTR)SymLink.Buffer);
-    DPRINT("IoSetDeviceInterfaceState('%wZ', %u)\n", SymbolicLinkName, Enable);
-
     Status = OpenRegistryHandlesFromSymbolicLink(SymbolicLinkName,
                                                  KEY_CREATE_SUB_KEY,
                                                  NULL,
@@ -1315,7 +1322,7 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
 
     /* Get pointer to the PDO */
     Status = IoGetDeviceObjectPointer(
-        &SymLink,
+        SymbolicLinkName,
         0, /* DesiredAccess */
         &FileObject,
         &PhysicalDeviceObject);