阅读:4135回复:14
请教:在XP下用IoAttachDeviceToDeviceStack挂接硬盘没有问题,可是在VISTA却不行,请各路高手相助!
以前写了个硬盘过滤驱动程序,在2K、XP都可以正常工作,可是在VISTA下却在滚动条转几圈就重启了,请各路高手、豪侠拔刀相助,小虾谢谢大家[p:1]
|
|
沙发#
发布于:2007-03-15 09:01
代码贴出来,不然就别问了.
|
|
|
板凳#
发布于:2007-03-15 09:35
NTSTATUS MC_AddDevice(
PDRIVER_OBJECT iDriverObject, PDEVICE_OBJECT iPhysicalDeviceObject ) { ANSI_STRING mAnsiString; UNICODE_STRING mUnicodeString; PDEVICE_OBJECT mDeviceObject; mPDEVICE_EXTENSION mDeviceExtension; NTSTATUS mStatus; PDEVICE_OBJECT DeviceObject; PFILE_OBJECT FileObject; IoCreateDevice( mDriverObject, sizeof( mDEVICE_EXTENSION ), NULL, FILE_DEVICE_DISK, 0, FALSE, &mDeviceObject ); mDeviceObject -> Flags |= DO_DIRECT_IO; mDeviceExtension = mDeviceObject -> DeviceExtension; // 设备扩展指针 mDeviceExtension -> mExtDeviceObject = mDeviceObject; // 回指功能设备对象 RtlInitAnsiString( &mAnsiString, L""\\Device\\Harddisk0\\Partition1"" ); // 初始化字符串 RtlAnsiStringToUnicodeString( &mUnicodeString, &mAnsiString, TRUE ); IoGetDeviceObjectPointer(&mUnicodeString, 0, &FileObject, &DeviceObject); mDeviceExtension -> mExtTargetDevice = IoAttachDeviceToDeviceStack(mDeviceObject, DeviceObject); RtlFreeUnicodeString( &mUnicodeString ); // 释放字符串缓冲区 } 请各位高手帮忙看看呀! |
|
地板#
发布于:2007-05-02 15:45
vista主要要在upperfliter挂接,pnp方式
|
|
地下室#
发布于:2007-05-03 22:08
老兄,能不能给个QQ?
|
|
5楼#
发布于:2007-05-06 12:59
你挂接的时候 \\Device\\Harddisk0\\Partition1 这个对象一定存在吗???
不存在,当然要挂接失败。 |
|
|
6楼#
发布于:2007-05-07 14:59
我也遇到和LZ类似的问题,有机会可以探讨,我的邮箱是tough_lion@163.com
|
|
7楼#
发布于:2007-05-09 11:23
一看就是做还原卡的,哈哈
换\\Device\\Harddisk0\\Partition1为\\Device\\Dr0\\Partition1呢? |
|
8楼#
发布于:2007-07-06 21:38
建议你直接看MS SOURCE CODE
PDEVICE_OBJECT IoAttachDeviceToDeviceStack( IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice ) /*++ Routine Description: This routine attaches the source device object to the target device object and returns a pointer to the actual device attached to, if successful. Arguments: SourceDevice - Specifies the device object that is to be attached to the target device. TargetDevice - Specifies the device object to which the attachment is to occur. Return Value: If successful, this function returns a pointer to the device object to which the attachment actually occurred. If unsuccessful, this function returns NULL. (This could happen if the device currently at the top of the attachment chain is being unloaded, deleted or initialized.) --*/ { PDEVICE_OBJECT deviceObject; PDEVOBJ_EXTENSION sourceExtension; KIRQL irql; // // Retrieve a pointer to the source device object's extension outside // of the IopDatabaseLock, since it isn't protected by that. // sourceExtension = SourceDevice->DeviceObjectExtension; // // Get a pointer to the topmost device object in the stack of devices, // beginning with the TargetDevice, and attach to it. // ExAcquireFastLock( &IopDatabaseLock, &irql ); // // Tell the Special IRP code the stack has changed. Code that will reexamine // the stack takes the database lock, so we can place the call here. This // also allows us to assert correct behavoir *before* the stack is built up. // IOV_ATTACH_DEVICE_TO_DEVICE_STACK(SourceDevice, TargetDevice); deviceObject = IoGetAttachedDevice( TargetDevice ); // // Make sure that the SourceDevice object isn't already attached to // something else, this is now illegal. // ASSERT( sourceExtension->AttachedTo == NULL ); // // Now attach to the device, provided that it is not being unloaded, // deleted or initializing. // if (deviceObject->Flags & DO_DEVICE_INITIALIZING || deviceObject->DeviceObjectExtension->ExtensionFlags & (DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | DOE_REMOVE_PENDING | DOE_REMOVE_PROCESSED)) { // // The device currently at the top of the attachment chain is being // unloaded, deleted or initialized. // deviceObject = (PDEVICE_OBJECT) NULL; } else { // // Perform the attachment. First update the device previously at the // top of the attachment chain. // deviceObject->AttachedDevice = SourceDevice; deviceObject->Spare1++; // // Now update the new top-of-attachment-chain. // SourceDevice->StackSize = (UCHAR) (deviceObject->StackSize + 1); SourceDevice->AlignmentRequirement = deviceObject->AlignmentRequirement; SourceDevice->SectorSize = deviceObject->SectorSize; if (deviceObject->DeviceObjectExtension->ExtensionFlags & DOE_START_PENDING) { SourceDevice->DeviceObjectExtension->ExtensionFlags |= DOE_START_PENDING; } // // Attachment chain is doubly-linked. // sourceExtension->AttachedTo = deviceObject; } ExReleaseFastLock( &IopDatabaseLock, irql ); return deviceObject; } PDEVICE_OBJECT IoGetAttachedDevice( IN PDEVICE_OBJECT DeviceObject ) /*++ Routine Description: This routine returns the highest level device object associated with the specified device. N.B. Caller must own the IopDatabaseLock. External callers of this function must ensure nobody is attaching or detaching from the stack. If they cannot, they *must* use IoGetAttachedDeviceReference. Arguments: DeviceObject - Supplies a pointer to the device for which the attached device is to be returned. Return Value: The function value is the highest level device attached to the specified device. If no devices are attached, then the pointer to the device object itself is returned. --*/ { // // Loop through all of the device object's attached to the specified // device. When the last device object is found that is not attached // to, return it. // while (DeviceObject->AttachedDevice) { DeviceObject = DeviceObject->AttachedDevice; } return DeviceObject; } |
|
9楼#
发布于:2007-07-11 10:40
谢谢你
|
|
10楼#
发布于:2007-07-11 10:48
vista主要要在upperfliter挂接,pnp方式,况且在过滤硬盘的同时也会过滤U盘等其它磁盘设备,如何区分磁盘也是很头痛,大家一起讨论.
|
|
11楼#
发布于:2007-08-04 23:13
结合文件过滤挂分区的方法可以不过滤U盘设备
|
|
12楼#
发布于:2007-08-24 17:32
|
|
13楼#
发布于:2007-08-24 17:47
引用第7楼yuanyuan于2007-05-09 11:23发表的 : 有必要挂接Partition1吗?不挂一样可以做! |
|
|
14楼#
发布于:2007-08-30 17:32
Re:请教:在XP下用IoAttachDeviceToDeviceStack挂接硬盘没有问
大家可以参考DiskPerf,当然了可以省去其中WMI部分,当然采用文件过滤的挂接方式可以省去很多未知的麻烦,呵呵,祝大家愉快 |
|