Discuss this help topic in CBFS Forum

OnReadFile event/delegate/callback

Filter:

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

CallbackFileSystem     See also    

Overview

This event is fired when the OS needs to read the data from the open file or volume.

Declaration

[Pascal]
    property OnReadFile : TCbFsReadFileEvent;
    TCbFsReadFileEvent = procedure( Sender : TObject; FileInfo: TCbFsFileInfo; Position: Int64; var Buffer; BytesToRead: LongWord; var BytesRead: LongWord ) of object;

[C++ (Lib)]
    void (__stdcall *CbFsReadFileEvent)(void* Sender, CbFsFileInfo* FileInfo, __int64 Position, void * Buffer, unsigned long BytesToRead, unsigned long & BytesRead );

[C++ (VCL)]
    typedef void (__closure *TCbFsReadFileEvent)( System::TObject* Sender, TCbFsFileInfo* FileInfo, __int64 Position, void * Buffer, unsigned long BytesToRead, unsigned long & BytesRead );

[C++ (.NET)]
    public __delegate void CbFsReadFileEvent( CallbackFileSystem^ Sender, CbFsFileInfo^ FileInfo, Int64 Position, CbFsManagedBuffer Buffer, Int32 BytesToRead, Int32% BytesRead );
    typedef array<unsigned char>^ CbFsManagedBuffer;

    public __delegate void CbFsReadFileNativeEvent( CallbackFileSystem^ Sender, CbFsFileInfo^ FileInfo, Int64 Position, IntPtr Buffer, Int32 BytesToRead, Int32% BytesRead );

[C#]
    public void CbFsReadFileEvent( CallbackFileSystem Sender, CbFsFileInfo FileInfo, Int64 Position, byte[] Buffer, Int32 BytesToRead, ref Int32 BytesRead );

    public void CbFsReadFileNativeEvent( CallbackFileSystem Sender, CbFsFileInfo FileInfo, Int64 Position, IntPtr Buffer, Int32 BytesToRead, ref Int32 BytesRead );

[VB.NET]
    Sub CbFsReadFileEvent( ByVal Sender As CallbackFileSystem, ByVal FileInfo As CbFsFileInfo, ByVal Position As Int64, ByVal Buffer As Byte(), ByVal BytesToRead As Int32, ByRef BytesRead As Int32 )

    Sub CbFsReadFileNativeEvent( ByVal Sender As CallbackFileSystem, ByVal FileInfo As CbFsFileInfo, ByVal Position As Int64, ByVal Buffer As IntPtr, ByVal BytesToRead As Int32, ByRef BytesRead As Int32 )

[Java]
    void ICbFsFileEvents.onReadFile( CallbackFileSystem sender, CbFsFileInfo fileInfo, long position, byteArrayRef buffer, int bytesToRead, intRef bytesRead );

Parameters

  • Sender - reference to the class that called the delegate/event handler
  • FileInfo - contains the information about the file
  • Position - the starting position to read the file data from
  • Buffer - the buffer to put the read data
  • BytesToRead - the number of bytes to read from the file. The Buffer contains not more space, than this value.
  • BytesRead - the event handler must set the parameter to the number of bytes actually read from the file.

Description

This event is fired when the OS needs to read the data from the open file or volume. Write the data (no more than BytesToRead bytes) to the povided Buffer. Put the actual number of read bytes to BytesRead. Note, that unless you create the virtual disk for some specific application, your callback handler should be able to provide exactly BytesToRead bytes of data. Reading less data than expected is an unexpected situation for many applications, and they will fail if you provide less bytes than requested.
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.

Error handling

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

See also

MaxReadBlockSize property     GetHandleInfo method     OnCreateFile event     OnOpenFile event     OnWriteFile event    

Discuss this help topic in CBFS Forum