[ros-diffs] [fireball] 38550: - Merge IoGetRelatedTargetDevice implementation by Pierre Schweitzer (pierre-fsd branch), with my modifications.

fireball at svn.reactos.org fireball at svn.reactos.org
Sun Jan 4 10:35:36 CET 2009


Author: fireball
Date: Sun Jan  4 03:35:35 2009
New Revision: 38550

URL: http://svn.reactos.org/svn/reactos?rev=38550&view=rev
Log:
- Merge IoGetRelatedTargetDevice implementation by Pierre Schweitzer (pierre-fsd branch), with my modifications.

Modified:
    trunk/reactos/ntoskrnl/include/internal/io.h
    trunk/reactos/ntoskrnl/io/iomgr/device.c
    trunk/reactos/ntoskrnl/io/iomgr/iofunc.c

Modified: trunk/reactos/ntoskrnl/include/internal/io.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/io.h?rev=38550&r1=38549&r2=38550&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/io.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/io.h [iso-8859-1] Sun Jan  4 03:35:35 2009
@@ -709,6 +709,12 @@
     IN BOOLEAN ForceUnload
 );
 
+NTSTATUS
+NTAPI
+IoGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
+                         OUT PDEVICE_OBJECT *DeviceObject
+);
+
 //
 // IRP Routines
 //

Modified: trunk/reactos/ntoskrnl/io/iomgr/device.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/device.c?rev=38550&r1=38549&r2=38550&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/device.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/device.c [iso-8859-1] Sun Jan  4 03:35:35 2009
@@ -552,6 +552,51 @@
     }
 }
 
+NTSTATUS
+NTAPI
+IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
+                          OUT PDEVICE_NODE *DeviceNode)
+{
+    NTSTATUS Status;
+    IO_STACK_LOCATION Stack = {0};
+    IO_STATUS_BLOCK IoStatusBlock;
+    PDEVICE_RELATIONS DeviceRelations;
+    PDEVICE_OBJECT DeviceObject = NULL;
+
+    ASSERT(FileObject);
+
+    /* Get DeviceObject related to given FileObject */
+    DeviceObject = IoGetRelatedDeviceObject(FileObject);
+    if (!DeviceObject) return STATUS_NO_SUCH_DEVICE;
+
+    /* Define input parameters */
+    Stack.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
+    Stack.FileObject = FileObject;
+
+    /* Call the driver to query all relations (IRP_MJ_PNP) */
+    Status = IopInitiatePnpIrp(DeviceObject,
+                               &IoStatusBlock,
+                               IRP_MN_QUERY_DEVICE_RELATIONS,
+                               &Stack);
+    if (!NT_SUCCESS(Status)) return Status;
+
+    /* Get returned pointer to DEVICE_RELATIONS */
+    DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
+
+    /* Make sure it's not NULL and contains only one object */
+    ASSERT(DeviceRelations);
+    ASSERT(DeviceRelations->Count == 1);
+
+    /* Finally get the device node */
+    *DeviceNode = IopGetDeviceNode(DeviceRelations->Objects[0]);
+    if (!*DeviceNode) Status = STATUS_NO_SUCH_DEVICE;
+
+    /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
+    ExFreePool(DeviceRelations);
+
+    return Status;
+}
+
 /* PUBLIC FUNCTIONS ***********************************************************/
 
 /*
@@ -1205,6 +1250,26 @@
 
     /* Return the DO we found */
     return DeviceObject;
+}
+
+/*
+ * @implemented
+ */
+NTSTATUS
+NTAPI
+IoGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
+                         OUT PDEVICE_OBJECT *DeviceObject)
+{
+    NTSTATUS Status;
+    PDEVICE_NODE DeviceNode = NULL;
+
+    /* Call the internal helper function */
+    Status = IopGetRelatedTargetDevice(FileObject, &DeviceNode);
+    if (NT_SUCCESS(Status) && DeviceNode)
+    {
+        *DeviceObject = DeviceNode->PhysicalDeviceObject;
+    }
+    return Status;
 }
 
 /*

Modified: trunk/reactos/ntoskrnl/io/iomgr/iofunc.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/iofunc.c?rev=38550&r1=38549&r2=38550&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/iofunc.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/iofunc.c [iso-8859-1] Sun Jan  4 03:35:35 2009
@@ -3307,7 +3307,8 @@
     }
 
     /* Get the device object */
-    DeviceObject = IoGetRelatedDeviceObject(FileObject);
+    Status = IoGetRelatedTargetDevice(FileObject, &DeviceObject);
+    if (!NT_SUCCESS(Status)) return Status;
 
     /* Clear File Object event */
     KeClearEvent(&FileObject->Event);



More information about the Ros-diffs mailing list