文件系统过滤器驱动程序:创建碎片整理程序
我刚刚开始开发一个文件系统过滤器驱动程序,该驱动程序监视对任何文件的 I/O 写入(侦听 IRP_MJ_WRITE 请求),并在文件变得碎片时透明地对文件进行碎片整理。
目前,我有这样的代码:
NTSTATUS FsFilterDispatchWrite(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)
{
PFILE_OBJECT pFileObject = IoGetCurrentIrpStackLocation(Irp)->FileObject;
NTSTATUS result = FsFilterDispatchPassThrough(DeviceObject, Irp);
//FltFsControlFile(???);
return result;
}
其中我需要发出 FSCTL_GET_RETRIEVAL_POINTERS
I/O 控制代码。
但是,我对驱动程序开发领域相当陌生...... FltFsControlFile
是我在这里使用的正确函数吗?如果是,Instance
参数代表什么?如果没有,那么我应该如何去做呢?
I've just started working on a file system filter driver that monitors for I/O writes to any file (listening for IRP_MJ_WRITE
requests), and defragments the file transparently if it becomes fragmented.
Currently, I have code like this:
NTSTATUS FsFilterDispatchWrite(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp)
{
PFILE_OBJECT pFileObject = IoGetCurrentIrpStackLocation(Irp)->FileObject;
NTSTATUS result = FsFilterDispatchPassThrough(DeviceObject, Irp);
//FltFsControlFile(???);
return result;
}
in which I would need to issue the FSCTL_GET_RETRIEVAL_POINTERS
I/O control code.
However, I'm rather new to the area of driver development... is FltFsControlFile
the correct function for me to use here? If so, what does the Instance
parameter represent? And if not, then how should I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Merhad,
FltFsControlFile 是正确使用的 API,但请记住,不值得从过滤器驱动程序进行碎片整理,在内核模式下对 IO 路径进行碎片整理(或从工作线程进行碎片整理将非常低效),效率非常低。
Windows 使大多数文件可以在用户模式下进行碎片整理。检查 http://technet.microsoft.com/en-us /library/dd405526(VS.85).asp 和 http://technet.microsoft.com/en-us/library/ aa364577(VS.85).aspx
要监视 FS 活动,最好的办法是使用 USN 日志,这是非常有效的。不会对系统施加任何负载
http://technet. microsoft.com/en-us/library/aa365736(VS.85).aspx
Merhad,
FltFsControlFile is the correct API to use, but rememeber its not worth doing defragmentation from a filter driver, doing defrag on IO path (or from a worker thread will be highly in-efficient) in kernel mode is highly in efficient.
Windows made most of the files defragable from user mode. check http://technet.microsoft.com/en-us/library/dd405526(VS.85).asp and http://technet.microsoft.com/en-us/library/aa364577(VS.85).aspx
To monitor the FS activities the better thing to do is using USN journal, which is very efficient. Does not impose any load to the system
http://technet.microsoft.com/en-us/library/aa365736(VS.85).aspx