More cleaning ...
[linux-2.6/linux-mips.git] / include / linux / poll.h
blobb4bb681fd1ca08c76d4570ef63f281bd7b50f17c
1 #ifndef _LINUX_POLL_H
2 #define _LINUX_POLL_H
4 #include <asm/poll.h>
6 #ifdef __KERNEL__
8 #include <linux/wait.h>
9 #include <linux/string.h>
10 #include <linux/mm.h>
11 #include <asm/uaccess.h>
13 struct poll_table_struct;
15 /*
16 * structures and helpers for f_op->poll implementations
18 typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
20 typedef struct poll_table_struct {
21 poll_queue_proc qproc;
22 } poll_table;
24 static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
26 if (p && wait_address)
27 p->qproc(filp, wait_address, p);
30 static inline void init_poll_funcptr(poll_table *pt, poll_queue_proc qproc)
32 pt->qproc = qproc;
36 * Structures and helpers for sys_poll/sys_poll
38 struct poll_wqueues {
39 poll_table pt;
40 struct poll_table_page * table;
41 int error;
44 extern void poll_initwait(struct poll_wqueues *pwq);
45 extern void poll_freewait(struct poll_wqueues *pwq);
48 * Scaleable version of the fd_set.
51 typedef struct {
52 unsigned long *in, *out, *ex;
53 unsigned long *res_in, *res_out, *res_ex;
54 } fd_set_bits;
57 * How many longwords for "nr" bits?
59 #define FDS_BITPERLONG (8*sizeof(long))
60 #define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
61 #define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long))
64 * We do a VERIFY_WRITE here even though we are only reading this time:
65 * we'll write to it eventually..
67 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
69 static inline
70 int get_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
72 nr = FDS_BYTES(nr);
73 if (ufdset) {
74 int error;
75 error = verify_area(VERIFY_WRITE, ufdset, nr);
76 if (!error && __copy_from_user(fdset, ufdset, nr))
77 error = -EFAULT;
78 return error;
80 memset(fdset, 0, nr);
81 return 0;
84 static inline
85 void set_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
87 if (ufdset)
88 __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
91 static inline
92 void zero_fd_set(unsigned long nr, unsigned long *fdset)
94 memset(fdset, 0, FDS_BYTES(nr));
97 extern int do_select(int n, fd_set_bits *fds, long *timeout);
99 #endif /* KERNEL */
101 #endif /* _LINUX_POLL_H */