chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
阅读:4135回复:14

请教:在XP下用IoAttachDeviceToDeviceStack挂接硬盘没有问题,可是在VISTA却不行,请各路高手相助!

楼主#
更多 发布于:2007-03-14 19:10
  以前写了个硬盘过滤驱动程序,在2K、XP都可以正常工作,可是在VISTA下却在滚动条转几圈就重启了,请各路高手、豪侠拔刀相助,小虾谢谢大家[p:1]
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
沙发#
发布于:2007-03-15 09:01
代码贴出来,不然就别问了.
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
板凳#
发布于: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 );  // 释放字符串缓冲区

}

请各位高手帮忙看看呀!
alexacc
驱动牛犊
驱动牛犊
  • 注册日期2005-11-01
  • 最后登录2011-08-04
  • 粉丝0
  • 关注0
  • 积分6分
  • 威望51点
  • 贡献值0点
  • 好评度23点
  • 原创分0分
  • 专家分0分
地板#
发布于:2007-05-02 15:45
vista主要要在upperfliter挂接,pnp方式
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2007-05-03 22:08
老兄,能不能给个QQ?
alphapiao
驱动小牛
驱动小牛
  • 注册日期2002-06-21
  • 最后登录2011-05-04
  • 粉丝0
  • 关注0
  • 积分1004分
  • 威望155点
  • 贡献值0点
  • 好评度109点
  • 原创分1分
  • 专家分0分
5楼#
发布于:2007-05-06 12:59
你挂接的时候 \\Device\\Harddisk0\\Partition1 这个对象一定存在吗???

不存在,当然要挂接失败。
我的博客:xpddk.bokee.com
tough_lion
驱动牛犊
驱动牛犊
  • 注册日期2006-05-08
  • 最后登录2007-09-08
  • 粉丝0
  • 关注0
  • 积分370分
  • 威望38点
  • 贡献值0点
  • 好评度37点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2007-05-07 14:59
我也遇到和LZ类似的问题,有机会可以探讨,我的邮箱是tough_lion@163.com
yuanyuan
驱动大牛
驱动大牛
  • 注册日期2003-01-15
  • 最后登录2010-08-04
  • 粉丝0
  • 关注0
  • 积分1025分
  • 威望300点
  • 贡献值0点
  • 好评度232点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2007-05-09 11:23
一看就是做还原卡的,哈哈
换\\Device\\Harddisk0\\Partition1为\\Device\\Dr0\\Partition1呢?
liugang93
驱动牛犊
驱动牛犊
  • 注册日期2004-02-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分9分
  • 威望19点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
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;
}
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2007-07-11 10:40
谢谢你
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
10楼#
发布于:2007-07-11 10:48
vista主要要在upperfliter挂接,pnp方式,况且在过滤硬盘的同时也会过滤U盘等其它磁盘设备,如何区分磁盘也是很头痛,大家一起讨论.
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
11楼#
发布于:2007-08-04 23:13
结合文件过滤挂分区的方法可以不过滤U盘设备
boywhp
驱动中牛
驱动中牛
  • 注册日期2007-08-09
  • 最后登录2015-04-24
  • 粉丝2
  • 关注0
  • 积分1105分
  • 威望515点
  • 贡献值0点
  • 好评度254点
  • 原创分1分
  • 专家分0分
12楼#
发布于:2007-08-24 17:32
我想参考一下你的挂接代码,我的就是收不到驱动的信息,老火啊
boywhp@126.com
谢谢
ProPlayboy
驱动大牛
驱动大牛
  • 注册日期2005-07-07
  • 最后登录2022-02-15
  • 粉丝0
  • 关注0
  • 积分1016分
  • 威望811点
  • 贡献值0点
  • 好评度719点
  • 原创分0分
  • 专家分0分
  • 社区居民
13楼#
发布于:2007-08-24 17:47
引用第7楼yuanyuan于2007-05-09 11:23发表的  :
一看就是做还原卡的,哈哈
换\Device\Harddisk0\Partition1为\Device\Dr0\Partition1呢?


有必要挂接Partition1吗?不挂一样可以做!
人不靓仔心灵美,版头不正红花仔!
chenriliang
驱动牛犊
驱动牛犊
  • 注册日期2006-07-25
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望19点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
14楼#
发布于:2007-08-30 17:32
Re:请教:在XP下用IoAttachDeviceToDeviceStack挂接硬盘没有问
大家可以参考DiskPerf,当然了可以省去其中WMI部分,当然采用文件过滤的挂接方式可以省去很多未知的麻烦,呵呵,祝大家愉快
游客

返回顶部