Where's CreationDisposition parameter and how do I distinguish between Open and Create operations?
In order to simplify the user mode interface Callback File System handles CreationDisposition itself and calls either OnCreateFile or OnOpenFile callback/event. CBFS knows whether the created/opened file exists because the information about it is obtained earlier by means of OnGetFileInfo callback/event. Also CBFS driver has an internal meta data cache where it holds information about recently used files/directories.
So if your OnCreateFile handler is called, you need to create the file. If the file exists and CBFS knows it, receiving OnCreateFile means that the file was requested for opening with "CreateAlways" flag, which means that you need to truncate the existing file. If you don't want to truncate the file for whatever reason, you should return ERROR_ALREADY_EXISTS error by throwing the exception with corresponding error code as parameter.