zylthinking
驱动牛犊
驱动牛犊
  • 注册日期2006-03-22
  • 最后登录2009-07-28
  • 粉丝0
  • 关注0
  • 积分62分
  • 威望9点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
阅读:1245回复:3

解释解释这个函数, 尤其其注释

楼主#
更多 发布于:2008-03-18 11:51
不要英文翻译阿, 我的英文还可以; 而是里面的各种情况到底是什么样一种情景, 或者哪里有相关资料?

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;
}
powerboot
驱动牛犊
驱动牛犊
  • 注册日期2007-12-15
  • 最后登录2009-12-26
  • 粉丝0
  • 关注0
  • 积分92分
  • 威望46点
  • 贡献值0点
  • 好评度34点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-03-19 19:41
结合devicetree来看就明白了~
zylthinking
驱动牛犊
驱动牛犊
  • 注册日期2006-03-22
  • 最后登录2009-07-28
  • 粉丝0
  • 关注0
  • 积分62分
  • 威望9点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
板凳#
发布于: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)
为真, 以及为什么有这样的不同处理。
xaxiao
驱动小牛
驱动小牛
  • 注册日期2007-09-11
  • 最后登录2010-02-10
  • 粉丝1
  • 关注0
  • 积分1分
  • 威望199点
  • 贡献值0点
  • 好评度197点
  • 原创分2分
  • 专家分0分
地板#
发布于:2008-04-03 22:12
没看明白
游客

返回顶部