2.2.0-final
[davej-history.git] / include / linux / poll.h
blob7eb57334fd4aedd868747a9d363278c4f4c7c40f
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>
14 struct poll_table_entry {
15 struct file * filp;
16 struct wait_queue wait;
17 struct wait_queue ** wait_address;
20 typedef struct poll_table_struct {
21 struct poll_table_struct * next;
22 unsigned int nr;
23 struct poll_table_entry * entry;
24 } poll_table;
26 #define __MAX_POLL_TABLE_ENTRIES ((PAGE_SIZE - sizeof (poll_table)) / sizeof (struct poll_table_entry))
28 extern void __pollwait(struct file * filp, struct wait_queue ** wait_address, poll_table *p);
30 extern inline void poll_wait(struct file * filp, struct wait_queue ** wait_address, poll_table *p)
32 if (p && wait_address)
33 __pollwait(filp, wait_address, p);
37 * For the kernel fd_set we use a fixed set-size for allocation purposes.
38 * This set-size doesn't necessarily bear any relation to the size the user
39 * uses, but should preferably obviously be larger than any possible user
40 * size (NR_OPEN bits).
42 * We need 6 bitmaps (in/out/ex for both incoming and outgoing), and we
43 * allocate one page for all the bitmaps. Thus we have 8*PAGE_SIZE bits,
44 * to be divided by 6. And we'd better make sure we round to a full
45 * long-word (in fact, we'll round to 64 bytes).
49 #define KFDS_64BLOCK ((PAGE_SIZE/(6*64))*64)
50 #define KFDS_NR (KFDS_64BLOCK*8 > NR_OPEN ? NR_OPEN : KFDS_64BLOCK*8)
51 typedef unsigned long kernel_fd_set[KFDS_NR/__NFDBITS];
54 * Scaleable version of the fd_set.
57 typedef struct {
58 unsigned long *in, *out, *ex;
59 unsigned long *res_in, *res_out, *res_ex;
60 } fd_set_bits;
63 * How many longwords for "nr" bits?
65 #define FDS_BITPERLONG (8*sizeof(long))
66 #define FDS_LONGS(nr) (((nr)+FDS_BITPERLONG-1)/FDS_BITPERLONG)
67 #define FDS_BYTES(nr) (FDS_LONGS(nr)*sizeof(long))
70 * We do a VERIFY_WRITE here even though we are only reading this time:
71 * we'll write to it eventually..
73 * Use "unsigned long" accesses to let user-mode fd_set's be long-aligned.
75 static inline
76 int get_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
78 nr = FDS_BYTES(nr);
79 if (ufdset) {
80 int error;
81 error = verify_area(VERIFY_WRITE, ufdset, nr);
82 if (!error && __copy_from_user(fdset, ufdset, nr))
83 error = -EFAULT;
84 return error;
86 memset(fdset, 0, nr);
87 return 0;
90 static inline
91 void set_fd_set(unsigned long nr, void *ufdset, unsigned long *fdset)
93 if (ufdset)
94 __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
97 static inline
98 void zero_fd_set(unsigned long nr, unsigned long *fdset)
100 memset(fdset, 0, FDS_BYTES(nr));
103 extern int do_select(int n, fd_set_bits *fds, long *timeout);
105 #endif /* KERNEL */
107 #endif /* _LINUX_POLL_H */