EldoS | Feel safer!

Software components for data protection, secure storage and transfer

File Context and Opens and Closes

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#27772
Posted: 12/24/2013 11:53:06
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

When I either create a file or Open it for the first time I place a pointer to a structure for that file into the FileHandleContext area provided by the CbFs file system. I use that structure in subsequent read and write calls. When I get the OnClose callback I free the memory for the structure and set the FileHandleContext pointer to NULL. Unfortunately I have found that this doesn't always work as I would like it to. As noted many time before in this Forum by Vladimir, Windows explorer opens a file for read when you are enumerating the directory. So, what I have found is that when I look at a file on my virtual disk and then right-click and choose "Open With .." and I open it with notepad, the file gets opened first by explorer and then sometimes, but not all the time, before explorer closes it, notepad opens the same file and therefore I place a new context for that file in the context area. Then, before I get the OnRead callback, explorer (not notepad) comes in and closes the file, which causes my OnClose callback to delete the file context and make the pointer to it NULL. This causes the read that comes next from notepad to fail.

This doesn't happen all the time, it is intermittent. I have SetSerializeCallbacks set to TRUE, so I don't think it is a multi-threading issue. Is there some way of being certain that the Close from Explorer will come before the Open from notepad? If that is not the case, then I may have to make my context a pushdown stack of structures and match up the Close call with the correct structure from the list of structures that I keep in the context stack. I hesitate to do that because it seems too complicated. Any help Vladimir or anyone else can give me in this area would be appreciated.
#27773
Posted: 12/24/2013 12:20:49
by Eugene Mayevski (EldoS Corp.)

Since version 4 FileContext and HandleContext are different entities. FileContext is shared between concurrent open/close operations and HandleConext is linked to each open operation.

Until version 4 there was one field available.

With FileContext you need to count references (i.e. count all open/close operations) and dispose the user object only when the count goes down to zero (i.e. the last handle to the file is closed).

It seems that you don't do reference counting and you have CallAllOpenCloseCallbacks set to true. This causes the problem if you dispose the user object when there exist opened handles to the file.


Sincerely yours
Eugene Mayevski
#27784
Posted: 12/26/2013 15:38:30
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

I am now doing reference counting and that seems to work much better. I still have a problem with Word or Excel documents as they create temporary files used for backup and recovery that my virtual disk does not handle very well. But, I believe that is a problem with my database system, not CbFs, although if you know of anything related to Word or Excel documents that might help me figure out what is wrong I'd appreciate hearing about it.
#27785
Posted: 12/26/2013 23:59:33
by Eugene Mayevski (EldoS Corp.)

There's nothing with Office that would require special handling other than temporary files (they can be distinguished using FILE_ATTRIBUTE_TEMPORARY flag if memory serves) could possibly (if you prefer) be created on the real disk or in memory for speed and efficiency (i.e. there's no need to put them to the database). On the other hand keeping the temporary files on the real disk is sort of delayed write, so you need to ensure that the file can be later flushed to the DB.


Sincerely yours
Eugene Mayevski
#27786
Posted: 12/27/2013 12:50:55
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

The problem was that the file contexts were getting confused between the opens and the reads and writes. The file context that I create at open time contains a file descriptor that is significant to my database system and since I was now doing reference counting when I did the opens the file descriptor was stale when it arrived at the read function. So, what I did was create a queue of file structures and passed the queue as the file handle context and used the reference count as an index into the queue. This allowed me to pick up the correct file descriptor in the read and write functions. Everything seems to be working fine now, Thank you for your help.
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 1517 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!