xxxsunzk
驱动牛犊
驱动牛犊
  • 注册日期2004-11-23
  • 最后登录2004-12-01
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1258回复:3

各位大虾帮俺看看这段是想干啥,行行好

楼主#
更多 发布于:2004-11-24 11:42
我知道这段是添加设备    他为何要把NextLowerDriver->DeviceType赋给deviceObject->DeviceType 呢,什么意思?

#pragma PAGEDCODE
NTSTATUS
FilterAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject
    )

NTSTATUS                   status = STATUS_SUCCESS;
    PDEVICE_OBJECT          deviceObject = NULL;
    PDEVICE_EXTENSION       pdx;
    ULONG                   deviceType = FILE_DEVICE_UNKNOWN;
    ULONG                   length=0;
    WCHAR                   DriverKeyName[1024];

    PAGED_CODE ();


    //
    // IoIsWdmVersionAvailable(1, 0x20) returns TRUE on os after Windows 2000.
    //
    if (!IoIsWdmVersionAvailable(1, 0x20)) { /*checks whether a given WDM version is supported by the operating system zk添加*/
        //
        // Win2K system bugchecks if the filter attached to a storage device
        // doesn't specify the same DeviceType as the device it's attaching
        // to. This bugcheck happens in the filesystem when you disable
        // the devicestack whose top level deviceobject doesn't have a VPB.
        // To workaround we will get the toplevel object's DeviceType and
        // specify that in IoCreateDevice.
        //
        deviceObject = IoGetAttachedDeviceReference(PhysicalDeviceObject);/*   */
        deviceType = deviceObject->DeviceType;
        ObDereferenceObject(deviceObject);/* decrements the given object's reference count and performs retention checks */
    
}

    //
    // Create a filter device object.
    //

    status = IoCreateDevice (DriverObject,
                             sizeof (DEVICE_EXTENSION),
                             NULL,  // No Name
                             deviceType,
                             FILE_DEVICE_SECURE_OPEN,
                             FALSE,
                             &deviceObject);


    if (!NT_SUCCESS (status)) {
        //
        // Returning failure here prevents the entire stack from functioning,
        // but most likely the rest of the stack will not be able to create
        // device objects either, so it is still OK.
        //
        return status;
    }

    DebugPrint (("AddDevice PDO (0x%x) FDO (0x%x)\n",
                    PhysicalDeviceObject, deviceObject));

    pdx = (PDEVICE_EXTENSION) deviceObject->DeviceExtension;
    pdx->NextLowerDriver = IoAttachDeviceToDeviceStack (
                                       deviceObject,
                                       PhysicalDeviceObject);
    //
    // Failure for attachment is an indication of a broken plug & play system.
    //

    if(NULL == pdx->NextLowerDriver) {

        IoDeleteDevice(deviceObject);
        return STATUS_UNSUCCESSFUL;
    }

    deviceObject->Flags |= pdx->NextLowerDriver->Flags &
                            (DO_BUFFERED_IO | DO_DIRECT_IO |
                            DO_POWER_PAGABLE );



    deviceObject->DeviceType = pdx->NextLowerDriver->DeviceType;
    
    deviceObject->Characteristics =
                          pdx->NextLowerDriver->Characteristics;
    
    pdx->Self = deviceObject;
    pdx->PhysicalDeviceObject = PhysicalDeviceObject;

    //ASSERT(0);
    //ASSERT(1);

    status=IoGetDeviceProperty(PhysicalDeviceObject,
       DevicePropertyDriverKeyName,
       sizeof(DriverKeyName),
       &DriverKeyName,
       &length);

    if ((status==0) && (length))
    {
       _snwprintf(pdx->DriverKeyName,arraysize(pdx->DriverKeyName),L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Class\\%ws",DriverKeyName);

       DebugPrint(("Reading registry key %ws\n",pdx->DriverKeyName));
       pdx->ClockFrequency = ReadRegistryValue(pdx->DriverKeyName, L"ClockRate");
       pdx->LockDteRate.BaudRate = ReadRegistryValue(pdx->DriverKeyName, L"LockDteRate");
    }

    if (!pdx->ClockFrequency)
    {
       //pdx->ClockFrequency = 14745600;    //DL=4 for 230400
       //pdx->ClockFrequency = 3686400;    //DL=1 for 230400
       pdx->ClockFrequency = 1843200;  //default
    }
    DebugPrint(("ClockFrequency %ld\n",pdx->ClockFrequency));

    pdx->VPU1655xX8Mode = ReadDeviceRegistryDWord(pdx->PhysicalDeviceObject, L"VPU1655xX8Mode");
    DebugPrint(("VPU1655xX8Mode %ld\n",pdx->VPU1655xX8Mode));

   if ((WindowsNTVersion == WINDOWS2000) && (NTServicePack < 4))
      {
      //This is to fix a power management bug in early Windows 2000 versions...
      pdx->DisablePowerManagement = ReadDeviceRegistryDWord(pdx->PhysicalDeviceObject, L"EnablePowerManagement");
      DebugPrint(("DisablePowerManagement %ld\n",pdx->DisablePowerManagement));
      }
    //
    // Set the initial state of the Filter DO
    //

    INITIALIZE_PNP_STATE(pdx);

    DebugPrint(("AddDevice: %x to %x->%x \n", deviceObject,
                       pdx->NextLowerDriver,
                       PhysicalDeviceObject));

    deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

    return STATUS_SUCCESS;
KMK
KMK
驱动大牛
驱动大牛
  • 注册日期2001-09-12
  • 最后登录2017-10-06
  • 粉丝2
  • 关注0
  • 积分42分
  • 威望404点
  • 贡献值2点
  • 好评度58点
  • 原创分1分
  • 专家分1分
  • 社区居民
沙发#
发布于:2004-11-24 12:11
在IoCreateDevice时要用DeviceType,直接从下一个转用就方便多 !
xxxsunzk
驱动牛犊
驱动牛犊
  • 注册日期2004-11-23
  • 最后登录2004-12-01
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-11-24 13:46
IoCreateDevice调用完 deviceObject->DeviceType已有值

干吗deviceObject->DeviceType=|= pdx->NextLowerDriver->Flags &(DO_BUFFERED_IO | DO_DIRECT_IO |
DO_POWER_PAGABLE );
我很菜
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
地板#
发布于:2004-11-25 13:15
确保和下层设备对象有同样的属性,并能从同样的地方来获得数据.
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
游客

返回顶部