fifo_vnops.c revision 1.34 1 1.34 chs /* $NetBSD: fifo_vnops.c,v 1.34 2002/07/27 16:43:36 chs Exp $ */
2 1.9 cgd
3 1.1 cgd /*
4 1.25 fvdl * Copyright (c) 1990, 1993, 1995
5 1.8 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd *
35 1.25 fvdl * @(#)fifo_vnops.c 8.10 (Berkeley) 5/27/95
36 1.1 cgd */
37 1.32 lukem
38 1.32 lukem #include <sys/cdefs.h>
39 1.34 chs __KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.34 2002/07/27 16:43:36 chs Exp $");
40 1.1 cgd
41 1.6 mycroft #include <sys/param.h>
42 1.25 fvdl #include <sys/systm.h>
43 1.8 mycroft #include <sys/proc.h>
44 1.6 mycroft #include <sys/time.h>
45 1.6 mycroft #include <sys/namei.h>
46 1.6 mycroft #include <sys/vnode.h>
47 1.6 mycroft #include <sys/socket.h>
48 1.6 mycroft #include <sys/socketvar.h>
49 1.6 mycroft #include <sys/stat.h>
50 1.6 mycroft #include <sys/ioctl.h>
51 1.6 mycroft #include <sys/file.h>
52 1.6 mycroft #include <sys/errno.h>
53 1.6 mycroft #include <sys/malloc.h>
54 1.17 christos #include <sys/un.h>
55 1.20 mycroft #include <sys/poll.h>
56 1.19 mycroft
57 1.6 mycroft #include <miscfs/fifofs/fifo.h>
58 1.19 mycroft #include <miscfs/genfs/genfs.h>
59 1.1 cgd
60 1.1 cgd /*
61 1.1 cgd * This structure is associated with the FIFO vnode and stores
62 1.1 cgd * the state associated with the FIFO.
63 1.1 cgd */
64 1.1 cgd struct fifoinfo {
65 1.1 cgd struct socket *fi_readsock;
66 1.1 cgd struct socket *fi_writesock;
67 1.34 chs long fi_opencount;
68 1.1 cgd long fi_readers;
69 1.1 cgd long fi_writers;
70 1.1 cgd };
71 1.1 cgd
72 1.17 christos int (**fifo_vnodeop_p) __P((void *));
73 1.29 jdolecek const struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
74 1.8 mycroft { &vop_default_desc, vn_default_error },
75 1.8 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
76 1.8 mycroft { &vop_create_desc, fifo_create }, /* create */
77 1.8 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
78 1.8 mycroft { &vop_open_desc, fifo_open }, /* open */
79 1.8 mycroft { &vop_close_desc, fifo_close }, /* close */
80 1.8 mycroft { &vop_access_desc, fifo_access }, /* access */
81 1.8 mycroft { &vop_getattr_desc, fifo_getattr }, /* getattr */
82 1.8 mycroft { &vop_setattr_desc, fifo_setattr }, /* setattr */
83 1.8 mycroft { &vop_read_desc, fifo_read }, /* read */
84 1.8 mycroft { &vop_write_desc, fifo_write }, /* write */
85 1.13 mycroft { &vop_lease_desc, fifo_lease_check }, /* lease */
86 1.8 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
87 1.20 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
88 1.25 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
89 1.8 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
90 1.8 mycroft { &vop_fsync_desc, fifo_fsync }, /* fsync */
91 1.8 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
92 1.8 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
93 1.8 mycroft { &vop_link_desc, fifo_link }, /* link */
94 1.8 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
95 1.8 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
96 1.8 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
97 1.8 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
98 1.8 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
99 1.8 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
100 1.8 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
101 1.8 mycroft { &vop_inactive_desc, fifo_inactive }, /* inactive */
102 1.8 mycroft { &vop_reclaim_desc, fifo_reclaim }, /* reclaim */
103 1.8 mycroft { &vop_lock_desc, fifo_lock }, /* lock */
104 1.8 mycroft { &vop_unlock_desc, fifo_unlock }, /* unlock */
105 1.8 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
106 1.8 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
107 1.8 mycroft { &vop_print_desc, fifo_print }, /* print */
108 1.8 mycroft { &vop_islocked_desc, fifo_islocked }, /* islocked */
109 1.8 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
110 1.8 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
111 1.8 mycroft { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
112 1.8 mycroft { &vop_valloc_desc, fifo_valloc }, /* valloc */
113 1.8 mycroft { &vop_vfree_desc, fifo_vfree }, /* vfree */
114 1.8 mycroft { &vop_truncate_desc, fifo_truncate }, /* truncate */
115 1.8 mycroft { &vop_update_desc, fifo_update }, /* update */
116 1.8 mycroft { &vop_bwrite_desc, fifo_bwrite }, /* bwrite */
117 1.31 sommerfe { &vop_putpages_desc, fifo_putpages }, /* putpages */
118 1.17 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
119 1.1 cgd };
120 1.29 jdolecek const struct vnodeopv_desc fifo_vnodeop_opv_desc =
121 1.8 mycroft { &fifo_vnodeop_p, fifo_vnodeop_entries };
122 1.1 cgd
123 1.1 cgd /*
124 1.1 cgd * Trivial lookup routine that always fails.
125 1.1 cgd */
126 1.1 cgd /* ARGSUSED */
127 1.17 christos int
128 1.30 lukem fifo_lookup(void *v)
129 1.17 christos {
130 1.8 mycroft struct vop_lookup_args /* {
131 1.30 lukem struct vnode *a_dvp;
132 1.30 lukem struct vnode **a_vpp;
133 1.30 lukem struct componentname *a_cnp;
134 1.17 christos } */ *ap = v;
135 1.8 mycroft
136 1.8 mycroft *ap->a_vpp = NULL;
137 1.1 cgd return (ENOTDIR);
138 1.1 cgd }
139 1.1 cgd
140 1.1 cgd /*
141 1.1 cgd * Open called to set up a new instance of a fifo or
142 1.1 cgd * to find an active instance of a fifo.
143 1.1 cgd */
144 1.1 cgd /* ARGSUSED */
145 1.17 christos int
146 1.30 lukem fifo_open(void *v)
147 1.17 christos {
148 1.8 mycroft struct vop_open_args /* {
149 1.30 lukem struct vnode *a_vp;
150 1.30 lukem int a_mode;
151 1.30 lukem struct ucred *a_cred;
152 1.30 lukem struct proc *a_p;
153 1.17 christos } */ *ap = v;
154 1.30 lukem struct vnode *vp;
155 1.30 lukem struct fifoinfo *fip;
156 1.30 lukem struct proc *p;
157 1.30 lukem struct socket *rso, *wso;
158 1.30 lukem int error;
159 1.24 mycroft static const char openstr[] = "fifo";
160 1.1 cgd
161 1.30 lukem vp = ap->a_vp;
162 1.30 lukem p = ap->a_p;
163 1.30 lukem
164 1.1 cgd if ((fip = vp->v_fifoinfo) == NULL) {
165 1.1 cgd MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_VNODE, M_WAITOK);
166 1.1 cgd vp->v_fifoinfo = fip;
167 1.17 christos if ((error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0)) != 0) {
168 1.1 cgd free(fip, M_VNODE);
169 1.1 cgd vp->v_fifoinfo = NULL;
170 1.1 cgd return (error);
171 1.1 cgd }
172 1.1 cgd fip->fi_readsock = rso;
173 1.17 christos if ((error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0)) != 0) {
174 1.1 cgd (void)soclose(rso);
175 1.1 cgd free(fip, M_VNODE);
176 1.1 cgd vp->v_fifoinfo = NULL;
177 1.1 cgd return (error);
178 1.1 cgd }
179 1.1 cgd fip->fi_writesock = wso;
180 1.17 christos if ((error = unp_connect2(wso, rso)) != 0) {
181 1.1 cgd (void)soclose(wso);
182 1.1 cgd (void)soclose(rso);
183 1.1 cgd free(fip, M_VNODE);
184 1.1 cgd vp->v_fifoinfo = NULL;
185 1.1 cgd return (error);
186 1.1 cgd }
187 1.8 mycroft fip->fi_readers = fip->fi_writers = 0;
188 1.34 chs fip->fi_opencount = 0;
189 1.1 cgd wso->so_state |= SS_CANTRCVMORE;
190 1.1 cgd rso->so_state |= SS_CANTSENDMORE;
191 1.1 cgd }
192 1.34 chs fip->fi_opencount++;
193 1.8 mycroft if (ap->a_mode & FREAD) {
194 1.16 mycroft if (fip->fi_readers++ == 0) {
195 1.1 cgd fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
196 1.1 cgd if (fip->fi_writers > 0)
197 1.1 cgd wakeup((caddr_t)&fip->fi_writers);
198 1.1 cgd }
199 1.16 mycroft }
200 1.16 mycroft if (ap->a_mode & FWRITE) {
201 1.16 mycroft if (fip->fi_writers++ == 0) {
202 1.16 mycroft fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
203 1.16 mycroft if (fip->fi_readers > 0)
204 1.16 mycroft wakeup((caddr_t)&fip->fi_readers);
205 1.2 cgd }
206 1.16 mycroft }
207 1.16 mycroft if (ap->a_mode & FREAD) {
208 1.16 mycroft if (ap->a_mode & O_NONBLOCK) {
209 1.1 cgd } else {
210 1.16 mycroft while (fip->fi_writers == 0) {
211 1.25 fvdl VOP_UNLOCK(vp, 0);
212 1.16 mycroft error = tsleep((caddr_t)&fip->fi_readers,
213 1.16 mycroft PCATCH | PSOCK, openstr, 0);
214 1.25 fvdl vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
215 1.16 mycroft if (error)
216 1.16 mycroft goto bad;
217 1.1 cgd }
218 1.16 mycroft }
219 1.16 mycroft }
220 1.16 mycroft if (ap->a_mode & FWRITE) {
221 1.16 mycroft if (ap->a_mode & O_NONBLOCK) {
222 1.16 mycroft if (fip->fi_readers == 0) {
223 1.16 mycroft error = ENXIO;
224 1.16 mycroft goto bad;
225 1.16 mycroft }
226 1.16 mycroft } else {
227 1.2 cgd while (fip->fi_readers == 0) {
228 1.25 fvdl VOP_UNLOCK(vp, 0);
229 1.2 cgd error = tsleep((caddr_t)&fip->fi_writers,
230 1.8 mycroft PCATCH | PSOCK, openstr, 0);
231 1.25 fvdl vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
232 1.8 mycroft if (error)
233 1.16 mycroft goto bad;
234 1.2 cgd }
235 1.1 cgd }
236 1.1 cgd }
237 1.16 mycroft return (0);
238 1.30 lukem bad:
239 1.25 fvdl VOP_CLOSE(vp, ap->a_mode, ap->a_cred, p);
240 1.1 cgd return (error);
241 1.1 cgd }
242 1.1 cgd
243 1.1 cgd /*
244 1.1 cgd * Vnode op for read
245 1.1 cgd */
246 1.1 cgd /* ARGSUSED */
247 1.17 christos int
248 1.30 lukem fifo_read(void *v)
249 1.17 christos {
250 1.8 mycroft struct vop_read_args /* {
251 1.30 lukem struct vnode *a_vp;
252 1.30 lukem struct uio *a_uio;
253 1.30 lukem int a_ioflag;
254 1.30 lukem struct ucred *a_cred;
255 1.17 christos } */ *ap = v;
256 1.30 lukem struct uio *uio;
257 1.30 lukem struct socket *rso;
258 1.30 lukem int error, startresid;
259 1.1 cgd
260 1.30 lukem uio = ap->a_uio;
261 1.30 lukem rso = ap->a_vp->v_fifoinfo->fi_readsock;
262 1.1 cgd #ifdef DIAGNOSTIC
263 1.1 cgd if (uio->uio_rw != UIO_READ)
264 1.1 cgd panic("fifo_read mode");
265 1.1 cgd #endif
266 1.1 cgd if (uio->uio_resid == 0)
267 1.1 cgd return (0);
268 1.8 mycroft if (ap->a_ioflag & IO_NDELAY)
269 1.1 cgd rso->so_state |= SS_NBIO;
270 1.1 cgd startresid = uio->uio_resid;
271 1.25 fvdl VOP_UNLOCK(ap->a_vp, 0);
272 1.27 matt error = (*rso->so_receive)(rso, (struct mbuf **)0, uio,
273 1.27 matt (struct mbuf **)0, (struct mbuf **)0, (int *)0);
274 1.25 fvdl vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
275 1.1 cgd /*
276 1.1 cgd * Clear EOF indication after first such return.
277 1.1 cgd */
278 1.1 cgd if (uio->uio_resid == startresid)
279 1.1 cgd rso->so_state &= ~SS_CANTRCVMORE;
280 1.23 kleink if (ap->a_ioflag & IO_NDELAY) {
281 1.1 cgd rso->so_state &= ~SS_NBIO;
282 1.23 kleink if (error == EWOULDBLOCK &&
283 1.23 kleink ap->a_vp->v_fifoinfo->fi_writers == 0)
284 1.23 kleink error = 0;
285 1.23 kleink }
286 1.1 cgd return (error);
287 1.1 cgd }
288 1.1 cgd
289 1.1 cgd /*
290 1.1 cgd * Vnode op for write
291 1.1 cgd */
292 1.1 cgd /* ARGSUSED */
293 1.17 christos int
294 1.30 lukem fifo_write(void *v)
295 1.17 christos {
296 1.8 mycroft struct vop_write_args /* {
297 1.30 lukem struct vnode *a_vp;
298 1.30 lukem struct uio *a_uio;
299 1.30 lukem int a_ioflag;
300 1.30 lukem struct ucred *a_cred;
301 1.17 christos } */ *ap = v;
302 1.30 lukem struct socket *wso;
303 1.30 lukem int error;
304 1.1 cgd
305 1.30 lukem wso = ap->a_vp->v_fifoinfo->fi_writesock;
306 1.1 cgd #ifdef DIAGNOSTIC
307 1.8 mycroft if (ap->a_uio->uio_rw != UIO_WRITE)
308 1.1 cgd panic("fifo_write mode");
309 1.1 cgd #endif
310 1.8 mycroft if (ap->a_ioflag & IO_NDELAY)
311 1.1 cgd wso->so_state |= SS_NBIO;
312 1.25 fvdl VOP_UNLOCK(ap->a_vp, 0);
313 1.27 matt error = (*wso->so_send)(wso, (struct mbuf *)0, ap->a_uio, 0,
314 1.27 matt (struct mbuf *)0, 0);
315 1.25 fvdl vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
316 1.8 mycroft if (ap->a_ioflag & IO_NDELAY)
317 1.1 cgd wso->so_state &= ~SS_NBIO;
318 1.1 cgd return (error);
319 1.1 cgd }
320 1.1 cgd
321 1.1 cgd /*
322 1.1 cgd * Device ioctl operation.
323 1.1 cgd */
324 1.1 cgd /* ARGSUSED */
325 1.17 christos int
326 1.30 lukem fifo_ioctl(void *v)
327 1.17 christos {
328 1.8 mycroft struct vop_ioctl_args /* {
329 1.30 lukem struct vnode *a_vp;
330 1.30 lukem u_long a_command;
331 1.30 lukem caddr_t a_data;
332 1.30 lukem int a_fflag;
333 1.30 lukem struct ucred *a_cred;
334 1.30 lukem struct proc *a_p;
335 1.17 christos } */ *ap = v;
336 1.30 lukem struct file filetmp;
337 1.30 lukem int error;
338 1.1 cgd
339 1.8 mycroft if (ap->a_command == FIONBIO)
340 1.1 cgd return (0);
341 1.16 mycroft if (ap->a_fflag & FREAD) {
342 1.8 mycroft filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
343 1.16 mycroft error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
344 1.16 mycroft if (error)
345 1.16 mycroft return (error);
346 1.16 mycroft }
347 1.16 mycroft if (ap->a_fflag & FWRITE) {
348 1.8 mycroft filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
349 1.16 mycroft error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
350 1.16 mycroft if (error)
351 1.16 mycroft return (error);
352 1.16 mycroft }
353 1.16 mycroft return (0);
354 1.1 cgd }
355 1.1 cgd
356 1.1 cgd /* ARGSUSED */
357 1.17 christos int
358 1.30 lukem fifo_poll(void *v)
359 1.17 christos {
360 1.20 mycroft struct vop_poll_args /* {
361 1.30 lukem struct vnode *a_vp;
362 1.30 lukem int a_events;
363 1.30 lukem struct proc *a_p;
364 1.17 christos } */ *ap = v;
365 1.30 lukem struct file filetmp;
366 1.30 lukem int revents;
367 1.1 cgd
368 1.30 lukem revents = 0;
369 1.20 mycroft if (ap->a_events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
370 1.8 mycroft filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
371 1.20 mycroft if (filetmp.f_data)
372 1.20 mycroft revents |= soo_poll(&filetmp, ap->a_events, ap->a_p);
373 1.16 mycroft }
374 1.20 mycroft if (ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
375 1.8 mycroft filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
376 1.20 mycroft if (filetmp.f_data)
377 1.20 mycroft revents |= soo_poll(&filetmp, ap->a_events, ap->a_p);
378 1.16 mycroft }
379 1.20 mycroft
380 1.20 mycroft return (revents);
381 1.1 cgd }
382 1.1 cgd
383 1.25 fvdl int
384 1.30 lukem fifo_inactive(void *v)
385 1.25 fvdl {
386 1.25 fvdl struct vop_inactive_args /* {
387 1.30 lukem struct vnode *a_vp;
388 1.30 lukem struct proc *a_p;
389 1.25 fvdl } */ *ap = v;
390 1.25 fvdl
391 1.25 fvdl VOP_UNLOCK(ap->a_vp, 0);
392 1.25 fvdl return (0);
393 1.25 fvdl }
394 1.25 fvdl
395 1.1 cgd /*
396 1.1 cgd * This is a noop, simply returning what one has been given.
397 1.1 cgd */
398 1.17 christos int
399 1.30 lukem fifo_bmap(void *v)
400 1.17 christos {
401 1.8 mycroft struct vop_bmap_args /* {
402 1.30 lukem struct vnode *a_vp;
403 1.30 lukem daddr_t a_bn;
404 1.30 lukem struct vnode **a_vpp;
405 1.30 lukem daddr_t *a_bnp;
406 1.30 lukem int *a_runp;
407 1.17 christos } */ *ap = v;
408 1.1 cgd
409 1.8 mycroft if (ap->a_vpp != NULL)
410 1.8 mycroft *ap->a_vpp = ap->a_vp;
411 1.8 mycroft if (ap->a_bnp != NULL)
412 1.8 mycroft *ap->a_bnp = ap->a_bn;
413 1.25 fvdl if (ap->a_runp != NULL)
414 1.25 fvdl *ap->a_runp = 0;
415 1.1 cgd return (0);
416 1.1 cgd }
417 1.1 cgd
418 1.1 cgd /*
419 1.1 cgd * Device close routine
420 1.1 cgd */
421 1.1 cgd /* ARGSUSED */
422 1.17 christos int
423 1.30 lukem fifo_close(void *v)
424 1.17 christos {
425 1.8 mycroft struct vop_close_args /* {
426 1.30 lukem struct vnode *a_vp;
427 1.30 lukem int a_fflag;
428 1.30 lukem struct ucred *a_cred;
429 1.30 lukem struct proc *a_p;
430 1.17 christos } */ *ap = v;
431 1.30 lukem struct vnode *vp;
432 1.30 lukem struct fifoinfo *fip;
433 1.1 cgd
434 1.30 lukem vp = ap->a_vp;
435 1.30 lukem fip = vp->v_fifoinfo;
436 1.16 mycroft if (ap->a_fflag & FREAD) {
437 1.16 mycroft if (--fip->fi_readers == 0)
438 1.16 mycroft socantsendmore(fip->fi_writesock);
439 1.16 mycroft }
440 1.8 mycroft if (ap->a_fflag & FWRITE) {
441 1.16 mycroft if (--fip->fi_writers == 0)
442 1.1 cgd socantrcvmore(fip->fi_readsock);
443 1.1 cgd }
444 1.34 chs if (--fip->fi_opencount == 0) {
445 1.34 chs (void) soclose(fip->fi_readsock);
446 1.34 chs (void) soclose(fip->fi_writesock);
447 1.34 chs FREE(fip, M_VNODE);
448 1.34 chs vp->v_fifoinfo = NULL;
449 1.34 chs }
450 1.34 chs return (0);
451 1.1 cgd }
452 1.1 cgd
453 1.1 cgd /*
454 1.1 cgd * Print out the contents of a fifo vnode.
455 1.1 cgd */
456 1.17 christos int
457 1.30 lukem fifo_print(void *v)
458 1.17 christos {
459 1.8 mycroft struct vop_print_args /* {
460 1.30 lukem struct vnode *a_vp;
461 1.17 christos } */ *ap = v;
462 1.1 cgd
463 1.22 christos printf("tag VT_NON");
464 1.8 mycroft fifo_printinfo(ap->a_vp);
465 1.22 christos printf("\n");
466 1.17 christos return 0;
467 1.1 cgd }
468 1.1 cgd
469 1.1 cgd /*
470 1.1 cgd * Print out internal contents of a fifo vnode.
471 1.1 cgd */
472 1.17 christos void
473 1.30 lukem fifo_printinfo(struct vnode *vp)
474 1.1 cgd {
475 1.30 lukem struct fifoinfo *fip;
476 1.1 cgd
477 1.30 lukem fip = vp->v_fifoinfo;
478 1.22 christos printf(", fifo with %ld readers and %ld writers",
479 1.21 christos fip->fi_readers, fip->fi_writers);
480 1.1 cgd }
481 1.1 cgd
482 1.1 cgd /*
483 1.8 mycroft * Return POSIX pathconf information applicable to fifo's.
484 1.8 mycroft */
485 1.17 christos int
486 1.30 lukem fifo_pathconf(void *v)
487 1.17 christos {
488 1.8 mycroft struct vop_pathconf_args /* {
489 1.30 lukem struct vnode *a_vp;
490 1.30 lukem int a_name;
491 1.30 lukem register_t *a_retval;
492 1.17 christos } */ *ap = v;
493 1.8 mycroft
494 1.8 mycroft switch (ap->a_name) {
495 1.8 mycroft case _PC_LINK_MAX:
496 1.8 mycroft *ap->a_retval = LINK_MAX;
497 1.8 mycroft return (0);
498 1.8 mycroft case _PC_PIPE_BUF:
499 1.8 mycroft *ap->a_retval = PIPE_BUF;
500 1.8 mycroft return (0);
501 1.8 mycroft case _PC_CHOWN_RESTRICTED:
502 1.26 kleink *ap->a_retval = 1;
503 1.26 kleink return (0);
504 1.26 kleink case _PC_SYNC_IO:
505 1.8 mycroft *ap->a_retval = 1;
506 1.8 mycroft return (0);
507 1.8 mycroft default:
508 1.8 mycroft return (EINVAL);
509 1.8 mycroft }
510 1.1 cgd /* NOTREACHED */
511 1.1 cgd }
512