4 * written by Paul H. Hargrove
9 static int fifo_open(struct inode
* inode
,struct file
* filp
)
14 switch( filp
->f_mode
) {
19 * POSIX.1 says that O_NONBLOCK means return with the FIFO
20 * opened, even when there is no process writing the FIFO.
22 filp
->f_op
= &connecting_fifo_fops
;
23 if (!PIPE_READERS(*inode
)++)
24 wake_up_interruptible(&PIPE_WAIT(*inode
));
25 if (!(filp
->f_flags
& O_NONBLOCK
) && !PIPE_WRITERS(*inode
)) {
26 PIPE_RD_OPENERS(*inode
)++;
27 while (!PIPE_WRITERS(*inode
)) {
28 if (signal_pending(current
)) {
29 retval
= -ERESTARTSYS
;
32 interruptible_sleep_on(&PIPE_WAIT(*inode
));
34 if (!--PIPE_RD_OPENERS(*inode
))
35 wake_up_interruptible(&PIPE_WAIT(*inode
));
37 while (PIPE_WR_OPENERS(*inode
))
38 interruptible_sleep_on(&PIPE_WAIT(*inode
));
39 if (PIPE_WRITERS(*inode
))
40 filp
->f_op
= &read_fifo_fops
;
41 if (retval
&& !--PIPE_READERS(*inode
))
42 wake_up_interruptible(&PIPE_WAIT(*inode
));
48 * POSIX.1 says that O_NONBLOCK means return -1 with
49 * errno=ENXIO when there is no process reading the FIFO.
51 if ((filp
->f_flags
& O_NONBLOCK
) && !PIPE_READERS(*inode
)) {
55 filp
->f_op
= &write_fifo_fops
;
56 if (!PIPE_WRITERS(*inode
)++)
57 wake_up_interruptible(&PIPE_WAIT(*inode
));
58 if (!PIPE_READERS(*inode
)) {
59 PIPE_WR_OPENERS(*inode
)++;
60 while (!PIPE_READERS(*inode
)) {
61 if (signal_pending(current
)) {
62 retval
= -ERESTARTSYS
;
65 interruptible_sleep_on(&PIPE_WAIT(*inode
));
67 if (!--PIPE_WR_OPENERS(*inode
))
68 wake_up_interruptible(&PIPE_WAIT(*inode
));
70 while (PIPE_RD_OPENERS(*inode
))
71 interruptible_sleep_on(&PIPE_WAIT(*inode
));
72 if (retval
&& !--PIPE_WRITERS(*inode
))
73 wake_up_interruptible(&PIPE_WAIT(*inode
));
79 * POSIX.1 leaves this case "undefined" when O_NONBLOCK is set.
80 * This implementation will NEVER block on a O_RDWR open, since
81 * the process can at least talk to itself.
83 filp
->f_op
= &rdwr_fifo_fops
;
84 if (!PIPE_READERS(*inode
)++)
85 wake_up_interruptible(&PIPE_WAIT(*inode
));
86 while (PIPE_WR_OPENERS(*inode
))
87 interruptible_sleep_on(&PIPE_WAIT(*inode
));
88 if (!PIPE_WRITERS(*inode
)++)
89 wake_up_interruptible(&PIPE_WAIT(*inode
));
90 while (PIPE_RD_OPENERS(*inode
))
91 interruptible_sleep_on(&PIPE_WAIT(*inode
));
97 if (retval
|| PIPE_BASE(*inode
))
99 page
= __get_free_page(GFP_KERNEL
);
100 if (PIPE_BASE(*inode
)) {
106 PIPE_LOCK(*inode
) = 0;
107 PIPE_START(*inode
) = PIPE_LEN(*inode
) = 0;
108 PIPE_BASE(*inode
) = (char *) page
;
113 * Dummy default file-operations: the only thing this does
114 * is contain the open that then fills in the correct operations
115 * depending on the access mode of the file...
117 static struct file_operations def_fifo_fops
= {
125 fifo_open
, /* will set read or write pipe_fops */
132 struct inode_operations fifo_inode_operations
= {
133 &def_fifo_fops
, /* default file operations */
145 NULL
, /* writepage */
148 NULL
/* permission */
151 void init_fifo(struct inode
* inode
)
153 inode
->i_op
= &fifo_inode_operations
;
154 PIPE_LOCK(*inode
) = 0;
155 PIPE_BASE(*inode
) = NULL
;
156 PIPE_START(*inode
) = PIPE_LEN(*inode
) = 0;
157 PIPE_RD_OPENERS(*inode
) = PIPE_WR_OPENERS(*inode
) = 0;
158 PIPE_WAIT(*inode
) = NULL
;
159 PIPE_READERS(*inode
) = PIPE_WRITERS(*inode
) = 0;