- Use IoGetDevObjExtension and STDCALL->NTAPI.

- Fix some bugs in IoGetRelatedDeviceObject: We should make sure that FO_DIRECT_DEVICE_OPEN isn't set when reading from the VPB's DO, otherwise we return the FO's DO directly. Also check for attachment before trying to get any attached device.

svn path=/trunk/; revision=22741
This commit is contained in:
Alex Ionescu 2006-07-01 17:51:45 +00:00
parent 28692c3bed
commit fcb5f1cfb6

View file

@ -954,11 +954,11 @@ IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
* @implemented * @implemented
*/ */
PDEVICE_OBJECT PDEVICE_OBJECT
STDCALL NTAPI
IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject) IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
{ {
/* Return the attached Device */ /* Return the attached Device */
return (((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->AttachedTo); return IoGetDevObjExtension(DeviceObject)->AttachedTo;
} }
/* /*
@ -968,7 +968,7 @@ IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject)
* @implemented * @implemented
*/ */
NTSTATUS NTSTATUS
STDCALL NTAPI
IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject, OUT PFILE_OBJECT *FileObject,
@ -986,8 +986,8 @@ IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName,
* @implemented * @implemented
*/ */
NTSTATUS NTSTATUS
STDCALL NTAPI
IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject, IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject,
OUT PDEVICE_OBJECT *DiskDeviceObject) OUT PDEVICE_OBJECT *DiskDeviceObject)
{ {
PEXTENDED_DEVOBJ_EXTENSION DeviceExtension; PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
@ -1001,14 +1001,18 @@ IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject,
IoAcquireVpbSpinLock(&OldIrql); IoAcquireVpbSpinLock(&OldIrql);
/* Get the Device Extension */ /* Get the Device Extension */
DeviceExtension = (PEXTENDED_DEVOBJ_EXTENSION)FileSystemDeviceObject->DeviceObjectExtension; DeviceExtension = IoGetDevObjExtension(FileSystemDeviceObject);
/* Make sure this one has a VPB too */ /* Make sure this one has a VPB too */
Vpb = DeviceExtension->Vpb; Vpb = DeviceExtension->Vpb;
if (!Vpb) return STATUS_INVALID_PARAMETER; if (!Vpb) return STATUS_INVALID_PARAMETER;
/* Make sure someone it's mounted */ /* Make sure that it's mounted */
if ((!Vpb->ReferenceCount) || (Vpb->Flags & VPB_MOUNTED)) return STATUS_VOLUME_DISMOUNTED; if ((!Vpb->ReferenceCount) || (Vpb->Flags & VPB_MOUNTED))
{
/* It's not, so return failure */
return STATUS_VOLUME_DISMOUNTED;
}
/* Return the Disk Device Object */ /* Return the Disk Device Object */
*DiskDeviceObject = Vpb->RealDevice; *DiskDeviceObject = Vpb->RealDevice;
@ -1022,13 +1026,14 @@ IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject,
* @implemented * @implemented
*/ */
PDEVICE_OBJECT PDEVICE_OBJECT
STDCALL NTAPI
IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject) IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
{ {
PEXTENDED_DEVOBJ_EXTENSION DeviceExtension = (PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension; PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
PDEVICE_OBJECT LowerDeviceObject = NULL; PDEVICE_OBJECT LowerDeviceObject = NULL;
/* Make sure it's not getting deleted */ /* Make sure it's not getting deleted */
DeviceExtension = IoGetDevObjExtension(DeviceObject);
if (DeviceExtension->ExtensionFlags & (DOE_UNLOAD_PENDING | if (DeviceExtension->ExtensionFlags & (DOE_UNLOAD_PENDING |
DOE_DELETE_PENDING | DOE_DELETE_PENDING |
DOE_REMOVE_PENDING | DOE_REMOVE_PENDING |
@ -1055,29 +1060,40 @@ IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject)
* @implemented * @implemented
*/ */
PDEVICE_OBJECT PDEVICE_OBJECT
STDCALL NTAPI
IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject) IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
{ {
PDEVICE_OBJECT DeviceObject = FileObject->DeviceObject; PDEVICE_OBJECT DeviceObject = FileObject->DeviceObject;
/* Get logical volume mounted on a physical/virtual/logical device */ /* Check if we have a VPB with a device object */
if (FileObject->Vpb && FileObject->Vpb->DeviceObject) if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
{ {
/* Then use the DO from the VPB */
ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN));
DeviceObject = FileObject->Vpb->DeviceObject; DeviceObject = FileObject->Vpb->DeviceObject;
} }
else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
/* (FileObject->DeviceObject->Vpb) &&
* Check if file object has an associated device object mounted by some (FileObject->DeviceObject->Vpb->DeviceObject))
* other file system.
*/
if (FileObject->DeviceObject->Vpb &&
FileObject->DeviceObject->Vpb->DeviceObject)
{ {
/* The disk device actually has a VPB, so get the DO from there */
DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject; DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
} }
else
{
/* Otherwise, this was a direct open */
DeviceObject = FileObject->DeviceObject;
}
/* Return the highest attached device */ /* Check if we were attached */
return IoGetAttachedDevice(DeviceObject); if (DeviceObject->AttachedDevice)
{
/* Return the highest attached device */
DeviceObject = IoGetAttachedDevice(DeviceObject);
}
/* Return the DO we found */
return DeviceObject;
} }
/* /*