How to set Wait parameter in CcCopyWrite?

Hi, I’m developing an encryption filter based on minifilter with shadowFileObject tech.
Now I’m a little confused about CcCopyWrite, I call CcCopyWrite in IRP_MJ_WRITE PreRoutine for cached IO with Wait = TRUE.
But I wonder when should I set Wait = FALSE, is it related with IRP_DEFER_IO_COMPELETION flag?

If u want to make the call synchronous set the Boolean value to TRUE.
Otherwise FALSE. no need to take pain of IRP_DEFER_IO_COMPELETION .

With TRUE, CcCopyRead is not allowed to return “cannot do this time”, and is mandated to really do the operation inline, even with blocking.

With FALSE, CcCopyRead is not allowed to block, but can return “cannot do this inline, blocking is required”.

BTW, many FastIo functions are the same (they call CcCopyRead/Write internally).

Yes, if CcCopyRead returns FALSE (“cannot do this time”), you will probably need to defer.

wrote in message news:xxxxx@ntfsd…
> If u want to make the call synchronous set the Boolean value to TRUE.
> Otherwise FALSE. no need to take pain of IRP_DEFER_IO_COMPELETION .
>
>

Thanks guys, I follow the fastfat source( read the value of wait parameter from Data ) and set it into the CcCopyRead.

The general sequence is:

  • IoIsOperationSynchronous (renamed CanFsdWait() in FASTFAT). This checks for “inherently sync” (always sync on all file objects) operations (like some QueryInfo and SetInfos, and, pre-Vista, the create path too), and also for non-overlapped files.
  • if IoIsOperationSynchronous is TRUE - then you can block, since the OS will block waiting for your IRP anyway. So, call CcCopyRead(TRUE).
  • if IoIsOperationSynchronous is FALSE - then you cannot block, since you will ruin the overlapped IO in such a case. In this case, call CcCopyRead(FALSE). If it is done - then complete the IRP inline.
  • otherwise, if it returns “cannot do without waiting” (just FALSE retval) - then you must pend the IRP to the worker thread (called “FSP thread” in FASTFAT), and return STATUS_PENDING.
  • the worker thread in turn calls the same function (the inner FatCommonXxx, not FatFsdXxx which does the analyzis above) with CcCopyRead(TRUE).

Also note that FASTFAT IIRC uses FsRtlCopyRead/Write as its FastIo, which is a wrapper around CcCopyRead/Write (and the write path also does EOF/VDL mgmt).


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntfsd…
> Thanks guys, I follow the fastfat source( read the value of wait parameter from Data ) and set it into the CcCopyRead.
>

Thanks Maxim ;D
Your answer is concise and to the point.
Besides, fastfat source seems really well-designed.