[pickup] [RFC/PATCH] Nonotify - A simplistic way to determine directory content changes



Hi,

Some time ago there was a thread I refer to in the subject
(http://mail.gnome.org/archives/nautilus-list/2004-June/msg00011.html
and further).
I'm also very interested in this subject. I'm working on a HAL
automounter (some code by me was ripped from the HAL mailing list and
used in that thread ;-)
http://mail.gnome.org/archives/nautilus-list/2004-June/msg00063.html
), and I'd also need a way to get umounting and ejecting of removable
media done in a somehow more user-friendly way (not to mention "like
MS does it", sorry).

We've had some discussion on this on our mailing list
(http://sourceforge.net/mailarchive/forum.php?forum_id=40939), and
found out some possible solututions:

1. There is the MMC2 eject event, that's also handled by HAL now, but
only few devices support it
(http://freedesktop.org/pipermail/hal/2004-May/000237.html and
further, also in June).
2. Just unlock the drive (using ioctl()), and umount *when the media
is already removed*, i.e. after we got the HAL call that the disc was
removed, which is, in fact, bad. This is the way we handle stuff now
tough.

Currently we're looking for a better solution (solution 1 is good, but
not widely-usable). What I'd like to achieve is this: lock the drive
whenever it's in use, unlock when it isn't anymore, quite simple.
The only method to check whether a drive is in use I know of is
looking in /proc/[pids]/fd/*, and using readlink on all symlinks.
I started to implement this using FAM, but FAM only allows scanning
one level deep. What I do now: scan /proc, if I get an event there,
check whether a numerical-named dir was added, if so, start monitoring
the 'fd' dir beneath it, and so on.
This is not a very good solution tough. The current code
(http://cvs.sourceforge.net/viewcvs.py/ivman/ivman_ng/src/libProcNotification/)
isnt working yet, but is already a mess now (I'll rewrite it).
I'm afraid this causes a lot of overhead tough. Every time a file is
created under /proc or under /proc/[pid]/fd, I check whether it's a
symlink, if so, readlink it, check whether it links to  a device we
had to monitor, or to a file under a path (mountpoint) we had to
monitor, if so, counter++. If its not a symlink, its a dir under
/proc, start to monitor /proc/[thepid]/fd, if things get deleted, take
care of that, and counter--, and so on (I know this is confusing,
don't know really well how to explain this).
The problem is this event gets triggered for *every* accessed file,
whilst the amount of 'good calls' (i.e. the calls we can actually
*use*) is very small, whilst processing every call takes a while.

So what I'd like to ask: does anyone knows a better solution for this?
Summarized: get an event whenever a device is in use, or a file in a
subdirectory of the mountpoint of that device. I didn't find any good,
to the point and fast solution yet.

Some more info is in my blog, planet.freedesktop.org

Regards, and thanks for any comments/help/suggestions,

Nicolas

PS sorry for this confusing message, I'm not a native speaker.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]