Skip to contentSkip to conversation

Detecting changes in a directory tree

DISCUSSION Jeroen van Disseldorp 2 participants 3 messages Jan 16, 2003 – Jan 17, 2003

lore
Share & tools
lore
#0 lore raw

Hi,

For an application I'm writing I need to know if files in a certain directory tree were modified and/or deleted by another process. I assume that that tree is mounted on the machine that my app is running on. The device it has mounted on can be a local HD, but it can also be hosted remotely and mounted over nfs.

I know of FAM, but this is documented to only watch a directory 1 level deep, and I need the whole tree to be monitored. Does anyone know a solution for this? Does the kernel provide facilities for this?

(Please send me replies directly or via CC, as I am not subscribed to the kernel mailinglist)

Regards,
Jeroen van Disseldorp mailto:[email protected]

Signature · 1 line
Be the change you wish to see in the world    -- Gandhi
#1 lore raw
Quoted 1 line · Jeroen van Disseldorp

Hi,

Hi Jeroen,

Quoted 10 lines

For an application I'm writing I need to know if files in a certain directory tree were modified and/or deleted by another process. I assume that that tree is mounted on the machine that my app is running on. The device it has mounted on can be a local HD, but it can also be hosted remotely and mounted over nfs.

I know of FAM, but this is documented to only watch a directory 1 level deep, and I need the whole tree to be monitored. Does anyone know a solution for this? Does the kernel provide facilities for this?
...

with a kernel >= 2.4.19 dnotify [1] might do what you want.

Quoted 2 lines

Regards,
Jeroen van Disseldorp mailto:[email protected]

cu
Adrian

[1] http://www.student.lu.se/~nbi98oli/dnotify.html

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#2 lore raw
Quoted 1 line · Adrian Bunk

with a kernel >= 2.4.19 dnotify [1] might do what you want.

Close, but is doesn't do it quite for me. I understand the problem of traversing inodes back up the tree, once they have changed, to see whether someone wants to receive an event. However I am not convinced that this is necessary. The idea I had was the following:

I would like to have a passthrough kind of filesystem (lets call is myfs for now) that can mount other parts of the filesystem and just maps everything to the original tree. For instance, I would mount /var on /mnt/var, using myfs. Everything from /mnt/var is directly mapped to /var.

The clue of this is that myfs *knows* about the notification, because it has to send notification to userspace for *every* inode. So if anything is written in /mnt/var, it can notify userspace. BTW for my app it would be acceptable that direct changes in /var don't lead to any events.

I haven't thought out the interface to userspace yet, but I think that can be worked out. Let me know if I'm making any sense here.

Regards,
Jeroen mailto:[email protected]

Signature · 1 line
Be the change that you want to see in the world    -- Gandhi