决定哪种请求类型必须处理,哪些请求可以由framework代为处理
最常用的请求:
创建/关闭/读/写/ device I/O control
创建请求
CreateFile返回的是进程句柄而不是线程句柄。
应用程序调用CreateFile时,I/O manager创建file object,并向设备栈发送一个create request。
WDF接收到create request时,对应I/O manager file object创建一个WDF file object,用于为驱动建立和应用程序的会话。
** 一个file object可以被多个进程使用,一个会话可以被继承handle的进程或者复制handle的进程共享。
清空和关闭请求
应用程序在不需要file handle时调用CloseHandle,I/O manager递减handle count
当handle count到0时,I/O manager发送cleanup request
驱动在收到cleanup request后,需要取消所有的file object的outstanding I/O request
在object reference count到0且所有file的I/O都完成了,I/O manager就发起一个close request
-------/CloseHandle和Cleanup\----------
最后一个应用程序closehandle时,驱动收到cleanup请求。
cleanup请求到达的context是进程相关的,驱动清空会话内容
而close请求到达的context是任意的
读写请求
应用程序调用ReadFile和WriteFile,用buffer及length传递内容
I/O manager创建IRP,根据设备栈的I/O transfer type建立缓冲I/O或直接I/O
驱动返回数据及其长度
Device I/O control 请求
应用程序使用DeviceIoControl函数产生设备I/O控制请求(IOCTLs,device controls,I/O controls)。应用程序使用control code来表示操作(device 相关),control code有标准的和自定义的两种。
内核模式组件可以定义和发起私有的IOCTLs。
例子:CDROM的磁盘弹出,Fx2_Driverhe Osrusbfx2支持请求来控制USB灯光,支持custom control codes。
IOCTL的不同处:
1.类型由control code表示
2.可以选择定义input和output buffer
3.output buffer可以被用来input
总结:
每个I/O请求类型对应一个IRP major function code。
下表是WDF支持的所有IRP类型
WDM IRP major function code | Comments |
---|---|
IRP_MJ_CLEANUP | Supported through immediate callbacks on a file object; not queued. |
IRP_MJ_CLOSE | Supported through immediate callbacks on a file object; not queued. |
IRP_MJ_CREATE | Supported through queues for both KMDF and UMDF, and through immediate callbacks on a device object for KMDF only. |
IRP_MJ_DEVICE_CONTROL | Supported through queues. |
IRP_MJ_INTERNAL_DEVICE_CONTROL | Supported through queues for KMDF only. |
IRP_MJ_PNP | Supported through state-specific callbacks on a device object. |
IRP_MJ_POWER | Supported through state-specific callbacks on a device object. |
IRP_MJ_READ | Supported through queues. |
IRP_MJ_SHUTDOWN | Supported for control (non-Plug and Play) device objects in KMDF only. |
IRP_MJ_SYSTEM_CONTROL | Supported through WMI objects in KMDF only. |
IRP_MJ_WRITE | Supported through queues. |