minifiler file redirection

Hi
I want to implement a so called “file virtualization system”.
The main idea is to build a file copy-on-write mechanism that any write can be redirected to some other place.
I know I can use STATUS_REPARSE within IRP_MJ_CREATE, and I have implemented a demo.
But., I want to do this on IRP_MJ_WRITE. Open another file, change the TragetFileObject param.
Is that possible?

It’s possible, but not quite that easy. First, TargetFileObject has some
issues when the FILE_OBJECTs are on different volumes (
http://fsfilters.blogspot.com/2011/09/file-io-redirection-between-volumes.html
).
Also, just switching the TargetFileObject from under the IRP_MJ_WRITE
sounds easy but can be problematic, things need to be kept in sync between
those FILE_OBJECTs, there are things like byte-range locks and oplocks that
need to be dealt with.

But there are other, more complex issues that might make it impossible to
use the TargetFileObject approach.
Do you need to make different users or processes accessing the file see
different data (process P1 sees the old, unmodified data while P2 sees the
data it just wrote)? Or does everything see the same data (more like a
snapshot mechanism)?

Basically, it would help if you could describe your requirements a bit more.

Thanks,
Alex.

On Thu, Feb 13, 2014 at 6:56 PM, <121960169@qq.com> wrote:

Hi
I want to implement a so called “file virtualization system”.
The main idea is to build a file copy-on-write mechanism that any
write can be redirected to some other place.
I know I can use STATUS_REPARSE within IRP_MJ_CREATE, and I have
implemented a demo.
But., I want to do this on IRP_MJ_WRITE. Open another file, change the
TragetFileObject param.
Is that possible?


NTFSD is sponsored by OSR

OSR is hiring!! Info at http://www.osr.com/careers

For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Thank you, Alex.
I do need to make different users or processes accessing the file see different data .
I am trying to make a simple demo can work with MS winword. But meet tons of trouble.
Once i redirect IRP_MJ_WRITE (copy target file first), the following IRP_MJ_READ doesn’t work.
I don’t know what happened.
Do you have any tips?
Here my ugly code:

PRE_IRP_MJ_WRITE :
ReparseNormalFileToNewPath(&pFileStreamContext->FileNameInfo->Name,
&usTargetFileName);

KeAcquireGuardedMutex(gWriteMutex); //released on POST_IRP_MJ_WRITE
CopyFile(&pFileStreamContext->FileNameInfo->Name, &usTargetFileName);

status = CreareFileObject(FltObjects,
&usTargetFileName,
&hFileHandle,
&pFileObj);

pFileInfo = ExAllocatePool(NonPagedPool, sizeof(FILE_INFOMATION));
pFileInfo->FileHandle = hFileHandle;
pFileInfo->FileObject = pFileObj;
*CompletionContext = pFileInfo;

PRE_IRP_MJ_READ :
ReparseNormalFileToNewPath(&pFileStreamContext->FileNameInfo->Name,
&usTargetFileName);

KeAcquireGuardedMutex(gWriteMutex); //released on POST_IRP_MJ_READ
status = CreareFileObject(FltObjects,
&usTargetFileName,
&hFileHandle,
&pFileObj);

pFileInfo = ExAllocatePool(NonPagedPool, sizeof(FILE_INFOMATION));
pFileInfo->FileHandle = hFileHandle;
pFileInfo->FileObject = pFileObj;
*CompletionContext = pFileInfo;

Data->Iopb->TargetFileObject = pFileObj;
FltSetCallbackDataDirty(Data);