diff -ruN -X _diff_exclude_from_file linux-2.4.3/arch/i386/config.in linux-2.4.3+fd_events/arch/i386/config.in
--- linux-2.4.3/arch/i386/config.in	Mon Jan  8 16:27:56 2001
+++ linux-2.4.3+fd_events/arch/i386/config.in	Tue Apr  3 08:31:23 2001
@@ -227,6 +227,13 @@
 tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF
 tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC
 
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+  bool 'File Events Interface (EXPERIMENTAL)' CONFIG_FILE_EVENTS
+
+  dep_mbool '  File Events Debugging' CONFIG_DEBUG_FILE_EVENTS $CONFIG_FILE_EVENTS
+
+fi
+
 bool 'Power Management support' CONFIG_PM
 
 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
diff -ruN -X _diff_exclude_from_file linux-2.4.3/arch/i386/kernel/entry.S linux-2.4.3+fd_events/arch/i386/kernel/entry.S
--- linux-2.4.3/arch/i386/kernel/entry.S	Wed Nov  8 20:09:50 2000
+++ linux-2.4.3+fd_events/arch/i386/kernel/entry.S	Tue Apr  3 16:44:25 2001
@@ -645,6 +645,8 @@
 	.long SYMBOL_NAME(sys_madvise)
 	.long SYMBOL_NAME(sys_getdents64)	/* 220 */
 	.long SYMBOL_NAME(sys_fcntl64)
+	.long SYMBOL_NAME(sys_bind_event)
+	.long SYMBOL_NAME(sys_get_events)
 	.long SYMBOL_NAME(sys_ni_syscall)	/* reserved for TUX */
 
 	/*
@@ -653,6 +655,6 @@
 	 * entries. Don't panic if you notice that this hasn't
 	 * been shrunk every time we add a new system call.
 	 */
-	.rept NR_syscalls-221
+	.rept NR_syscalls-223
 		.long SYMBOL_NAME(sys_ni_syscall)
 	.endr
diff -ruN -X _diff_exclude_from_file linux-2.4.3/fs/select.c linux-2.4.3+fd_events/fs/select.c
--- linux-2.4.3/fs/select.c	Fri Feb  9 14:29:44 2001
+++ linux-2.4.3+fd_events/fs/select.c	Wed Apr  4 17:06:04 2001
@@ -18,7 +18,9 @@
 #include <linux/smp_lock.h>
 #include <linux/poll.h>
 #include <linux/file.h>
+#include <linux/fdevent.h>
 
+#include <asm/softirq.h>	/* for spinlocks to work */
 #include <asm/uaccess.h>
 
 #define ROUND_UP(x,y) (((x)+(y)-1)/(y))
@@ -491,3 +493,213 @@
 	poll_freewait(&table);
 	return err;
 }
