You can/should use IopGetDeviceNode instead of the ugly (but necessary) triple-casting you have.
*DeviceNode = (PDEVICE_NODE)((PEXTENDED_DEVOBJ_EXTENSION)DeviceRelations->Objects[0]-
DeviceObjectExtension)->DeviceNode;
Also, I believe there is a bug in Nt/IoQuery/SetVolumeInformation -- we call IoGetRelatedDeviceObject instead of IoGetRelatedTargetDevice, because the function was missing.
Good job!
On 3-Jan-09, at 4:35 AM, pschweitzer@svn.reactos.org wrote:
Author: pschweitzer Date: Sat Jan 3 03:35:10 2009 New Revision: 38523
URL: http://svn.reactos.org/svn/reactos?rev=38523&view=rev Log:
- Implemeted Io(p)GetRelatedTargetDevice
- Fixed FsRtlNotifyVolumeEvent
Modified: branches/pierre-fsd/ntoskrnl/fsrtl/pnp.c branches/pierre-fsd/ntoskrnl/include/internal/io.h branches/pierre-fsd/ntoskrnl/io/iomgr/device.c
Modified: branches/pierre-fsd/ntoskrnl/fsrtl/pnp.c URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/fsrtl/pnp.c?... = = = = = = = = ====================================================================== --- branches/pierre-fsd/ntoskrnl/fsrtl/pnp.c [iso-8859-1] (original) +++ branches/pierre-fsd/ntoskrnl/fsrtl/pnp.c [iso-8859-1] Sat Jan 3 03:35:10 2009 @@ -43,8 +43,7 @@ PDEVICE_OBJECT DeviceObject = NULL; TARGET_DEVICE_CUSTOM_NOTIFICATION Notification;
- /* FIXME: We should call IoGetRelatedTargetDevice here */
- DeviceObject = IoGetRelatedDeviceObject(FileObject);
- IoGetRelatedTargetDevice(FileObject, &DeviceObject); if (DeviceObject) { Notification.Version = 1;
Modified: branches/pierre-fsd/ntoskrnl/include/internal/io.h URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/include/inte... = = = = = = = = ====================================================================== --- branches/pierre-fsd/ntoskrnl/include/internal/io.h [iso-8859-1] (original) +++ branches/pierre-fsd/ntoskrnl/include/internal/io.h [iso-8859-1] Sat Jan 3 03:35:10 2009 @@ -669,6 +669,12 @@ IN BOOLEAN ForceUnload );
+NTSTATUS +NTAPI +IoGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
OUT PDEVICE_OBJECT *DeviceObject+);
// // IRP Routines //
Modified: branches/pierre-fsd/ntoskrnl/io/iomgr/device.c URL: http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/io/iomgr/dev... = = = = = = = = ====================================================================== --- branches/pierre-fsd/ntoskrnl/io/iomgr/device.c [iso-8859-1] (original) +++ branches/pierre-fsd/ntoskrnl/io/iomgr/device.c [iso-8859-1] Sat Jan 3 03:35:10 2009 @@ -552,6 +552,49 @@ } }
+NTSTATUS +NTAPI +IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
OUT PDEVICE_NODE *DeviceNode)+{
- NTSTATUS Status;
- IO_STACK_LOCATION Stack;
- 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;- }
- /* Call the driver to query all the relations (IRP_MJ_PNP) */
- Status = IopInitiatePnpIrp(DeviceObject, &IoStatusBlock,
IRP_MN_QUERY_DEVICE_RELATIONS,&Stack);
- if (NT_SUCCESS(Status))
- {
DeviceRelations =(PDEVICE_RELATIONS)IoStatusBlock.Information;
ASSERT(DeviceRelations);ASSERT(DeviceRelations->Count == 1);/* We finally get the device node */*DeviceNode = (PDEVICE_NODE)((PEXTENDED_DEVOBJ_EXTENSION)DeviceRelations->Objects[0]-
DeviceObjectExtension)->DeviceNode;
if (!*DeviceNode){Status = STATUS_NO_SUCH_DEVICE;}/* Free the DEVICE_RELATIONS structure, we don't need itanymore */
ExFreePool(DeviceRelations);- }
- return Status;
+}
/* PUBLIC FUNCTIONS ***********************************************************/
/* @@ -1205,6 +1248,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;
- /* We call the internal function to do all the work */
- Status = IopGetRelatedTargetDevice(FileObject, &DeviceNode);
- if (NT_SUCCESS(Status) && DeviceNode)
- {
*DeviceObject = DeviceNode->PhysicalDeviceObject;- }
- return Status;
}
/*
Best regards, Alex Ionescu