mirror of
https://github.com/reactos/reactos.git
synced 2025-05-18 00:31:27 +00:00
- Merge IoGetRelatedTargetDevice implementation by Pierre Schweitzer (pierre-fsd branch), with my modifications.
svn path=/trunk/; revision=38550
This commit is contained in:
parent
7b50d4352c
commit
8935e052bf
3 changed files with 73 additions and 1 deletions
|
@ -709,6 +709,12 @@ IopDereferenceDeviceObject(
|
|||
IN BOOLEAN ForceUnload
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
IoGetRelatedTargetDevice(IN PFILE_OBJECT FileObject,
|
||||
OUT PDEVICE_OBJECT *DeviceObject
|
||||
);
|
||||
|
||||
//
|
||||
// IRP Routines
|
||||
//
|
||||
|
|
|
@ -552,6 +552,51 @@ IopStartNextPacketByKeyEx(IN PDEVICE_OBJECT DeviceObject,
|
|||
}
|
||||
}
|
||||
|
||||
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 ***********************************************************/
|
||||
|
||||
/*
|
||||
|
@ -1207,6 +1252,26 @@ IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
|
|||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
|
|
|
@ -3307,7 +3307,8 @@ NtSetVolumeInformationFile(IN HANDLE FileHandle,
|
|||
}
|
||||
|
||||
/* Get the device object */
|
||||
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
||||
Status = IoGetRelatedTargetDevice(FileObject, &DeviceObject);
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
/* Clear File Object event */
|
||||
KeClearEvent(&FileObject->Event);
|
||||
|
|
Loading…
Reference in a new issue