+
+#ifdef CONFIG_FILE_EVENTS
+
+int print_in_delive_file_event = 0;
+
+
+/* Takes an event and registers current->files->fd[fd] to watch for 
+ * ev->mask on ev->fd; when something happens the event structure gets
+ * queued on current->files->file_event_head; this queue is returned
+ * to the user when sys_get_events is called
+ */
+asmlinkage long sys_bind_event(struct fdevent *uev)
+{
+	struct fdevent *ev;
+	int err=0, flags;
+	
+	FEDBG("sys_bind_event( %p )",uev);
+	
+	if( !(ev = kmalloc(sizeof(struct fdevent), GFP_KERNEL)) ) {
+		err = -ENOMEM;
+		FEDBG("  kmalloc( %d, GFP_KERNEL ) failed", sizeof(struct fdevent));
+		goto out;
+	}
+	
+	if( copy_from_user(ev, uev, sizeof(struct fdevent)) ) {
+		err = -EFAULT;
+		FEDBG("  copy_from_user( %p, %p, %d ) failed", 
+		      ev, uev, sizeof(struct fdevent));
+		goto out_ev;
+	}
+
+	FEDBG("  ev->mask = %lx", ev->mask );
+	
+	/* before we start we have to make sure that the queue list for this 
+	 * task is properly initialized; considre this a delayed initialization
+	 * as we know that not all tasks will want to use this interface */
+	spin_lock(&current->files->file_event_list.lock);
+	if( ! current->files->file_event_list.head )
+		INIT_FILE_EVENT_LIST(&(current->files->file_event_list));
+	spin_unlock(&current->files->file_event_list.lock);
+	
+	/* now execute the desired command */
+	switch( ev->fd ) {
+		int i;
+		struct file *file;
+		
+	case FDEVENT_FD_EXISTING:
+		FEDBG("  ev->fd = FDEVENT_FD_EXISTING" );
+		
+		/* set the ev->mask on each existing current->files->fd[*] */
+		for(i=0;i<current->files->max_fds;i++) {
+			file = fget(i);
+			if( file ) {
+				file->f_event_mask = ev->mask;
+				fput(file);
+			}
+		}
+		break;
+		
+	case FDEVENT_FD_DEFAULT:
+		FEDBG("  ev->fd = FDEVENT_FD_DEFAULT" );
+		
+		/* set the default mask for new fd to ev->mask */
+		current->files->file_event_default_mask = ev->mask;
+		break;
+		
+	default:
+		FEDBG("  ev->fd = %d", ev->fd );
+		
+		/* set the ev->mask on the specified ev->fd */
+		file = fget(ev->fd);
+		if (!file) {
+			err = -EBADF;
+			goto out_ev;
+		}
+		file->f_event_mask = ev->mask;
+		fput(file);
+	}
+
+
+	print_in_delive_file_event = 1;
+
+out_ev:
+	kfree(ev);
+out:
+	FEDBG("  <sys_bind_event [%d]", err);
+	return err;
+}
+
+/* see sys_bind_event for specifics; in general this is just like a sys_poll call
+ * but an array of files does not have to be traversed as the files_struct
+ * of the current process already knows what events have fired */
+asmlinkage long sys_get_events(struct fdevent *uevs, unsigned int nevs, long timeout)
+{
+	int ret=0;
+	register file_event_t *ev, *nev;
+	register struct fdevent *uev = uevs;
+	file_event_list_t *list = &current->files->file_event_list;
+
+	FEDBG("sys_get_events( %p, %u, %lu )", uevs, nevs, timeout);
+	
+	spin_lock_bh(&list->lock);
+	
+	ev = list->head;
+	while( ev != (file_event_t*)list ) {
+		int error = copy_to_user( uev, &ev->event, sizeof(*uev) );
+		if( signal_pending(current) ) {
+			if ( !ret )
+				ret = -EINTR;
+			break;
+		}
+		if( error ) {
+			if( !ret ) 
+				ret = -EFAULT;
+			break;
+		}
+		
+		ev->event.mask = 0;
+		
+		nev = ev->next;
+		file_event_list_del(ev);
+		ev = nev;
+		
+		uev++;
+		ret++;
+		if( ret==nevs ) 
+			break;
+	}
+	
+	spin_unlock_bh(&list->lock);
+
+	print_in_delive_file_event = 0;
+
+	FEDBG("  <sys_get_events [%d]", ret);
+	return ret;
+}
+
+/* initialize a file based on file_struct of a task 
+ *  file  - a newly created file
+ *  files - a files_struct of the task called from
+ */
+int file_event_init( struct file *file, struct files_struct *files )
+{
+	if( file ) {
+		file->f_event_mask = files->file_event_default_mask;
+		file->f_event_list = &files->file_event_list;
+		INIT_FILE_EVENT( &file->f_event );
+	}
+	return 0;
+}
+
+/* releases any bindings the file has with the event list for it's task */
+int file_event_release( struct file *file )
+{
+	if( file && file->f_event_list ) {
+		int flags;
+		file_event_list_t *list = file->f_event_list;
+		
+		spin_lock_irqsave(&list->lock,flags);
+		if( file->f_event.event.mask ) {
+			FEDBG("file_event_release( %p ): removing from list", file);
+			file_event_list_del( &file->f_event );
+		}
+		spin_unlock_irqrestore(&list->lock,flags);
+	}
+	return 0;
+}
+
+/* deliver an event
+ *  file - file pointer, properly locked a la get_file 
+ *  mask - what event fired (see fdevent.h)
+ */
+int deliver_file_event(struct file *file, unsigned long mask)
+{
+	if( print_in_delive_file_event )
+		FEDBG("deliver_file_event( %p, %lx )", file, mask);
+
+	if( file && (file->f_event_mask & mask) ) {
+		file_event_list_t *list = file->f_event_list;
+		file_event_t *ev = &file->f_event;
+
+		FEDBG("deliver_file_event( %p, %lx )", file, mask);
+		FEDBG("  passes mask (%lx) checks; list is at (%p)", 
+		      file->f_event_mask, list);
+
+		if( list ) {
+		
+			spin_lock_bh(&list->lock);
+		
+			if( ! ev->event.mask ) {
+				FEDBG("  appending event (%p) to list (%p)",
+				      ev, list );
+				file_event_list_add_tail( ev, list );
+			}
+
+			FEDBG("  event state moved from %lx to %lx", 
+			      ev->event.mask, ev->event.mask|mask);
+			ev->event.mask |= mask;
+
+			spin_unlock_bh(&list->lock);
+		
+		}
+		
+		FEDBG("  <deliver_file_event [0]");
+	}
+
+	return 0;
+}
+
+#endif
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/asm-i386/fdevent.h linux-2.4.3+fd_events/include/asm-i386/fdevent.h
--- linux-2.4.3/include/asm-i386/fdevent.h	Wed Dec 31 19:00:00 1969
+++ linux-2.4.3+fd_events/include/asm-i386/fdevent.h	Mon Apr  2 16:21:31 2001
@@ -0,0 +1,46 @@
+#ifndef __i386_FDEVENT_H
+#define __i386_FDEVENT_H
+
+#include <asm/poll.h>
+
+/* Event types are borowed from poll.h;
+ * NOTE that while the current implementation shares the flags of poll()
+ *     this cannot be taken as a rule
+ */
+#define FDEVENT_IN	POLLIN     /* 0x0001 */
+#define FDEVENT_PRI	POLLPRI    /* 0x0002 */
+#define FDEVENT_OUT	POLLOUT    /* 0x0004 */
+#define FDEVENT_ERR	POLLERR    /* 0x0008 */
+#define FDEVENT_HUP	POLLHUP    /* 0x0010 */
+#define FDEVENT_NVAL	POLLNVLA   /* 0x0020 */
+
+/* non standard, sais poll.h */
+#define FDEVENT_RDNORM	POLLRDNORM /* 0x0040 */
+#define FDEVENT_RDBAND	POLLRDBAND /* 0x0080 */
+#define FDEVENT_WRNORM	POLLWRNORM /* 0x0100 */
+#define FDEVENT_WRBAND	POLLWRBAND /* 0x0200 */
+#define FDEVENT_MSG	POLLMSG    /* 0x0400 */
+
+struct fdevent;
+
+typedef void (fdevent_fn)(struct fdevent*);
+
+struct fdevent {
+	int fd;
+	unsigned long mask;
+	void *data;
+	fdevent_fn *fn;
+};
+
+#define FDEVENT_INIT { 0, 0, NULL, NULL }
+#define INIT_FDEVENT(ptr) do { \
+	(ptr)->fd = 0; (ptr)->mask = 0; \
+	(ptr)->data = 0; (ptr)->fn = 0; \
+} while (0)
+
+
+/* wildcards for fdevent.fd */
+#define FDEVENT_FD_EXISTING -1
+#define FDEVENT_FD_DEFAULT  -2
+
+#endif
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/asm-i386/unistd.h linux-2.4.3+fd_events/include/asm-i386/unistd.h
--- linux-2.4.3/include/asm-i386/unistd.h	Fri Aug 11 17:39:23 2000
+++ linux-2.4.3+fd_events/include/asm-i386/unistd.h	Wed Apr  4 10:10:43 2001
@@ -227,6 +227,8 @@
 #define __NR_madvise1		219	/* delete when C lib stub is removed */
 #define __NR_getdents64		220
 #define __NR_fcntl64		221
