OnWriteFileC event/delegate/callback

Filter:

Pascal    C++ (Lib)    C++ (VCL)    C++ (.NET)    C#    VB.NET   

CBFSFilter     See also    

Overview

This callback is called when the OS needs to write the data from the open file or volume.

Declaration

[Pascal]
    property OnWriteFileC : TCBFSFltWriteFileEventC;
    TCBFSFltWriteFileEventC = procedure(Sender : TObject; FileName: TCBString; var Position: Int64; var Buffer; var BytesToWrite: LongWord; Direction: LongWord; var FileContext: pointer; var HandleContext: pointer; var ProcessRequest: boolean) of object;
    type TCBString = {$ifdef UNICODE}UnicodeString{$else}WideString{$endif};

[C++ (Lib)]
    typedef void (*CBFSFltWriteFileEventC)(CBFSFilter* Sender, LPWSTR FileName, __int64 *Position, PVOID Buffer, LPDWORD BytesToWrite, CBFSFltDataFlow Direction, PVOID* FileContext, PVOID* HandleContext, LPBOOL ProcessRequest);

[C++ (VCL)]
    typedef void __fastcall (__closure *TCBFSFltWriteFileEventC)(System::TObject* Sender, TCBString FileName, __int64 &Position, void *Buffer, unsigned long &BytesToWrite, unsigned Direction, void* *FileContext, void* *HandleContext, bool &ProcessRequest);

[C++ (.NET)]
    public delegate void CBFSFltWriteFileEventC(CBFSFilter^ Sender, String^ FileName, Int64% Position, IntPtr Buffer, Int32% BytesToWrite, CBFSFltDataFlow Direction, IntPtr% FileContext, IntPtr% HandleContext, bool% ProcessRequest);

[C#]
    delegate void CBFSFltWriteFileEventC(CBFSFilter^ Sender, string FileName, ref long Position, IntPtr Buffer, ref Int32 BytesToWrite, CBFSFltDataFlow Direction, ref IntPtr FileContext, ref IntPtr HandleContext, ref bool ProcessRequest);

[VB.NET]
    Delegate Sub CBFSFltWriteFileEventC(ByVal Sender As CBFSFilter, ByVal FileName As String, ByRef Position As Long, ByVal Buffer As IntPtr, ByRef BytesToWrite As Int32, ByVal Direction As CBFSFltDataFlow, ByRef FileContext As IntPtr, ByRef HandleContext as IntPtr, ByRef ProcessRequest As Boolean)

Parameters

  • Sender - reference to the class that called the delegate/event handler
  • FileName - contains the name of the file
  • Position - the starting position to write the file data to
  • Buffer - the buffer to put the write data
  • BytesToWrite - the number of bytes to write from the file. The Buffer contains not more space, than this value.
  • Direction - specifies the direction of the data fllow (see below)
  • FileContext - the placeholder for the application-defined data, common to all concurrent file operations on the file
  • HandleContext - the placeholder for the application-defined data, local to each opened file handle
  • ProcessRequest - specifies, whether the request must be passed further to the underlying filters and the file system

Values of CBFSFltDataFlow

Description

This callback event is fired when the OS needs to write the data to the open file or volume, before the request is passed to the underlying file system. If you need to alter the data before writing, write the data (no more than BytesToWrite bytes) to the provided buffer. If your application writes the data elsewhere and doesn't write them to the underlying file system, set ProcessRequest parameter to false.

To report the failure and cancel writing operation you need to throw an instance of ECBFSFilterError (setting ProcessRequest to false won't cancel the operation).

.NET:
In .NET you should not try to replace the Buffer. Instead you need to copy the data to the provided buffer. You can use Array.Copy method for this.

Read more about contexts.

Attention: HandleContext can be empty, if the operation is performed by the cache manager or memory manager. In these situation, the operation is not associated with any particular handle.

Read more about cached and non-cached requests

Error handling

See Error handling topic for detailed information about how to report errors, which occur in the event handlers, back to CBFSFilter.

See also

OnWriteFileN