获得FDO by name

    NTSTATUS            ntStatus = STATUS_SUCCESS;  
    PDEVICE_OBJECT  DeviceObject = NULL;  
    PFILE_OBJECT        FileObject = NULL;    
    ntStatus = IoGetDeviceObjectPointer(pObjectName,FILE_ALL_ACCESS,&FileObject,&DeviceObject);  
    if(!NT_SUCCESS(ntStatus))  
    {  
        KdPrint(("IoGetDeviceObjectPointer Failed,ntStatus = 0x%08lX\n",ntStatus));  
        goto _EXIT0_;  
    }  
    KdPrint(("IoGetDeviceObjectPointer succeed!\n"));  
 
    DeviceObject = IoGetLowerDeviceObject(DeviceObject);  
    if(!DeviceObject)  
    {  
        KdPrint(("IoGetLowerDeviceObject Failed,ntStatus = 0x%08lX!\n",ntStatus));  
        ntStatus = STATUS_UNSUCCESSFUL;  
        goto _EXIT1_;  
    }  
 
    while(!(DeviceObject->Flags & DO_BUS_ENUMERATED_DEVICE))  
    {  
        ObDereferenceObject(DeviceObject);  
        DeviceObject = IoGetLowerDeviceObject(DeviceObject);  
        if(!DeviceObject)  
        {  
            ObDereferenceObject(FileObject);  
            ntStatus = STATUS_UNSUCCESSFUL;  
            goto _EXIT1_;  
        }   
    }

照例pdo设备都会在Flags中设置DO_BUS_ENUMERATED_DEVICE,这也是判断PDO和FDO的标准之一

 

 

The IoGetLowerDeviceObject routine returns a pointer to the next-lower-level device object on the driver stack.

 

Ntifs.h (include Ntifs.h)

<= DISPATCH_LEVEL

 

posted @ 2011-04-10 15:16  ahuo  阅读(453)  评论(0编辑  收藏  举报