WriteFile Event

Fires when the OS needs to write data to an open file.


class CBFSWriteFileEventParams {
  const QString &FileName();
  qint64 Position();
  const void *Buffer();
  qint64 BytesToWrite();
  qint64 BytesWritten();
  void SetBytesWritten(qint64 lBytesWritten);
  qint64 HandleInfo();
  void *FileContext();
  void SetFileContext(void *lpFileContext);
  void *HandleContext();
  void SetHandleContext(void *lpHandleContext);
  int ResultCode();
  void SetResultCode(int iResultCode);
  int EventRetVal();
  void SetEventRetVal(int iRetVal);
// To handle, connect one or more slots to this signal. void WriteFile(CBFSWriteFileEventParams *e);
// Or, subclass CBFS and override this emitter function. virtual int FireWriteFile(CBFSWriteFileEventParams *e) {...}


This event fires when the OS needs to write data to the already-open file specified by FileName.

To handle this event properly, applications should write BytesToWrite bytes of data to the specified file, copying it from the memory region pointed to by Buffer. Writing must begin at the specified Position in the file, and when writing is complete, applications must set BytesWritten to reflect the actual number of bytes written to the file. Applications must not attempt to copy more than BytesToWrite bytes of data from Buffer.

Please refer to the Buffer Parameters topic for more information on how to work with memory buffer event parameters.

Note: While it is technically possible for an application to write fewer than BytesToWrite bytes of data, doing so is abnormal, and should be avoided. Most processes treat write requests as "all or nothing", so writing less data than requested is likely to cause an ungraceful failure.

The HandleInfo parameter carries a handle to an object with information about the file handle. While within the event handler, it can be used to call any of the following methods: GetHandleCreatorProcessId, GetHandleCreatorProcessName, GetHandleCreatorThreadId, or GetHandleCreatorToken. (This parameter may be absent, in which case it will be 0.)

The FileContext and HandleContext parameters are placeholders for application-defined data associated with the file and specific handle, respectively. Please refer to the Contexts topic for more information. (HandleContext may be absent, in which case it will be nullptr.)

The ResultCode parameter will always be 0 when the event is fired. If the event cannot be handled in a "successful" manner for some reason (e.g., a resource isn't available, security checks failed, etc.), set it to a non-zero value to report an appropriate error. Please refer to the Error Reporting and Handling topic for more information.

Note: In most cases, the event is fired when the cache needs to write the data to the filesystem. This happens asynchronously, later than process(es) called the WriteFile() function or alternatives. For such asynchronous write events, the result code returned by the event handler does not get back to the process or processes that wrote the data.

Copyright (c) 2022 Callback Technologies, Inc. - All rights reserved.
CBFS Connect 2020 Qt Edition - Version 20.0 [Build 8348]