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) {
if (FileObject->Flags & FO_FILE_OBJECT_HAS_EXTENSION) { PIOP_FILE_OBJECT_EXTENSION fileObjectExtension =
(PIOP_FILE_OBJECT_EXTENSION)(FileObject + 1); ASSERT(!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN)); if (fileObjectExtension->TopDeviceObjectHint != NULL &&
IopVerifyDeviceObjectOnStack(deviceObject, fileObjectExtension->TopDeviceObjectHint)) {
return fileObjectExtension->TopDeviceObjectHint;
}
}
deviceObject = IoGetAttachedDevice( deviceObject );
} return deviceObject;
}

这个也是网上很普及的东西了。传入开启设备或者文件产生的文件对象 获得文件对象对应的设备所在的设备堆栈的最顶层设备。

根据 FileObject->Vpb != NULL && FileObject->Vpb->DeviceObject != NULL (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN 来判断设备对象的获取方式。 FILE_DEVICE_DISK等磁盘设备类型,如果卷设备挂载完成,则fileobject->vpb是存在的,那么获取到fileobject->vpb->deviceobject,。 如果卷设备挂载进行中,那么fileobject->vpb可能不存在,返回fileobject->devieobject->vpb->deviceobject。

对于非磁盘设备等设备类型 上述两种条件是无法满足的 函数获取文件对象结构中的设备对象。

然后通过不断轮询设备的AttachedDevice   直到为NULL 获取设备堆栈中最顶层设备(IoGetAttachedDevice)

获取文件对象的fileObjectExtension 验证这个设备 fileObjectExtension->TopDeviceObjectHint != NULL &&   IopVerifyDeviceObjectOnStack()

然后返回获得的设备对象

IoGetRelatedDeviceObject学习的更多相关文章

  1. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  2. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  3. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  4. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  5. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  6. Unity3d学习 制作地形

    这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...

  7. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  8. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  9. 多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类)

    前言:刚学习了一段机器学习,最近需要重构一个java项目,又赶过来看java.大多是线程代码,没办法,那时候总觉得多线程是个很难的部分很少用到,所以一直没下决定去啃,那些年留下的坑,总是得自己跳进去填 ...

随机推荐

  1. JAVA 集合操作总结

    1.Collection 1.基本操作 对集合的基础操作 1.boolean add(Object o) //添加对象到集合 2.boolean remove(Object o) //删除指定的对象 ...

  2. 知识图谱实战开发案例剖析-番外篇(1)- Neo4j是否支持按照边权重加粗和大数量展示

    一.前言 本文是<知识图谱实战开发案例完全剖析>系列文章和网易云视频课程的番外篇,主要记录学员在知识图谱等相关内容的学习 过程中,提出的共性问题进行展开讨论.该部分内容原始内容记录在网易云 ...

  3. Cannot change version of project facet Dynamic Web Module to 2.4问题解决

    问题现象: eclipse中,有个maven web项目,报错:Cannot change version of project facet Dynamic Web Module to 2.4,截图如 ...

  4. FreeBsd网络性能优化方案sysctl

    以下是阿盛的配置 sysctl net.inet.tcp.msl= sysctl net.inet.tcp.mssdflt= sysctl net.inet.tcp.minmss= sysctl ne ...

  5. 常用HDFS操作命令

    前一段时间频繁使用HDFS,又收集到了一些命令,在这儿分享出来,大数据的框架及设计原理方面的理论文章暂时还没有时间总结,后面有时间逐渐整理发出来. 注:在使用命令时,可以使用 hadoop fs,如果 ...

  6. delphi 字符串string转流TStream

    function StringToFile(mString : string; mFileName : TFileName) : Boolean;var vFileChar : file of Cha ...

  7. PHP chdir函数:改变当前的目录

    PHP chdir函数的作用是改变当前的目录,这里主机吧详细介绍下chdir函数的用法,并列举使用chdir函数的例子. chdir定义和用法: chdir() 函数改变当前的目录. chdir实例: ...

  8. Codeforces Round #551 (Div. 2) A-E

    A. Serval and Bus 算出每辆车会在什么时候上车, 取min即可 #include<cstdio> #include<algorithm> #include< ...

  9. 《深入浅出 Java Concurrency》目录

    最近在学习J.U.C,看到一个大神 关于这个系列写的非常精辟,由于想做笔记,故系列转载并记录之. 原文:http://www.blogjava.net/xylz/archive/2010/07/08/ ...

  10. OS模块的介绍

    os,语义为操作系统,模块提供了访问多个操作系统服务的功能,可以处理文件和目录这些我们日常手动需要做的操作.os和它的子模块os.path还包括一些用于检查.构造.删除目录和文件的函数,以及一些处理路 ...