我正在使用C#和Dokan库编写我的文件系统,并被困在了WriteFile上。
public int WriteFile(
String filename,
Byte[] buffer,
ref uint writtenBytes,
long offset,
DokanFileInfo info)
{
try
{
FileStream fs = File.OpenWrite( GetFullPath(filename) , FileMode.Open );
fs.Seek(offset, SeekOrigin.Begin);
fs.Lock(offset, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
fs.Unlock(offset, buffer.Length);
writtenBytes = (uint)buffer.Length;
return 0;
}
catch (Exception e)
{
Console.WriteLine("FAIL WriteFile {0}", e.Message);
return -1;
}
}当我运行app并从Dokan的虚拟驱动器打开txt文件时,添加一些行并尝试保存它。我从记事本中得到了“参数为incorect”的错误。
在代码中,我得到了File.OpenWrite()调用的异常。例外是System.IO.IOException。消息:“进程无法访问文件foo.txt,因为它正在被其他进程使用。”
。
Dokan应该作为代理工作,允许调用用户定义的WriteFile,对吗?如果它因为写作而被锁定了,我该怎么做呢?
请帮帮忙。也许你有过杜坎的经验,也有任何不管用的线索。
我使用的是- Win 7 Pro x64 - 64位Dokan驱动程序- App被编译为x86
发布于 2012-02-19 10:39:14
在离开该方法之前,必须在流中调用Dispose。这不是最好的解决办法。您可以在CreateFile中构造文件流,将其传递给info.Context,并在ReadFile、WriteFile中使用它,并在清理过程中调用dispose。
https://stackoverflow.com/questions/9337752
复制相似问题