This source file includes following definitions.
- fifo_open
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 PIPE_READERS(*inode)++;
31 if (!(filp->f_flags & O_NONBLOCK))
32 while (!PIPE_WRITERS(*inode)) {
33 if (PIPE_HEAD(*inode) != PIPE_TAIL(*inode))
34 break;
35 if (current->signal & ~current->blocked) {
36 retval = -ERESTARTSYS;
37 break;
38 }
39 interruptible_sleep_on(&PIPE_READ_WAIT(*inode));
40 }
41 if (retval)
42 PIPE_READERS(*inode)--;
43 break;
44
45 case 2:
46
47
48
49
50
51 if ((filp->f_flags & O_NONBLOCK) && !PIPE_READERS(*inode)) {
52 retval = -ENXIO;
53 break;
54 }
55 filp->f_op = &write_pipe_fops;
56 PIPE_WRITERS(*inode)++;
57 while (!PIPE_READERS(*inode)) {
58 if (current->signal & ~current->blocked) {
59 retval = -ERESTARTSYS;
60 break;
61 }
62 interruptible_sleep_on(&PIPE_WRITE_WAIT(*inode));
63 }
64 if (retval)
65 PIPE_WRITERS(*inode)--;
66 break;
67
68 case 3:
69
70
71
72
73
74
75 filp->f_op = &rdwr_pipe_fops;
76 PIPE_WRITERS(*inode) += 1;
77 PIPE_READERS(*inode) += 1;
78 break;
79
80 default:
81 retval = -EINVAL;
82 }
83 if (PIPE_WRITERS(*inode))
84 wake_up(&PIPE_READ_WAIT(*inode));
85 if (PIPE_READERS(*inode))
86 wake_up(&PIPE_WRITE_WAIT(*inode));
87 if (retval || inode->i_size)
88 return retval;
89 page = get_free_page(GFP_KERNEL);
90 if (inode->i_size) {
91 free_page(page);
92 return 0;
93 }
94 if (!page)
95 return -ENOMEM;
96 inode->i_size = page;
97 return 0;
98 }
99
100
101
102
103
104
105 struct file_operations def_fifo_fops = {
106 NULL,
107 NULL,
108 NULL,
109 NULL,
110 NULL,
111 NULL,
112 fifo_open,
113 NULL
114 };