I have a requirement, where based on some criteria, writes should be blocked, but at the same time move/replacing this file with another version of this file should succeed (Effectively I want to maintain this file as a view/read only copy. At the same time, if somebody modified it, then I want to get the latest version for this file).

In order to achieve this I tried with both methods.

1) Setting the file readonly attribute:
With this approach, I was able to block the user from writing, but the move is failing with access denied permission.

You can try the second variant but with setting the CallbackFileSystem.FileCacheEnabled property to false or setting the CallbackFileSystem.CachePolicyWriteThrough property to true (in the last case the caching is still enabled but for any write operation the OnWrite callback will be called immediately).
Unfortunately there is one case when it doesn't work "as expected" - when the file is written by the use of the memory mapped section (MapViewOfFile, etc). In this case file data, which is being written, is written in memory first (and CBFS doesn't know about this). And only later the system component "memory manager" flushes the data to the file. Of course the OnWrite callback will be called, but if you finish it with error then the memory manager will decide to repeat the operation several times and then show on the active desktop an error message (something like this i.imgur.com/iBA8D9A.png). Although for this case you can try to return "success" from the OnWrite callback if the GetOriginatorProcessId == 4 (which means that the SYSTEM process is performing write).

Thanks for the quick response. I tried both options and none of them is triggering the OnWriteFile Event. This event is getting for the other file, but not the one I am interested in(I have a DB file inside my SolidFS and this event is getting triggered for the db journal file). So most probably, it appears to me that the cache is still in place and the CBFS might be doing a lazy write.

So just wondering any other approach through which we can achieve this functionality.

We use cookies to help provide you with the best possible online experience. By using this site, you agree that we may store and access cookies on your device. You can find out more about and set your own preferences here.