CBFS Filter 2020 C++ Builder Edition

Questions / Feedback?

BeforeCreateFile Event

Fires before a file or directory is created.

Syntax

typedef struct {
  String FileName;
  int DesiredAccess;
  int Attributes;
  int ShareMode;
  int Options;
  int CreateDisposition;
  bool VirtualFile;
  bool ProcessRequest;
  int ResultCode;
} TcbfCBFilterBeforeCreateFileEventParams;

typedef void __fastcall (__closure *TcbfCBFilterBeforeCreateFileEvent)(System::TObject* Sender, TcbfCBFilterBeforeCreateFileEventParams *e);

__property TcbfCBFilterBeforeCreateFileEvent OnBeforeCreateFile = { read=FOnBeforeCreateFile, write=FOnBeforeCreateFile };

Remarks

This event fires before the file or directory specified by FileName is created. Please refer to the File Create/Open Events topic for more information about how the component determines whether to fire this event or BeforeOpenFile.

Applications may use this event to modify the request's parameters, or to block the request entirely. To do the latter, set ProcessRequest to false; this has the same effect as returning ACCESS_DENIED.

Applications that make use of virtual files should, if necessary, use this event to perform any actions needed to create a virtual file. Please refer to the VirtualFile parameter's description, below, for additional information.

Applications only need to handle this event if they've added a standard filter rule that includes the FS_CE_BEFORE_CREATE flag. Please note that applications must have the FilterOwnRequests configuration setting enabled if they wish to filter their own file/directory creation requests.

The initial values of the DesiredAccess, Attributes, ShareMode, Options, and CreateDisposition parameters reflect the values that were passed for the similarly-named parameters of the Windows API's CreateFile function (or, more accurately, the values carried by the IRP_MJ_CREATE IRP). Please refer to Microsoft's documentation for more information.

To determine whether the request is for a file or a directory, compare Attributes against the Windows API's FILE_ATTRIBUTE_DIRECTORY constant, like so:

// Check whether the request is for a file or a directory.
bool isDirectory = Attributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY;
FILE_ATTRIBUTE_DIRECTORY will only be present if it was specified by the calling process; its presence or absence does not indicate the real presence of the attribute on the file or directory on disk.

To determine whether a file will be deleted when its last handle is closed, compare Options against the Windows API's FILE_FLAG_DELETE_ON_CLOSE constant, like so:

// Check whether the file will be deleted on close.
bool deleteOnClose = Options & FILE_FLAG_DELETE_ON_CLOSE == FILE_FLAG_DELETE_ON_CLOSE;

To prevent a file or directory from being opened, set the ResultCode parameter to a non-zero value (typically ERROR_ACCESS_DENIED (5)).

The VirtualFile parameter specifies whether a virtual file is being created (i.e., a file that should not exist on and/or be opened from the disk). If the specified file is known to be virtual (i.e., it has been opened as virtual already), this parameter will be true initially; otherwise, it will be false initially, in which case it may be set to true to create the specified file as virtual. Please refer to the Virtual Files topic for more information.

Applications that change the value of the VirtualFile parameter must do so consistently; i.e., a specific file must always be either virtual or not virtual. It is not possible to make a file virtual for one set of requests and non-virtual for another set of requests; doing so can lead to undefined behavior in the component or the OS.

The ProcessRequest parameter controls whether the request is sent onwards for further processing by subsequent filter drivers and the filesystem; it is true by default.

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.

This event is fired synchronously; please refer to the Event Types topic for more information.

 
 
Copyright (c) 2020 Callback Technologies, Inc. - All rights reserved.
CBFS Filter 2020 C++ Builder Edition - Version 20.0 [Build 7543]