Forum Topic - How to get notified if a new file is created inside a dir?: (3 Items)
   
How to get notified if a new file is created inside a dir?  
Hello All,

I have a requirement to get notified(i do not know how) if a file is created inside say /dev/umass/xxx

This is required for my app to spawn other drivers. Bascically i could use a loop and see if there were any new entry, 
but this solution does not look good and will consume more CPU.

Can someone suggest a better method to monitor a directory path for dynamic file creation/removal?

Eg: On file creation of /dev/umass/usb01100 & removal of /dev/umass/usb01100?

Thanks in advance for your help.

Regards,
Lavin
Re: How to get notified if a new file is created inside a dir?  
Short of using pps - which requires very "special" files - the only way to detect normal file changes is to create a 
resource manager and attach to the "root" of the namespace you want to watch.  You can then register handlers for any of
 the _IO_*  messages you want to "see" ( maybe _IO_OPEN, _IO_CLOSE_OCB and _IO_CLOSE_DUP?)   The handler(s) you create 
in the resource manager must have some mechanism to "notify" your monitor process.

You will have to be able to "trace back" from a "close"  message back to a structure containing the name.   You need to 
capture/save the name at _IO_OPEN.

This is complicated by the fact that you are interested in "removable" filesystems...

Dennis
Re: How to get notified if a new file is created inside a dir?  
Dennis! Thanks for your suggestion, let me think in the direction which you have proposed.