Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jul 2002 02:18:29 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Sean Hamilton <sh@planetquake.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Filesystem hook
Message-ID:  <3D392AE5.25FBF155@mindspring.com>
References:  <001501c22fa7$fd418a50$f019e8d8@slugabed.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Sean Hamilton wrote:
> In Windows, there is a filesystem hook, ie, applications can ask to be
> notified about changes to a given file system / structure. Thus, a directory
> listing could automatically update, etc.
> 
> Does FreeBSD offer a similar mechanism?

If you are talking about the IFSMgr_InstallFileSystemApiHook()
IFSMgr.VxD entry point, then no, FreeBSD does not have a
similar mechanism available.  The closest you can get is to
use a modified nullfs, and intercept the calls you want, but
to do this requires an explicit mount of the nullfs to enable.

If you just want modification events, you can get some events
as kevent() events, but not all of them.  Which events you get
(if any) will vary widely from filesystem to filesystem, and
most of the events are per-object.  That basically means that
you would need to monitor each object by getting an open file
descriptor; sometimes that would be mutually exclusive (e.g.
if the file was attempted to be opened O_EXCL/O_EXLOCK, the
previous open would cause the attempt to fail).  The number
of file descriptors required to monitor just directory events
on a large FS could very quickly become prohibitive, unless
you limited yourself to directories on which file browser
views were open (for example).


Likewise, you can't monitor creation events easily (no way to
have an open descriptor on a non-existant file that's about
the exist 8-)).

Finally, the interface and events are fairly limited, making
them only useful for monitoring.  So, for example, if you
wanted to require a password for deleting any file with the
letter "q" in its name, you would basically have to add events
and a communication channel to your user space program that
would popup the password prompt, etc..

If your example of monitoring a directoy on which a file browser
window is open for modifications is the full extent of what you
wanted to do, and you didn't want to actually intercept events,
only monitor them, then kevent() is probably the correct FreeBSD
approach for most cases, but you will need to be prepared to deal
with FS's that don't support it the same way you would deal with
it if there were no such facility (e.g. using a timer to drive a
stat() of a directory, etc.).

FWIW, if this is for AppleTalk volume modification notification,
very early on in FreeBSD's life, we added a volume modification
timestamp to the superblock, so that the AppleTalk clients would
not need to poll once per file browser window open on a directory,
once every 11 seconds (the client default).  See the statfs(2)
manual page for details.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D392AE5.25FBF155>