阅读:1258回复:3
各位大虾帮俺看看这段是想干啥,行行好
我知道这段是添加设备 他为何要把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; |
|
沙发#
发布于:2004-11-24 12:11
在IoCreateDevice时要用DeviceType,直接从下一个转用就方便多 !
|
|
板凳#
发布于:2004-11-24 13:46
IoCreateDevice调用完 deviceObject->DeviceType已有值
干吗deviceObject->DeviceType=|= pdx->NextLowerDriver->Flags &(DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_PAGABLE ); 我很菜 |
|
地板#
发布于:2004-11-25 13:15
确保和下层设备对象有同样的属性,并能从同样的地方来获得数据.
|
|
|