EldoS | Feel safer!

Software components for data protection, secure storage and transfer

NULL context in OnCloseFile() event

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#20429
Posted: 06/12/2012 12:38:58
by Rob Zimmerman (Basic support level)
Joined: 06/12/2012
Posts: 5

Scenario: I'm going through the eval by creating a simple "mirror" file system. For each callback I'm simply calling the appropriate Win32 call and performing the operation on the local disk.

Example: OnOpenFile- I'm calling CreateFile() and stashing the HANDLE into the context for later use (writes, reads, close, etc).

I also have a std::map of HANDLE/std::wstring to know what handles belong to what file/directory. I dump that out for debugging after each callback. (C:\BigDrive is the "root" for the mirror drive)

What I'm seeing:
Using the CLI I cd into my test directory (T:\test).

Code
06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsGetFileInfo()
06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:28:44 - DEBUG - FSHook - \booya
06/12/2012 13:28:44 - INFO - FSHook - 2 entries
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsCloseFile()
06/12/2012 13:28:44 - DEBUG - FSHook - \booya
06/12/2012 13:28:44 - INFO - FSHook - 1 entries
000001F4
C:\BigDrive\

06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsEnumerateDirectory()
06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsCloseEnumeration()
06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:28:44 - DEBUG - FSHook - \booya
06/12/2012 13:28:44 - INFO - FSHook - 2 entries
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsCloseFile()
06/12/2012 13:28:44 - DEBUG - FSHook - \booya
06/12/2012 13:28:44 - INFO - FSHook - 1 entries
000001F4
C:\BigDrive\

06/12/2012 13:28:44 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:28:44 - DEBUG - FSHook - \booya
06/12/2012 13:28:44 - INFO - FSHook - 2 entries
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya


OK, all is good. As we'd expect, the file system keeps \booya open since we're currently CD'd into it. Now let's cd into a sub-directory (test7)

Code
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsGetFileInfo()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya\test7
06/12/2012 13:31:18 - INFO - FSHook - 3 entries
00000120
C:\BigDrive\booya\test7
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsEnumerateDirectory()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseEnumeration()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya\test7
06/12/2012 13:31:18 - INFO - FSHook - 2 entries
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsEnumerateDirectory()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseEnumeration()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsEnumerateDirectory()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseEnumeration()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya\test7
06/12/2012 13:31:18 - INFO - FSHook - 3 entries
00000120
C:\BigDrive\booya\test7
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya\test7
06/12/2012 13:31:18 - INFO - FSHook - 2 entries
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsOpenFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya\test7
06/12/2012 13:31:18 - INFO - FSHook - 3 entries
00000120
C:\BigDrive\booya\test7
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya

06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsSetFileAttributes()
06/12/2012 13:31:18 - DEBUG - FSHook - Inside CbFsCloseFile()
06/12/2012 13:31:18 - DEBUG - FSHook - \booya
06/12/2012 13:31:18 - INFO - FSHook - 3 entries
00000120
C:\BigDrive\booya\test7
000001F4
C:\BigDrive\
00000328
C:\BigDrive\booya



Here's where I see the problem. The last call to OnCloseFile() is being called for \booya but the context handle is NULL. I've checked through my code about 10 times now and am certain I'm NOT setting the context to NULL in any other place other than
OnCreateFile() and OnOpenFile().

Is it normal for OnCloseFile() to hand out a NULL context in this scenario? If so, how do you suggest managing handles to previously opened files/directories? Or, maybe I just hit a bug :)

Thanks for the help...so far I'm pretty impressed with this library...very good stuff.

~Rob
#20430
Posted: 06/12/2012 13:38:13
by Rob Zimmerman (Basic support level)
Joined: 06/12/2012
Posts: 5

You would have thought after 12 years of coding I would have learned to step away from the monitor for a few minutes to give my brain a rest :)

I found the issue. In the OnEnumerationClose() callback I was setting the FileInfo context to NULL.

*commence smacking forehead against desk*

Reply

Statistics

Topic viewed 563 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!