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 Mon Apr 2 09:23:44 2001 @@ -227,6 +227,10 @@ 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 Descriptor Events Interface (EXPERIMENTAL)' 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/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 Mon Apr 2 12:53:02 2001 @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -491,3 +492,120 @@ poll_freewait(&table); return err; } + +#ifdef CONFIG_FILE_EVENTS +/* 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; + + if( (ev = kmalloc(sizeof(struct fdevent), GFP_KERNEL)) ) { + err = -ENOMEM; + goto out; + } + + if( copy_from_user(ev, uev, sizeof(struct fdevent)) ) { + err = -EFAULT; + goto out_ev; + } + + switch( ev->fd ) { + int i; + struct file *file; + + case FDEVENT_FD_EXISTING: + /* set the ev->mask on each existing current->files->fd[*] */ + for(i=0;ifiles->max_fds;i++) { + file = fget(i); + if( file ) { + file->f_event_mask = ev->mask; + fput(file); + } + } + break; + + case FDEVENT_FD_DEFAULT: + /* set the default mask for new fd to ev->mask */ + current->files->file_event_default_mask = ev->mask; + break; + + default: + /* 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); + } + +out_ev: + kfree(ev); +out: + return err; +} + +/* see sys_bind_event */ +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 = ¤t->files->file_event_list; + + spin_lock_bh(&list->lock); + + ev = list->head; + while( ev != (file_event_t*)list ) { + if( copy_to_user( uev, &ev->event, sizeof(*uev) ) ) { + if( !ret ) + ret = -EFAULT; + break; + } + + nev = ev->next; + file_event_list_del(ev); + ev = nev; + + uev++; + ret++; + if( ret==nevs ) + break; + } + + spin_unlock_bh(&list->lock); + + return ret; +} + +/* deliver and event + * filp - 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( file->f_event_mask & mask ) { + + file_event_list_t *list = file->f_event_list; + file_event_t *ev = &file->f_event; + + spin_lock_bh(&list->lock); + + if( ! ev->event.mask ) + file_event_list_add_tail( ev, list ); + + ev->event.mask |= mask; + + spin_unlock_bh(&list->lock); + } + + 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 12:17:12 2001 @@ -0,0 +1,36 @@ +#ifndef __i386_FDEVENT_H +#define __i386_FDEVENT_H + +/* Event types are borowed from poll.h */ +#define FDEVENT_IN 0x0001 +#define FDEVENT_PRI 0x0002 +#define FDEVENT_OUT 0x0004 +#define FDEVENT_ERR 0x0008 +#define FDEVENT_HUP 0x0010 +#define FDEVENT_NVAL 0x0020 + +/* non standard, sais poll.h */ +#define FDEVENT_RDNORM 0x0040 +#define FDEVENT_RDBAND 0x0080 +#define FDEVENT_WRNORM 0x0100 +#define FDEVENT_WRBAND 0x0200 +#define FDEVENT_MSG 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 } + +/* 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/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 Mon Apr 2 12:42:23 2001 @@ -0,0 +1,50 @@ +#ifndef _LINUX_FDEVENT_H +#define _LINUX_FDEVENT_H + +#ifdef CONFIG_FILE_EVENTS + +#include + +#ifdef __KERNEL__ + +#include +#include +#include + +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 FILE_EVENT_LIST_INIT { NULL, NULL, SPIN_LOCK_UNLOCKED } + +/* + * these are some wrappers for the 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( (struct list_head*)ev ); +} + + +#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 Apr 2 08:46:43 2001 +++ linux-2.4.3+fd_events/include/linux/fs.h Mon Apr 2 13:33:10 2001 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -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 Apr 2 08:46:44 2001 +++ linux-2.4.3+fd_events/include/linux/sched.h Mon Apr 2 12:42:27 2001 @@ -177,6 +177,10 @@ 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 }; #define INIT_FILES \