From owner-freebsd-hackers Sat Jul 20 2:19:36 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D41A537B400 for ; Sat, 20 Jul 2002 02:19:33 -0700 (PDT) Received: from harrier.mail.pas.earthlink.net (harrier.mail.pas.earthlink.net [207.217.120.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id 69C8643E64 for ; Sat, 20 Jul 2002 02:19:33 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from dialup-209.244.104.88.dial1.sanjose1.level3.net ([209.244.104.88] helo=mindspring.com) by harrier.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 17VqOW-00056i-00; Sat, 20 Jul 2002 02:19:21 -0700 Message-ID: <3D392AE5.25FBF155@mindspring.com> Date: Sat, 20 Jul 2002 02:18:29 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Sean Hamilton Cc: freebsd-hackers@freebsd.org Subject: Re: Filesystem hook References: <001501c22fa7$fd418a50$f019e8d8@slugabed.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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