cnmmd
驱动牛犊
驱动牛犊
  • 注册日期2004-03-15
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分62分
  • 威望48点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
  • 社区居民
阅读:1604回复:3

sfilter疑问1--如何将 filter driver object 挂在文件系统驱动堆栈上?

楼主#
更多 发布于:2004-06-25 13:24


我现在都不明白,到底是用IoAttachDeviceToDeviceStack函数呢,还是用FsRtlRegisterFileSystemFilterCallbacks
seaquester
驱动大牛
驱动大牛
  • 注册日期2002-05-22
  • 最后登录2016-06-16
  • 粉丝0
  • 关注0
  • 积分500分
  • 威望115点
  • 贡献值0点
  • 好评度107点
  • 原创分0分
  • 专家分52分
沙发#
发布于:2004-06-28 08:43
IoAttachDeviceToDeviceStack
八风舞遥翩,九野弄清音。 鸣高常向月,善舞不迎人。
cnmmd
驱动牛犊
驱动牛犊
  • 注册日期2004-03-15
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分62分
  • 威望48点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
  • 社区居民
板凳#
发布于:2004-06-28 09:30
File system filter driver DriverEntry中的工作
1,创建Control Device Object
RtlInitUnicodeString(&nameString, FILESPY_FULLDEVICE_NAME);
status = IoCreateDevice(
        DriverObject,                  //DriverObject
        0,                             //DeviceExtensionSize
        &nameString,                   //DeviceName
        FILE_DEVICE_DISK_FILE_SYSTEM,  //DeviceType
        FILE_DEVICE_SECURE_OPEN,       //DeviceCharacteristics
        FALSE,                         //Exclusive
        &gControlDeviceObject);        //DeviceObject

2,注册IRP派遣函数
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
    DriverObject->MajorFunction = SpyDispatch;
}
DriverObject->MajorFunction[IRP_MJ_CREATE] = SpyCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = SpyClose;
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = SpyFsControl;

3,注册Fast I/O 派遣函数
RtlZeroMemory(fastIoDispatch, sizeof(FAST_IO_DISPATCH));
fastIoDispatch->SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
fastIoDispatch->FastIoCheckIfPossible = SpyFastIoCheckIfPossible;
fastIoDispatch->FastIoRead = SpyFastIoRead;
fastIoDispatch->FastIoWrite = SpyFastIoWrite;
fastIoDispatch->FastIoQueryBasicInfo = SpyFastIoQueryBasicInfo;
fastIoDispatch->FastIoQueryStandardInfo = SpyFastIoQueryStandardInfo;
fastIoDispatch->FastIoLock = SpyFastIoLock;
fastIoDispatch->FastIoUnlockSingle = SpyFastIoUnlockSingle;
fastIoDispatch->FastIoUnlockAll = SpyFastIoUnlockAll;
fastIoDispatch->FastIoUnlockAllByKey = SpyFastIoUnlockAllByKey;
fastIoDispatch->FastIoDeviceControl = SpyFastIoDeviceControl;
fastIoDispatch->FastIoDetachDevice = SpyFastIoDetachDevice;
fastIoDispatch->FastIoQueryNetworkOpenInfo = SpyFastIoQueryNetworkOpenInfo;
fastIoDispatch->MdlRead = SpyFastIoMdlRead;
fastIoDispatch->MdlReadComplete = SpyFastIoMdlReadComplete;
fastIoDispatch->PrepareMdlWrite = SpyFastIoPrepareMdlWrite;
fastIoDispatch->MdlWriteComplete = SpyFastIoMdlWriteComplete;
fastIoDispatch->FastIoReadCompressed = SpyFastIoReadCompressed;
fastIoDispatch->FastIoWriteCompressed = SpyFastIoWriteCompressed;
fastIoDispatch->MdlReadCompleteCompressed = SpyFastIoMdlReadCompleteCompressed;
fastIoDispatch->MdlWriteCompleteCompressed = SpyFastIoMdlWriteCompleteCompressed;
fastIoDispatch->FastIoQueryOpen = SpyFastIoQueryOpen;

DriverObject->FastIoDispatch = fastIoDispatch;


4,注册回调函数
fsFilterCallbacks.SizeOfFsFilterCallbacks = sizeof(FS_FILTER_CALLBACKS);
fsFilterCallbacks.PreAcquireForSectionSynchronization = SpyPreFsFilterOperation;
fsFilterCallbacks.PostAcquireForSectionSynchronization = SpyPostFsFilterOperation;
fsFilterCallbacks.PreReleaseForSectionSynchronization = SpyPreFsFilterOperation;
fsFilterCallbacks.PostReleaseForSectionSynchronization = SpyPostFsFilterOperation;
fsFilterCallbacks.PreAcquireForCcFlush = SpyPreFsFilterOperation;
fsFilterCallbacks.PostAcquireForCcFlush = SpyPostFsFilterOperation;
fsFilterCallbacks.PreReleaseForCcFlush = SpyPreFsFilterOperation;
fsFilterCallbacks.PostReleaseForCcFlush = SpyPostFsFilterOperation;
fsFilterCallbacks.PreAcquireForModifiedPageWriter = SpyPreFsFilterOperation;
fsFilterCallbacks.PostAcquireForModifiedPageWriter = SpyPostFsFilterOperation;
fsFilterCallbacks.PreReleaseForModifiedPageWriter = SpyPreFsFilterOperation;
fsFilterCallbacks.PostReleaseForModifiedPageWriter = SpyPostFsFilterOperation;

status = FsRtlRegisterFileSystemFilterCallbacks(DriverObject, &fsFilterCallbacks);


5,其他初始化工作

6,注册回调函数
Filter drivers can call IoRegisterFsRegistrationChange to register a callback routine to be called whenever a file system driver calls IoRegisterFileSystem or IoUnregisterFileSystem to register or unregister itself. Filter drivers do this so they can see new file systems enter the system and choose whether to attach to them.

7,[Optional] Saving a Copy of the Registry Path String

8,Returning Status


但是我的疑问是:
Attaching a Filter to a File System or Volume 有两种方法:
(1)The end user can specify the volumes to filter by, for example, typing in the drive letters for the volumes. The end user's commands are relayed to the filter driver as a private IRP_MJ_DEVICE_CONTROL request. The FileSpy sample driver uses this approach when it is compiled with the global variable gFileSpyAttachMode set to FILESPY_ATTACH_ON_DEMAND. (It is set to FILESPY_ATTACH_ALL_VOLUMES by default.)
(2)The file system filter driver can attach to one or more file system drivers, listen for IRP_MJ_FILE_SYSTEM_CONTROL, IRP_MN_MOUNT_VOLUME requests, and attach to volumes as they are mounted. The SFilter sample driver uses this approach. The FileSpy sample driver uses this approach when it is compiled with the global variable gFileSpyAttachMode set to FILESPY_ATTACH_ALL_VOLUMES (the default value).

也就是说需要在IRP_MJ_FILE_SYSTEM_CONTROL派遣函数中Attaching a Filter to a File System or Volume.
但是,如果还没有Attach,如何收到该IRP呢?

我又考虑,可能是load order group的原因,导致将该filter driver加载到了file system堆栈中的吧。那么它可以收到该IRP了?

是不是该在该IRP中Attach呢?
youkenkin
驱动牛犊
驱动牛犊
  • 注册日期2004-04-14
  • 最后登录2004-07-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-07-02 16:57
1111
游客

返回顶部