This source file includes following definitions.
- fifo_open
- init_fifo
1
2
3
4
5
6
7 #include <linux/sched.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/fcntl.h>
11
12 extern struct file_operations read_pipe_fops;
13 extern struct file_operations write_pipe_fops;
14 extern struct file_operations rdwr_pipe_fops;
15
16 static int fifo_open(struct inode * inode,struct file * filp)
17 {
18 int retval = 0;
19 unsigned long page;
20
21 switch( filp->f_mode ) {
22
23 case 1:
24
25
26
27
28
29 filp->f_op = &read_pipe_fops;
30 if (!PIPE_READERS(*inode)++)
31 wake_up(&PIPE_WRITE_WAIT(*inode));
32 if (!(filp->f_flags & O_NONBLOCK) && !PIPE_WRITERS(*inode)) {
33 PIPE_RD_OPENERS(*inode)++;
34 while (!PIPE_WRITERS(*inode)) {
35 #if 0
36 if (PIPE_HEAD(*inode) != PIPE_TAIL(*inode))
37 break;
38 #endif
39 if (current->signal & ~current->blocked) {
40 retval = -ERESTARTSYS;
41 break;
42 }
43 interruptible_sleep_on(&PIPE_READ_WAIT(*inode));
44 }
45 if (!--PIPE_RD_OPENERS(*inode))
46 wake_up(&PIPE_WRITE_WAIT(*inode));
47 }
48 while (PIPE_WR_OPENERS(*inode))
49 interruptible_sleep_on(&PIPE_READ_WAIT(*inode));
50 if (retval && !--PIPE_READERS(*inode))
51 wake_up(&PIPE_WRITE_WAIT(*inode));
52 break;
53
54 case 2:
55
56
57
58
59
60 if ((filp->f_flags & O_NONBLOCK) && !PIPE_READERS(*inode)) {
61 retval = -ENXIO;
62 break;
63 }
64 filp->f_op = &write_pipe_fops;
65 if (!PIPE_WRITERS(*inode)++)
66 wake_up(&PIPE_READ_WAIT(*inode));
67 if (!PIPE_READERS(*inode)) {
68 PIPE_WR_OPENERS(*inode)++;
69 while (!PIPE_READERS(*inode)) {
70 if (current->signal & ~current->blocked) {
71 retval = -ERESTARTSYS;
72 break;
73 }
74 interruptible_sleep_on(&PIPE_WRITE_WAIT(*inode));
75 }
76 if (!--PIPE_WR_OPENERS(*inode))
77 wake_up(&PIPE_READ_WAIT(*inode));
78 }
79 while (PIPE_RD_OPENERS(*inode))
80 interruptible_sleep_on(&PIPE_WRITE_WAIT(*inode));
81 if (retval && !--PIPE_WRITERS(*inode))
82 wake_up(&PIPE_READ_WAIT(*inode));
83 break;
84
85 case 3:
86
87
88
89
90
91
92 filp->f_op = &rdwr_pipe_fops;
93 if (!PIPE_READERS(*inode)++)
94 wake_up(&PIPE_WRITE_WAIT(*inode));
95 while (PIPE_WR_OPENERS(*inode))
96 interruptible_sleep_on(&PIPE_READ_WAIT(*inode));
97 if (!PIPE_WRITERS(*inode)++)
98 wake_up(&PIPE_READ_WAIT(*inode));
99 while (PIPE_RD_OPENERS(*inode))
100 interruptible_sleep_on(&PIPE_WRITE_WAIT(*inode));
101 break;
102
103 default:
104 retval = -EINVAL;
105 }
106 if (retval || PIPE_BASE(*inode))
107 return retval;
108 page = get_free_page(GFP_KERNEL);
109 if (PIPE_BASE(*inode)) {
110 free_page(page);
111 return 0;
112 }
113 if (!page)
114 return -ENOMEM;
115 PIPE_HEAD(*inode) = PIPE_TAIL(*inode) = 0;
116 PIPE_BASE(*inode) = (char *) page;
117 return 0;
118 }
119
120
121
122
123
124
125 static struct file_operations def_fifo_fops = {
126 NULL,
127 NULL,
128 NULL,
129 NULL,
130 NULL,
131 NULL,
132 NULL,
133 fifo_open,
134 NULL,
135 NULL
136 };
137
138 static struct inode_operations fifo_inode_operations = {
139 &def_fifo_fops,
140 NULL,
141 NULL,
142 NULL,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
147 NULL,
148 NULL,
149 NULL,
150 NULL,
151 NULL,
152 NULL,
153 NULL
154 };
155
156 void init_fifo(struct inode * inode)
157 {
158 inode->i_op = &fifo_inode_operations;
159 inode->i_pipe = 1;
160 PIPE_BASE(*inode) = NULL;
161 PIPE_HEAD(*inode) = PIPE_TAIL(*inode) = 0;
162 PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
163 PIPE_READ_WAIT(*inode) = PIPE_WRITE_WAIT(*inode) = NULL;
164 PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
165 }