+#define __NR_bind_event		222
+#define __NR_get_events		223
 
 /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
 
@@ -345,6 +347,7 @@
 static inline _syscall1(int,_exit,int,exitcode)
 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
 static inline _syscall1(int,delete_module,const char *,name)
+
 
 static inline pid_t wait(int * wait_stat)
 {
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/linux/fdevent.h linux-2.4.3+fd_events/include/linux/fdevent.h
--- linux-2.4.3/include/linux/fdevent.h	Wed Dec 31 19:00:00 1969
+++ linux-2.4.3+fd_events/include/linux/fdevent.h	Wed Apr  4 15:00:13 2001
@@ -0,0 +1,83 @@
+#ifndef _LINUX_FDEVENT_H
+#define _LINUX_FDEVENT_H
+
+#ifdef CONFIG_FILE_EVENTS
+
+#include <asm/fdevent.h>
+
+#ifdef __KERNEL__
+
+#include <linux/list.h>
+#include <asm/spinlock.h>
+#include <asm/types.h>
+
+/* debug macros */
+#ifdef CONFIG_DEBUG_FILE_EVENTS
+#define FEDBG(format, arg...) printk(KERN_ERR __FILE__ ":%d: " \
+                                   format "\n" , __LINE__ , ## arg)
+#else
+#define FEDBG(format, arg...) do{/*nothing*/}while(0)
+#endif
+
+typedef struct file_event_s {
+	struct file_event_s *next, *prev; /* queue stored in files_struct */
+	struct fdevent event;
+	
+} file_event_t;
+
+typedef struct file_event_list_s {
+	struct file_event_s *head, *tail; /* just like next/prev above */
+	spinlock_t lock;
+} file_event_list_t;
+
+#define FILE_EVENT_INIT { NULL, NULL, FDEVENT_INIT }
+#define INIT_FILE_EVENT(ptr) do { \
+	(ptr)->next = ptr; (ptr)->prev = ptr; \
+	INIT_FDEVENT( &(ptr)->event ); \
+} while (0)
+
+#define FILE_EVENT_LIST_INIT { NULL, NULL, SPIN_LOCK_UNLOCKED }
+#define INIT_FILE_EVENT_LIST(ptr) do { \
+	(ptr)->head = (void*)ptr; (ptr)->tail = (void*)ptr; \
+	spin_lock_init( &(ptr)->lock ); \
+} while (0)
+
+
+/* 
+ * these are some wrappers for the <list.h> functions we are interested in
+ * ... no point in reinventing the wheel.
+ */
+
+static inline void 
+file_event_list_add_tail( file_event_t *ev, file_event_list_t *list )
+{
+	list_add_tail( (struct list_head*)ev, (struct list_head*)list );
+}
+
+static inline void 
+file_event_list_del( file_event_t *ev )
+{
+	list_del_init( (struct list_head*)ev );
+}
+
+/* forward declarations */
+struct file;
+struct files_struct;
+
+/* enqueue the event */
+extern int 
+deliver_file_event(struct file *file, unsigned long mask);
+
+/* initialize links between the file and the task's files_struct */
+extern int
+file_event_init( struct file *file, struct files_struct *files );
+
+/* clean up links and remove file from any link list */
+extern int
+file_event_release( struct file *file );
+
+#endif /* __KERNEL__ */
+
+#endif /* CONFIG_FILE_EVENTS */
+
+#endif /* _LINUX_FDEVENT_H */
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/linux/fs.h linux-2.4.3+fd_events/include/linux/fs.h
--- linux-2.4.3/include/linux/fs.h	Mon Mar 26 18:48:11 2001
+++ linux-2.4.3+fd_events/include/linux/fs.h	Wed Apr  4 15:25:58 2001
@@ -21,6 +21,7 @@
 #include <linux/cache.h>
 #include <linux/stddef.h>
 #include <linux/string.h>
