阅读:1245回复:3
解释解释这个函数, 尤其其注释
不要英文翻译阿, 我的英文还可以; 而是里面的各种情况到底是什么样一种情景, 或者哪里有相关资料?
PDEVICE_OBJECT IoGetRelatedDeviceObject( IN PFILE_OBJECT FileObject ) /*++ Routine Description: This routine returns a pointer to the actual device object than an I/O Request Packet (IRP) should be given to based on the specified file object. N.B. - Callers of this function must ensure no device object is attaching or detaching from this stack for the duration of this call. This is because the database lock is *not* held! Arguments: FileObject - Pointer to the file object representing the open file. Return Value: The return value is a pointer to the device object for the driver to whom the request is to be given. --*/ { PDEVICE_OBJECT deviceObject; // // If the file object was taken out against the mounted file system, it // will have a Vpb. Traverse it to get to the DeviceObject. Note that in // this case we should never follow FileObject->DeviceObject, as that // mapping may be invalid after a forced dismount. // if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL) { ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN)); deviceObject = FileObject->Vpb->DeviceObject; // // If a driver opened a disk device using direct device open and // later on it uses IoGetRelatedTargetDeviceObject to find the // device object it wants to send an IRP then it should not get the // filesystem device object. This is so that if the device object is in the // process of being mounted then vpb is not stable. // } else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) && FileObject->DeviceObject->Vpb != NULL && FileObject->DeviceObject->Vpb->DeviceObject != NULL) { deviceObject = FileObject->DeviceObject->Vpb->DeviceObject; // // This is a direct open against the device stack (and there is no mounted // file system to strain the IRPs through). // } else { deviceObject = FileObject->DeviceObject; } ASSERT( deviceObject != NULL ); // // Check to see whether or not the device has any associated devices. // If so, return the highest level device; otherwise, return a pointer // to the device object itself. // if (deviceObject->AttachedDevice != NULL) { deviceObject = IoGetAttachedDevice( deviceObject ); } return deviceObject; } |
|
沙发#
发布于:2008-03-19 19:41
结合devicetree来看就明白了~
|
|
板凳#
发布于:2008-03-21 10:56
我想弄明白的不是设备栈, 而是什么时候
if (FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL) 为真, 什么时候 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) && FileObject->DeviceObject->Vpb != NULL && FileObject->DeviceObject->Vpb->DeviceObject != NULL) 为真, 以及为什么有这样的不同处理。 |
|
地板#
发布于:2008-04-03 22:12
没看明白
|
|