From: "Rüdiger Klaehn" <rudi@lambda-computing.de>
To: ivern@acm.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: File change notification
Date: Wed, 31 Dec 2003 19:48:53 +0100 [thread overview]
Message-ID: <3FF31A15.4070307@lambda-computing.de> (raw)
In-Reply-To: <3FF31366.30206@acm.org>
[-- Attachment #1: Type: text/plain, Size: 2460 bytes --]
Javier Fernandez-Ivern wrote:
> Rüdiger Klaehn wrote:
>
>> I have been wondering for some time why there is no decent file
>> change notification mechanism in linux. Is there some deep
>> philosophical reason for this, or is it just that nobody has found
>> the time to implement it? If it is the latter, I am willing to
>> implement it as long there is a chance to get this accepted into the
>> mainstream kernel.
>
>
> Well, there's fam. But AFAIK that's all done in user space, and your
> approach would be significantly more efficient (as a matter of fact,
> fam could be modified to use your change device as a first level of
> notification.)
>
Fam is a user space library that has some nice features such as network
transparent change notification. It currently uses the dnotify mechanism
if the underlying kernel supports it, but as I mentioned the dnotify
mechanism requires an open file handle and works only for single
directories. If the underlying os does not support dnotify, fam resorts
to polling for file changes (yuk!).
When I have the basics worked out for the new mechanism, one thing I
would like to do is to modify the fam library to use it. That would be a
good way to test it, and it would also immediately benefit the big
desktop environments which use fam.
> I'll be interested in testing this, or (if you wish) help get it done.
> I'm a kernel hacking newbie at the moment, but I have tinkered around
> enough with the VFS to be able to work on this. Up to you.
>
Any help is appreciated. At the moment I am quite happy about what is
being logged, but I am not sure how to best expose this to the
interested user space processes. A device was the easiest way, and so
that is what I used. Other possibilities would be a file in /proc or
something completely different. I got the impression that dbus might be
useful for this, but I have no idea how to use it.
If you want to help me, just apply the patch and see wether it works for
you. You could also take a look at the code and see if you see something
completely broken.
best regards and a happy new year,
Rüdiger
p.s. I attached a small test program. It just reads the contents of the
/dev/inotify device and prints them in (somewhat) human readable form.
For example to watch for changes in .txt files I would use inotify_test
| grep txt. This would print out a line whenever a txt file anywhere on
a system has been created or changed.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: inotify.h --]
[-- Type: text/x-chdr; name="inotify.h", Size: 562 bytes --]
/*
* Inode notification for Linux
*
* Copyright (C) 2003,2004 Rüdiger Klaehn
*/
#define IN_ACCESS 0x00000001 /* Node accessed */
#define IN_MODIFY 0x00000002 /* Node modified */
#define IN_CREATE 0x00000004 /* Node created */
#define IN_DELETE 0x00000008 /* Node removed */
#define IN_RENAME 0x00000010 /* Node renamed */
#define IN_ATTRIB 0x00000020 /* Node changed attibutes */
#define DNAME_LEN 32
typedef struct
{
unsigned long event;
unsigned long file_ino;
unsigned long src_ino;
unsigned long dst_ino;
unsigned char name[DNAME_LEN];
} in_info;
[-- Attachment #3: inotify_test.c --]
[-- Type: text/x-csrc, Size: 1001 bytes --]
#include <stdio.h>
#include "inotify.h"
void geteventname(unsigned long event,char *buffer,int n)
{
unsigned long events[6]=
{
IN_ACCESS,
IN_MODIFY,
IN_CREATE,
IN_DELETE,
IN_RENAME,
IN_ATTRIB
};
const char *names[6]=
{
"IN_ACCESS",
"IN_MODIFY",
"IN_CREATE",
"IN_DELETE",
"IN_RENAME",
"IN_ATTRIB"
};
int i;
strncpy(buffer,"",n);
for(i=0;i<6;i++)
{
if(event&events[i])
{
if(strlen(buffer)>0)
strncat(buffer,"|",n);
strncat(buffer,names[i],n);
}
}
}
int main()
{
FILE *file;
in_info info;
int len;
char eventname[256];
file=fopen("/dev/inotify","rb");
if(!file)
{
printf("Error: could not open /dev/inotify!\n");
return -1;
}
while(1)
{
len=fread(&info,1,sizeof(info),file);
if(len==sizeof(info)) {
info.name[DNAME_LEN-1]=0;
geteventname(info.event,eventname,255);
printf("%s %lu %lu %lu %s\n",
eventname,
info.file_ino,
info.src_ino,
info.dst_ino,
info.name);
}
usleep(200);
}
fclose(file);
}
next prev parent reply other threads:[~2003-12-31 18:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-31 16:42 File change notification Rüdiger Klaehn
2003-12-31 18:20 ` Javier Fernandez-Ivern
2003-12-31 18:48 ` Rüdiger Klaehn [this message]
2004-01-01 1:28 ` Michael Clark
2004-01-01 1:58 ` Dave Jones
2004-01-01 2:18 ` Michael Clark
2004-01-01 2:30 ` Javier Fernandez-Ivern
2004-01-01 13:11 ` Rüdiger Klaehn
2003-12-31 20:49 ` Javier Fernandez-Ivern
2004-01-01 9:02 ` Juergen Hasch
2004-01-01 10:47 ` jw schultz
2004-01-01 12:44 ` Rüdiger Klaehn
2004-01-03 6:32 ` Jan Harkes
-- strict thread matches above, loose matches on Subject: below --
2004-02-07 8:29 John Ogness
2004-02-07 14:01 ` Christoph Hellwig
[not found] <18PG9-4og-27@gated-at.bofh.it>
[not found] ` <18TgF-QJ-7@gated-at.bofh.it>
[not found] ` <18TJE-1qL-3@gated-at.bofh.it>
2003-12-31 19:30 ` René Scharfe
2002-11-01 21:31 file " Colin Burnett
2002-11-01 22:19 ` Chris Wright
2002-11-02 15:43 ` Jamie Lokier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3FF31A15.4070307@lambda-computing.de \
--to=rudi@lambda-computing.de \
--cc=ivern@acm.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.