+#include <linux/fdevent.h>
 
 #include <asm/atomic.h>
 #include <asm/bitops.h>
@@ -495,6 +496,12 @@
 
 	/* needed for tty driver, and maybe others */
 	void			*private_data;
+	
+#ifdef CONFIG_FILE_EVENTS
+	unsigned long           f_event_mask;
+	file_event_t		f_event;
+	file_event_list_t       *f_event_list;
+#endif
 };
 extern spinlock_t files_lock;
 #define file_list_lock() spin_lock(&files_lock);
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/linux/sched.h linux-2.4.3+fd_events/include/linux/sched.h
--- linux-2.4.3/include/linux/sched.h	Mon Mar 26 18:48:11 2001
+++ linux-2.4.3+fd_events/include/linux/sched.h	Wed Apr  4 16:50:44 2001
@@ -177,8 +177,20 @@
 	fd_set close_on_exec_init;
 	fd_set open_fds_init;
 	struct file * fd_array[NR_OPEN_DEFAULT];
+#ifdef CONFIG_FILE_EVENTS
+	unsigned long file_event_default_mask;
+	file_event_list_t file_event_list;
+#endif
 };
 
+#ifdef CONFIG_FILE_EVENTS
+#define INIT_FILES_STRUCT_EVENTS ,                      \
+		file_event_default_mask: 0,             \
+		file_event_list:   FILE_EVENT_LIST_INIT
+#else
+#define INIT_FILES_STRUCT_EVENTS /* nothing */
+#endif
+
 #define INIT_FILES \
 { 							\
 	count:		ATOMIC_INIT(1), 		\
@@ -192,6 +204,7 @@
 	close_on_exec_init: { { 0, } }, 		\
 	open_fds_init:	{ { 0, } }, 			\
 	fd_array:	{ NULL, } 			\
+	INIT_FILES_STRUCT_EVENTS			\
 }
 
 /* Maximum number of active map areas.. This is a random (large) number */
