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 #include <linux/mm.h>
12
13 static int fifo_open(struct inode * inode,struct file * filp)
14 {
15 int retval = 0;
16 unsigned long page;
17
18 switch( filp->f_mode ) {
19
20 case 1:
21
22
23
24
25
26 filp->f_op = &connecting_fifo_fops;
27 if (!PIPE_READERS(*inode)++)
28 wake_up_interruptible(&PIPE_WAIT(*inode));
29 if (!(filp->f_flags & O_NONBLOCK) && !PIPE_WRITERS(*inode)) {
30 PIPE_RD_OPENERS(*inode)++;
31 while (!PIPE_WRITERS(*inode)) {
32 if (current->signal & ~current->blocked) {
33 retval = -ERESTARTSYS;
34 break;
35 }
36 interruptible_sleep_on(&PIPE_WAIT(*inode));
37 }
38 if (!--PIPE_RD_OPENERS(*inode))
39 wake_up_interruptible(&PIPE_WAIT(*inode));
40 }
41 while (PIPE_WR_OPENERS(*inode))
42 interruptible_sleep_on(&PIPE_WAIT(*inode));
43 if (PIPE_WRITERS(*inode))
44 filp->f_op = &read_fifo_fops;
45 if (retval && !--PIPE_READERS(*inode))
46 wake_up_interruptible(&PIPE_WAIT(*inode));
47 break;
48
49 case 2:
50
51
52
53
54
55 if ((filp->f_flags & O_NONBLOCK) && !PIPE_READERS(*inode)) {
56 retval = -ENXIO;
57 break;
58 }
59 filp->f_op = &write_fifo_fops;
60 if (!PIPE_WRITERS(*inode)++)
61 wake_up_interruptible(&PIPE_WAIT(*inode));
62 if (!PIPE_READERS(*inode)) {
63 PIPE_WR_OPENERS(*inode)++;
64 while (!PIPE_READERS(*inode)) {
65 if (current->signal & ~current->blocked) {
66 retval = -ERESTARTSYS;
67 break;
68 }
69 interruptible_sleep_on(&PIPE_WAIT(*inode));
70 }
71 if (!--PIPE_WR_OPENERS(*inode))
72 wake_up_interruptible(&PIPE_WAIT(*inode));
73 }
74 while (PIPE_RD_OPENERS(*inode))
75 interruptible_sleep_on(&PIPE_WAIT(*inode));
76 if (retval && !--PIPE_WRITERS(*inode))
77 wake_up_interruptible(&PIPE_WAIT(*inode));
78 break;
79
80 case 3:
81
82
83
84
85
86
87 filp->f_op = &rdwr_fifo_fops;
88 if (!PIPE_READERS(*inode)++)
89 wake_up_interruptible(&PIPE_WAIT(*inode));
90 while (PIPE_WR_OPENERS(*inode))
91 interruptible_sleep_on(&PIPE_WAIT(*inode));
92 if (!PIPE_WRITERS(*inode)++)
93 wake_up_interruptible(&PIPE_WAIT(*inode));
94 while (PIPE_RD_OPENERS(*inode))
95 interruptible_sleep_on(&PIPE_WAIT(*inode));
96 break;
97
98 default:
99 retval = -EINVAL;
100 }
101 if (retval || PIPE_BASE(*inode))
102 return retval;
103 page = __get_free_page(GFP_KERNEL);
104 if (PIPE_BASE(*inode)) {
105 free_page(page);
106 return 0;
107 }
108 if (!page)
109 return -ENOMEM;
110 PIPE_LOCK(*inode) = 0;
111 PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
112 PIPE_BASE(*inode) = (char *) page;
113 return 0;
114 }
115
116
117
118
119
120
121 static struct file_operations def_fifo_fops = {
122 NULL,
123 NULL,
124 NULL,
125 NULL,
126 NULL,
127 NULL,
128 NULL,
129 fifo_open,
130 NULL,
131 NULL
132 };
133
134 static struct inode_operations fifo_inode_operations = {
135 &def_fifo_fops,
136 NULL,
137 NULL,
138 NULL,
139 NULL,
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 };
153
154 void init_fifo(struct inode * inode)
155 {
156 inode->i_op = &fifo_inode_operations;
157 inode->i_pipe = 1;
158 PIPE_LOCK(*inode) = 0;
159 PIPE_BASE(*inode) = NULL;
160 PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
161 PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
162 PIPE_WAIT(*inode) = NULL;
163 PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
164 }