设备对象(DEVICE_OBJECT)

设备对象(DEVICE_OBJECT)

typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {

    CSHORT Type;

    USHORT Size;

    LONG ReferenceCount;

    struct _DRIVER_OBJECT *DriverObject;//指向驱动程序的驱动对象,同属一个驱动程序的驱动对象是指向的是统一的驱动对象

    struct _DEVICE_OBJECT *NextDevice;//指向下一个设备对象,同属于同一个驱动对象的设备

    struct _DEVICE_OBJECT *AttachedDevice;//指向下一个设备对象,指的是如果有更高一层的驱动附加到这个驱动,AttachedDevice指向更高一层的驱动。

    struct _IRP *CurrentIrp;//使用StartIO例程,此域指向当前IRP对象

    PIO_TIMER Timer;

    ULONG Flags;                                // See above:  DO_...

    ULONG Characteristics;                      // See ntioapi:  FILE_...

    __volatile PVPB Vpb;

    PVOID DeviceExtension;//指向设备扩展对象,每个设备都会指定一个设备扩展对象,设备扩展对象是
                          //设备自己特殊定义的结构体,由程序员自己定义,驱动程序中应避免全局变量
                          //的使用,因为全局变量涉及不易同步的问题。解决办法,将全局变量存在设备扩展里

    DEVICE_TYPE DeviceType;//指明设备的类型

    CCHAR StackSize;

    union {

        LIST_ENTRY ListEntry;

        WAIT_CONTEXT_BLOCK Wcb;

    } Queue;

    ULONG AlignmentRequirement;

    KDEVICE_QUEUE DeviceQueue;

    KDPC Dpc;

    //

    //  The following field is for exclusive use by the filesystem to keep

    //  track of the number of Fsp threads currently using the device

    //

    ULONG ActiveThreadCount;

    PSECURITY_DESCRIPTOR SecurityDescriptor;

    KEVENT DeviceLock;

    USHORT SectorSize;

    USHORT Spare1;

    struct _DEVOBJ_EXTENSION  *DeviceObjectExtension;

    PVOID  Reserved;

} DEVICE_OBJECT;

typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT; 


Flags
DO_BUFFERED_IO                                             读写操作使用缓冲方式(系统复制缓冲区)访问用户模式数据
DO_EXCLUSIVE                                                一次只允许一个线程打开设备句柄
DO_DIRECT_IO                                                 读写操作使用直接方式(内存描述符表)访问用户模式数据
DO_BUS_ENUMERATED_DEVICE                         Bus drivers set this flag in the PDO of each device they enumerate. This flag pertains only to the PDO; it must not be set in an FDO or filter DO. Therefore, higher-level drivers layered over a bus driver must not propagate this value up the device stack. 
DO_DEVICE_INITIALIZING                             设备对象正在初始化 
DO_POWER_INRUSH                                         Drivers of devices that require inrush current when powering on must set this flag. A driver cannot set both this flag and DO_POWER_PAGABLE. 
DO_POWER_PAGABLE                                      Windows? 2000 and later drivers that are pageable, are not part of the paging path, and do not require inrush current must set this flag. The system calls such drivers at IRQL PASSIVE_LEVEL. Drivers cannot set both this flag and DO_POWER_INRUSH. 
                                    All WDM, Windows 98, and Windows Me drivers must set DO_POWER_PAGABLE.  
DO_VERIFY_VOLUME                                         Removable-media drivers set this flag while processing transfer requests. Such drivers should also check for this flag in the target for a transfer request before transferring any data. See the Supporting Removable Media for details 

下面分别描述设备对象中驱动程序可访问成员的具体含义。
PDRIVER_OBJECT DriverObject:指向驱动程序中的驱动对象。同属一个驱动程序的驱动对象指针都指向同一个驱动对象。
PDEVICE_OBJECT NextDevice:指向下一个设备对象。这里的下一个设备对象是同一个驱动程序创建的若干设备对象中的一个。每个设备对象会根据NextDevice成员形成链表,从而遍历每个设备对象。在每次成功调用IoCreateDevice 后,I/O管理器就会更新该链表。当驱动被卸载时,需要遍历该链表,删除每个设备对象。
PIRP CurrentIrp:如果驱动使用StartIO例程,此成员将指向当前的IRP结构,否则为NULL。
ULONG Flags:此成员是一个32位的无符号整型变量,每个位有不同的含义。可通过按位取“或”操作为新创建的设备对象设置不同的特性。
ULONG Characteristics:此成员说明设备对象的特性,当驱动程序调用IoCreate-Device时,可设置FILE_REMOVABLE_MEDIA(表示存储设备支持可移动介质)、FILE_READ_ONLY_DEVICE(表示设备不能写)、FILE_FLOPPY_DISKETTE(表示设备是软盘设备)等值。
PVOID DeviceExtension:指向设备扩展对象。
DEVICE_TYPE DeviceType:指明设备的类型,由IoCreateDevice设置,根据设备的需要填写相应的设备类型。
CCHAR StackSize:在多层驱动的情况下,驱动与驱动之间形成类似堆栈的结构。IRP会依次从最高层传递到最底层。StackSize就是用于指定发送到该驱动的IRP在堆栈位置的最小层数的。IoCreateDevice在一个新创建的设备对象中设置该成员。
ULONG AlignmentRequirement:进行数据传输的时候,规范设备的地址对齐。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值