diff -ruN -X _diff_exclude_from_file linux-2.4.3/include/net/sock.h linux-2.4.3+fd_events/include/net/sock.h
--- linux-2.4.3/include/net/sock.h	Mon Mar 26 18:48:31 2001
+++ linux-2.4.3+fd_events/include/net/sock.h	Wed Apr  4 16:52:42 2001
@@ -37,6 +37,7 @@
 #include <linux/timer.h>
 #include <linux/cache.h>
 #include <linux/in.h>		/* struct sockaddr_in */
+#include <linux/fdevent.h>
 
 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
 #include <linux/in6.h>		/* struct sockaddr_in6 */
@@ -1216,10 +1217,28 @@
 	return amt;
 }
 
+extern int print_in_delive_file_event;
+
 static inline void sk_wake_async(struct sock *sk, int how, int band)
 {
 	if (sk->socket && sk->socket->fasync_list)
 		sock_wake_async(sk->socket, how, band);
+#ifdef CONFIG_FILE_EVENTS
+	if ( sk->socket && sk->socket->file ) {
+		int x=0;
+		if( print_in_delive_file_event ) {
+			printk("sk_wake_async(%p,%d,%d)\n",sk,how,band);
+		}
+		switch(band){
+		case POLL_IN:  x=POLLIN;  break;
+		case POLL_OUT: x=POLLOUT; break;
+		case POLL_PRI: x=POLLPRI; break;
+		case POLL_ERR: x=POLLERR; break;
+		case POLL_HUP: x=POLLHUP; break;
+		}
+		deliver_file_event(sk->socket->file, x);
+	}
+#endif
 }
 
 #define SOCK_MIN_SNDBUF 2048
diff -ruN -X _diff_exclude_from_file linux-2.4.3/kernel/fork.c linux-2.4.3+fd_events/kernel/fork.c
--- linux-2.4.3/kernel/fork.c	Mon Mar 19 15:35:08 2001
+++ linux-2.4.3+fd_events/kernel/fork.c	Tue Apr  3 17:05:29 2001
@@ -440,6 +440,11 @@
 	newf->close_on_exec = &newf->close_on_exec_init;
 	newf->open_fds	    = &newf->open_fds_init;
 	newf->fd	    = &newf->fd_array[0];
+	
+#ifdef CONFIG_FILE_EVENTS
+	newf->file_event_default_mask = 0;
+	INIT_FILE_EVENT_LIST( &newf->file_event_list );
+#endif
 
 	/* We don't yet have the oldf readlock, but even if the old
            fdset gets grown now, we'll only copy up to "size" fds */
@@ -485,6 +490,9 @@
 		if (f)
 			get_file(f);
 		*new_fds++ = f;
+#ifdef CONFIG_FILE_EVENTS
+		
+#endif
 	}
 	read_unlock(&oldf->file_lock);
 
diff -ruN -X _diff_exclude_from_file linux-2.4.3/net/socket.c linux-2.4.3+fd_events/net/socket.c
--- linux-2.4.3/net/socket.c	Fri Nov 17 14:36:27 2000
+++ linux-2.4.3+fd_events/net/socket.c	Tue Apr  3 09:39:44 2001
@@ -484,6 +484,10 @@
  
 void sock_release(struct socket *sock)
 {
+#ifdef CONFIG_FILE_EVENTS
+	(void)file_event_release( sock->file );
+#endif
+
 	if (sock->ops) 
 		sock->ops->release(sock);
 
@@ -898,7 +902,11 @@
 	retval = sock_map_fd(sock);
 	if (retval < 0)
 		goto out_release;
-
+	
+#ifdef CONFIG_FILE_EVENTS
+	(void)file_event_init( sock->file, current->files );
+#endif
+	
 out:
 	/* It may be already another descriptor 8) Not kernel problem. */
 	return retval;
@@ -953,8 +961,13 @@
 	err = put_user(fd1, &usockvec[0]); 
 	if (!err)
 		err = put_user(fd2, &usockvec[1]);
-	if (!err)
+	if (!err) {
+#ifdef CONFIG_FILE_EVENTS
+		(void)file_event_init( sock1->file, current->files );
+		(void)file_event_init( sock2->file, current->files );
+#endif
 		return 0;
+	}
 
 	sys_close(fd2);
 	sys_close(fd1);
@@ -1066,6 +1079,10 @@
 
 	if ((err = sock_map_fd(newsock)) < 0)
 		goto out_release;
+
+#ifdef CONFIG_FILE_EVENTS
+	(void)file_event_init( newsock->file, current->files );
+#endif
 
 out_put:
 	sockfd_put(sock);

