EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Correct use of NotifyDirectoryChange by type of change

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#34069
Posted: 07/17/2015 13:09:06
by Paolo Manili (Basic support level)
Joined: 02/23/2015
Posts: 16

Hi everyone,

I understand that NotifyDirectoryChange has to be used whenever an external change occurs to the structure mapped by CBFS, but it is a bit vague which kind of notification is correct for each case.
I know the topic has been covered before and I have read most of the relevant posts, but I am still at a loss as to what the correct behavior for some cases is.

First: I understand that calling Modified on folders causes Handle invalidation for all children of the notified path, we have therefore very nearly stopped sending that. Should we be sending modified for each child?

Second: What should be sent if icons or overlays are to be reloaded?

Third: Is fanModifiedMetaData only dedicated to FileAttributes or does it involve folder size recalculation too? or does it work only for files?

Four: Is it correct to notify renames as fanRemoved (oldPath) fanAdded (newPath) or is there a better way?

I tried notifying with the SHChangeNotify Windows API, but if overused it tends to break Windows refresh calls even outside of the CBFS path.

As usual thanks in advance for any help you can provide,
Paolo Manili

PS. I found in another thread that NotifyDirectoryChange requires Case Sensitive paths to be specified, but this information is missing in the latest CBFS chm guide.
#34070
Posted: 07/17/2015 13:24:17
by Eugene Mayevski (EldoS Corp.)

Quote
paolo.manili wrote:
First: I understand that calling Modified on folders causes Handle invalidation for all children of the notified path, we have therefore very nearly stopped sending that. Should we be sending modified for each child?


You need to report exactly the information that has changed. If it's file attributes or times, you report MetaDataChanged for the file. If it's file contents, you report Modified for the file.

Quote
paolo.manili wrote:
Second: What should be sent if icons or overlays are to be reloaded?


The quirks of Explorer are beyond our control and we don't have any particular answer to this question. Maybe File Modified should be reported, but whether the icon is refreshed, is up to Explorer. If you discover something, you are welcome to post your findings here.

Quote
paolo.manili wrote:
Third: Is fanModifiedMetaData only dedicated to FileAttributes or does it involve folder size recalculation too? or does it work only for files?


What is "folder size recalculation"? Is it something performed by Explorer? I don't know if this flag will be sufficient for Explorer. It depends on how Explorer monitors the disk.

In general, when you call NotifyDirectoryChange, the kernel-mode driver notifies the OS. Explorer is a regular application, it's not the OS core (there exist versions of Windows that don't have a GUI and Explorer). We do not have information about behavior of any applications that are not the part of the OS core. I believe there exist ways to enumerate open Explorer windows and somehow trigger their refresh from code, but this is beyond our area of expertise.

One more important factor is that Explorer behavior differs from version to version and also depends on what disk type and characteristics are set.

Quote
paolo.manili wrote:
Four: Is it correct to notify renames as fanRemoved (oldPath) fanAdded (newPath) or is there a better way?


I am leaving this for Volodymyr Zinin to answer.

Quote
paolo.manili wrote:
PS. I found in another thread that NotifyDirectoryChange requires Case Sensitive paths to be specified, but this information is missing in the latest CBFS chm guide.


Hmm, I'd like to see that statement - maybe there's some misunderstanding or badly written text. The notification should be case sensitive when you have two directories whose names differ only in case (I know this is possible somehow, though I couldn't create such directories in Explorer now). But otherwise I don't remember such requirements (again, will check this with Volodmyr and update the docs if needed).


Sincerely yours
Eugene Mayevski
#34074
Posted: 07/18/2015 03:59:17
by Volodymyr Zinin (EldoS Corp.)

When the flags fanAdded, fanRemoved, fanModified are used and the file is opened at that time then CBFS marks handles for this file as invalid. So any operations by the use of these handles return the "handle is invalid" error. The only successful operation will be CloseHandle. In the case of fanMetadataModified the handles are not marked invalid. "Metadata" means "file attributes" and "file times".
The file size depends on file data and if it has been changed then it means that the file data has been changes (already invalid) too. So in this case fanModified should be used.

If you use fanAdded, fanRemoved, fanModified for a parent directory then all opened files and subdirectories inside this one will be marked as invalid (their handles). But the system will be notified about adding/changing/removing for only this one specified directory.

The difference between fanModified and fanMetadataModified is that, in addition to notification of the system about the file modification, for fanModified the handles are marked invalid.

Quote
Four: Is it correct to notify renames as fanRemoved (oldPath) fanAdded (newPath) or is there a better way?

It is correct and it seems this is the only way.

Quote
I found in another thread that NotifyDirectoryChange requires Case Sensitive paths to be specified, but this information is missing in the latest CBFS chm guide.

Based on the code if the flags ShortFileNameSupport and CaseSensitiveFilenames are specified during the storage creation then NotifyDirectoryChange works with file names as case sensitive. In the other cases it is case insensitive.
#34088
Posted: 07/22/2015 10:19:20
by Paolo Manili (Basic support level)
Joined: 02/23/2015
Posts: 16

Hi,

thank you very much, this clarification has been of great help in reducing the number of refresh calls.

We still have a few odd cases where refresh doesn't occur (mostly folder rename or file extension changes), but they are likely to be issues in our implementation.
Once more thanks for the prompt and complete answer.

Best Regards,
Paolo Manili

Reply

Statistics

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