Search code examples
macosnetwork-programmingfsevents

How to monitor file changes on network mapped drives?


From what I see, network mapped drives appear as subfolders of the /Volumes folder.

What is the proper way to get file changes updates (delete/create/update) from this folder?

Would /dev/fsevents work for that?

How does Finder know about the changes?


Solution

  • You're correct, OS X mounts the network drives in /Volumes

    The way to get file change updates is to use File System Events API. It is a C-based API where you would watch for all changes in specific directories (or even /).

    You would create the stream with FSEventStreamCreate and starting it with FSEventStreamScheduleWithRunLoop

    Be prepared to dig into the header-file as there is more documentation on it as in the Reference documentation

    From what I can tell, Finder probably uses some internal API or the kernel queues which are more complex to setup than the higher-level API of FSEvents.h

    There is a nice GUI to helping you see how the whole events come in. It's called fseventer by fernlightning (not yet Yosemite ready)