日期:2014-05-17  浏览次数:21103 次

虚拟设备”的PDO如何创建
小弟最近正在看windows驱动的书,碰到了一个大大疑惑:
书上提到WDM是支持即插即用的驱动程序,因此不须要像NT驱动那样在DriverEntry中主动去创建设备,而是因为windows系统发现了新的设备,才把WDM驱动加载起来,并调用它的AddDevice例程。
这一点对于真实硬件来说可以理解,比如我插个u盘进去,操作系统发现后先创建一个PDO,然后再把上层驱动加起来并把它创建好的PDO作为参数扔过来。
但是,通常书上举例都是讲怎么去写一个“虚拟设备”的驱动,我就郁闷了,既然都是虚拟设备了,没有一个真实插入的事情,操作系统是怎么发现有一个这类的新设备出现了呢?虚拟设备,一般都是自己拿来做内核rookit用的吧,也就是说自己不创建的话,谁会帮你创建呢?

------解决方案--------------------
当与你设备创建完成的时候,是需要自己到管理器进行加载的,如Win7自带的虚拟硬盘功能,当在win7中按照虚拟硬盘向导生成好虚拟硬盘的时候,这时的向导就为你加载好了,但是一重启,你就要在管理里选择附加虚拟硬盘,然后找到你的虚拟硬盘文件,在加载上去,这样你的虚拟硬盘才能再用,因该是这样的。
------解决方案--------------------
You can specify root device name in your driver inf file. For example in DDK sample toast, you can find following line in bus.inf
%ToasterBus.DeviceDesc%=ToasterBus_Device, root\busenum
Once this inf file is installed, OS PnP manager will create a device node named \ROOT\BUSENUM\0000 and then install your driver on this virtual device.

Virtual device PDOs can also be created by virtual bus driver. In devmgmt.msc you can find UMBus Root Bus Enumerator under system devices. It is one of the virtual bus device. Bus driver in toast sample is also a virtual bus driver. It creates virtual Toast device.