xref: /freebsd/sys/fs/fifofs/fifo_vnops.c (revision 390e8cc2974df1888369c06339ef8e0e92b312b6)
1 /*
2  * Copyright (c) 1990, 1993, 1995
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)fifo_vnops.c	8.10 (Berkeley) 5/27/95
34  * $FreeBSD$
35  */
36 
37 #include <sys/param.h>
38 #include <sys/event.h>
39 #include <sys/filio.h>
40 #include <sys/fcntl.h>
41 #include <sys/file.h>
42 #include <sys/kernel.h>
43 #include <sys/lock.h>
44 #include <sys/mutex.h>
45 #include <sys/malloc.h>
46 #include <sys/poll.h>
47 #include <sys/proc.h> /* XXXKSE */
48 #include <sys/signalvar.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/sx.h>
52 #include <sys/systm.h>
53 #include <sys/un.h>
54 #include <sys/unistd.h>
55 #include <sys/vnode.h>
56 #include <fs/fifofs/fifo.h>
57 
58 /*
59  * This structure is associated with the FIFO vnode and stores
60  * the state associated with the FIFO.
61  */
62 struct fifoinfo {
63 	struct socket	*fi_readsock;
64 	struct socket	*fi_writesock;
65 	long		fi_readers;
66 	long		fi_writers;
67 };
68 
69 static int	fifo_print(struct vop_print_args *);
70 static int	fifo_lookup(struct vop_lookup_args *);
71 static int	fifo_open(struct vop_open_args *);
72 static int	fifo_close(struct vop_close_args *);
73 static int	fifo_inactive(struct vop_inactive_args *);
74 static int	fifo_read(struct vop_read_args *);
75 static int	fifo_write(struct vop_write_args *);
76 static int	fifo_ioctl(struct vop_ioctl_args *);
77 static int	fifo_poll(struct vop_poll_args *);
78 static int	fifo_kqfilter(struct vop_kqfilter_args *);
79 static int	fifo_pathconf(struct vop_pathconf_args *);
80 static int	fifo_advlock(struct vop_advlock_args *);
81 
82 static void	filt_fifordetach(struct knote *kn);
83 static int	filt_fiforead(struct knote *kn, long hint);
84 static void	filt_fifowdetach(struct knote *kn);
85 static int	filt_fifowrite(struct knote *kn, long hint);
86 
87 static struct filterops fiforead_filtops =
88 	{ 1, NULL, filt_fifordetach, filt_fiforead };
89 static struct filterops fifowrite_filtops =
90 	{ 1, NULL, filt_fifowdetach, filt_fifowrite };
91 
92 vop_t **fifo_vnodeop_p;
93 static struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
94 	{ &vop_default_desc,		(vop_t *) vop_defaultop },
95 	{ &vop_access_desc,		(vop_t *) vop_ebadf },
96 	{ &vop_advlock_desc,		(vop_t *) fifo_advlock },
97 	{ &vop_close_desc,		(vop_t *) fifo_close },
98 	{ &vop_create_desc,		(vop_t *) vop_panic },
99 	{ &vop_getattr_desc,		(vop_t *) vop_ebadf },
100 	{ &vop_getwritemount_desc, 	(vop_t *) vop_stdgetwritemount },
101 	{ &vop_inactive_desc,		(vop_t *) fifo_inactive },
102 	{ &vop_ioctl_desc,		(vop_t *) fifo_ioctl },
103 	{ &vop_kqfilter_desc,		(vop_t *) fifo_kqfilter },
104 	{ &vop_lease_desc,		(vop_t *) vop_null },
105 	{ &vop_link_desc,		(vop_t *) vop_panic },
106 	{ &vop_lookup_desc,		(vop_t *) fifo_lookup },
107 	{ &vop_mkdir_desc,		(vop_t *) vop_panic },
108 	{ &vop_mknod_desc,		(vop_t *) vop_panic },
109 	{ &vop_open_desc,		(vop_t *) fifo_open },
110 	{ &vop_pathconf_desc,		(vop_t *) fifo_pathconf },
111 	{ &vop_poll_desc,		(vop_t *) fifo_poll },
112 	{ &vop_print_desc,		(vop_t *) fifo_print },
113 	{ &vop_read_desc,		(vop_t *) fifo_read },
114 	{ &vop_readdir_desc,		(vop_t *) vop_panic },
115 	{ &vop_readlink_desc,		(vop_t *) vop_panic },
116 	{ &vop_reallocblks_desc,	(vop_t *) vop_panic },
117 	{ &vop_reclaim_desc,		(vop_t *) vop_null },
118 	{ &vop_remove_desc,		(vop_t *) vop_panic },
119 	{ &vop_rename_desc,		(vop_t *) vop_panic },
120 	{ &vop_rmdir_desc,		(vop_t *) vop_panic },
121 	{ &vop_setattr_desc,		(vop_t *) vop_ebadf },
122 	{ &vop_symlink_desc,		(vop_t *) vop_panic },
123 	{ &vop_write_desc,		(vop_t *) fifo_write },
124 	{ NULL, NULL }
125 };
126 static struct vnodeopv_desc fifo_vnodeop_opv_desc =
127 	{ &fifo_vnodeop_p, fifo_vnodeop_entries };
128 
129 VNODEOP_SET(fifo_vnodeop_opv_desc);
130 
131 int
132 fifo_vnoperate(ap)
133 	struct vop_generic_args /* {
134 		struct vnodeop_desc *a_desc;
135 		<other random data follows, presumably>
136 	} */ *ap;
137 {
138 	return (VOCALL(fifo_vnodeop_p, ap->a_desc->vdesc_offset, ap));
139 }
140 
141 /*
142  * Trivial lookup routine that always fails.
143  */
144 /* ARGSUSED */
145 static int
146 fifo_lookup(ap)
147 	struct vop_lookup_args /* {
148 		struct vnode * a_dvp;
149 		struct vnode ** a_vpp;
150 		struct componentname * a_cnp;
151 	} */ *ap;
152 {
153 
154 	*ap->a_vpp = NULL;
155 	return (ENOTDIR);
156 }
157 
158 /*
159  * Open called to set up a new instance of a fifo or
160  * to find an active instance of a fifo.
161  */
162 /* ARGSUSED */
163 static int
164 fifo_open(ap)
165 	struct vop_open_args /* {
166 		struct vnode *a_vp;
167 		int  a_mode;
168 		struct ucred *a_cred;
169 		struct thread *a_td;
170 	} */ *ap;
171 {
172 	struct vnode *vp = ap->a_vp;
173 	struct fifoinfo *fip;
174 	struct thread *td = ap->a_td;
175 	struct socket *rso, *wso;
176 	int error;
177 
178 	if ((fip = vp->v_fifoinfo) == NULL) {
179 		MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_VNODE, M_WAITOK);
180 		vp->v_fifoinfo = fip;
181 		error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0,
182 		    ap->a_td->td_ucred, ap->a_td);
183 		if (error) {
184 			free(fip, M_VNODE);
185 			vp->v_fifoinfo = NULL;
186 			return (error);
187 		}
188 		fip->fi_readsock = rso;
189 		error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0,
190 		    ap->a_td->td_ucred, ap->a_td);
191 		if (error) {
192 			(void)soclose(rso);
193 			free(fip, M_VNODE);
194 			vp->v_fifoinfo = NULL;
195 			return (error);
196 		}
197 		fip->fi_writesock = wso;
198 		error = unp_connect2(wso, rso);
199 		if (error) {
200 			(void)soclose(wso);
201 			(void)soclose(rso);
202 			free(fip, M_VNODE);
203 			vp->v_fifoinfo = NULL;
204 			return (error);
205 		}
206 		fip->fi_readers = fip->fi_writers = 0;
207 		wso->so_snd.sb_lowat = PIPE_BUF;
208 		rso->so_state |= SS_CANTRCVMORE;
209 	}
210 
211 	/*
212 	 * General access to fi_readers and fi_writers is protected using
213 	 * the vnode lock.
214 	 *
215 	 * Protect the increment of fi_readers and fi_writers and the
216 	 * associated calls to wakeup() with the vnode interlock in
217 	 * addition to the vnode lock.  This allows the vnode lock to
218 	 * be dropped for the msleep() calls below, and using the vnode
219 	 * interlock as the msleep() mutex prevents the wakeup from
220 	 * being missed.
221 	 */
222 	VI_LOCK(vp);
223 	if (ap->a_mode & FREAD) {
224 		fip->fi_readers++;
225 		if (fip->fi_readers == 1) {
226 			fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
227 			if (fip->fi_writers > 0) {
228 				wakeup(&fip->fi_writers);
229 				VI_UNLOCK(vp);
230 				sowwakeup(fip->fi_writesock);
231 				VI_LOCK(vp);
232 			}
233 		}
234 	}
235 	if (ap->a_mode & FWRITE) {
236 		fip->fi_writers++;
237 		if (fip->fi_writers == 1) {
238 			fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
239 			if (fip->fi_readers > 0) {
240 				wakeup(&fip->fi_readers);
241 				VI_UNLOCK(vp);
242 				sorwakeup(fip->fi_writesock);
243 				VI_LOCK(vp);
244 			}
245 		}
246 	}
247 	if ((ap->a_mode & FREAD) && (ap->a_mode & O_NONBLOCK) == 0) {
248 		if (fip->fi_writers == 0) {
249 			VOP_UNLOCK(vp, 0, td);
250 			error = msleep(&fip->fi_readers, VI_MTX(vp),
251 			    PCATCH | PSOCK, "fifoor", 0);
252 			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK, td);
253 			if (error) {
254 				fip->fi_readers--;
255 				if (fip->fi_readers == 0)
256 					socantsendmore(fip->fi_writesock);
257 				return (error);
258 			}
259 			VI_LOCK(vp);
260 			/*
261 			 * We must have got woken up because we had a writer.
262 			 * That (and not still having one) is the condition
263 			 * that we must wait for.
264 			 */
265 		}
266 	}
267 	if (ap->a_mode & FWRITE) {
268 		if (ap->a_mode & O_NONBLOCK) {
269 			if (fip->fi_readers == 0) {
270 				VI_UNLOCK(vp);
271 				fip->fi_writers--;
272 				if (fip->fi_writers == 0)
273 					socantrcvmore(fip->fi_readsock);
274 				return (ENXIO);
275 			}
276 		} else {
277 			if (fip->fi_readers == 0) {
278 				VOP_UNLOCK(vp, 0, td);
279 				error = msleep(&fip->fi_writers, VI_MTX(vp),
280 				    PCATCH | PSOCK, "fifoow", 0);
281 				vn_lock(vp,
282 				    LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK, td);
283 				if (error) {
284 					fip->fi_writers--;
285 					if (fip->fi_writers == 0)
286 						socantrcvmore(fip->fi_readsock);
287 					return (error);
288 				}
289 				/*
290 				 * We must have got woken up because we had
291 				 * a reader.  That (and not still having one)
292 				 * is the condition that we must wait for.
293 				 */
294 				return (0);
295 			}
296 		}
297 	}
298 	VI_UNLOCK(vp);
299 	return (0);
300 }
301 
302 /*
303  * Vnode op for read
304  */
305 /* ARGSUSED */
306 static int
307 fifo_read(ap)
308 	struct vop_read_args /* {
309 		struct vnode *a_vp;
310 		struct uio *a_uio;
311 		int  a_ioflag;
312 		struct ucred *a_cred;
313 	} */ *ap;
314 {
315 	struct uio *uio = ap->a_uio;
316 	struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
317 	struct thread *td = uio->uio_td;
318 	int error;
319 
320 #ifdef DIAGNOSTIC
321 	if (uio->uio_rw != UIO_READ)
322 		panic("fifo_read mode");
323 #endif
324 	if (uio->uio_resid == 0)
325 		return (0);
326 	if (ap->a_ioflag & IO_NDELAY)
327 		rso->so_state |= SS_NBIO;
328 	VOP_UNLOCK(ap->a_vp, 0, td);
329 	error = soreceive(rso, (struct sockaddr **)0, uio, (struct mbuf **)0,
330 	    (struct mbuf **)0, (int *)0);
331 	vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, td);
332 	if (ap->a_ioflag & IO_NDELAY)
333 		rso->so_state &= ~SS_NBIO;
334 	return (error);
335 }
336 
337 /*
338  * Vnode op for write
339  */
340 /* ARGSUSED */
341 static int
342 fifo_write(ap)
343 	struct vop_write_args /* {
344 		struct vnode *a_vp;
345 		struct uio *a_uio;
346 		int  a_ioflag;
347 		struct ucred *a_cred;
348 	} */ *ap;
349 {
350 	struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
351 	struct thread *td = ap->a_uio->uio_td;
352 	int error;
353 
354 #ifdef DIAGNOSTIC
355 	if (ap->a_uio->uio_rw != UIO_WRITE)
356 		panic("fifo_write mode");
357 #endif
358 	if (ap->a_ioflag & IO_NDELAY)
359 		wso->so_state |= SS_NBIO;
360 	VOP_UNLOCK(ap->a_vp, 0, td);
361 	error = sosend(wso, (struct sockaddr *)0, ap->a_uio, 0,
362 		       (struct mbuf *)0, 0, td);
363 	vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY, td);
364 	if (ap->a_ioflag & IO_NDELAY)
365 		wso->so_state &= ~SS_NBIO;
366 	return (error);
367 }
368 
369 /*
370  * Device ioctl operation.
371  */
372 /* ARGSUSED */
373 static int
374 fifo_ioctl(ap)
375 	struct vop_ioctl_args /* {
376 		struct vnode *a_vp;
377 		u_long  a_command;
378 		caddr_t  a_data;
379 		int  a_fflag;
380 		struct ucred *a_cred;
381 		struct thread *a_td;
382 	} */ *ap;
383 {
384 	struct file filetmp;	/* Local, so need not be locked. */
385 	int error;
386 
387 	if (ap->a_command == FIONBIO)
388 		return (0);
389 	if (ap->a_fflag & FREAD) {
390 		filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
391 		filetmp.f_cred = ap->a_cred;
392 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data,
393 		    ap->a_td->td_ucred, ap->a_td);
394 		if (error)
395 			return (error);
396 	}
397 	if (ap->a_fflag & FWRITE) {
398 		filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
399 		filetmp.f_cred = ap->a_cred;
400 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data,
401 		    ap->a_td->td_ucred, ap->a_td);
402 		if (error)
403 			return (error);
404 	}
405 	return (0);
406 }
407 
408 /* ARGSUSED */
409 static int
410 fifo_kqfilter(ap)
411 	struct vop_kqfilter_args /* {
412 		struct vnode *a_vp;
413 		struct knote *a_kn;
414 	} */ *ap;
415 {
416 	struct fifoinfo *fi = ap->a_vp->v_fifoinfo;
417 	struct socket *so;
418 	struct sockbuf *sb;
419 
420 	switch (ap->a_kn->kn_filter) {
421 	case EVFILT_READ:
422 		ap->a_kn->kn_fop = &fiforead_filtops;
423 		so = fi->fi_readsock;
424 		sb = &so->so_rcv;
425 		break;
426 	case EVFILT_WRITE:
427 		ap->a_kn->kn_fop = &fifowrite_filtops;
428 		so = fi->fi_writesock;
429 		sb = &so->so_snd;
430 		break;
431 	default:
432 		return (1);
433 	}
434 
435 	ap->a_kn->kn_hook = (caddr_t)so;
436 
437 	SLIST_INSERT_HEAD(&sb->sb_sel.si_note, ap->a_kn, kn_selnext);
438 	sb->sb_flags |= SB_KNOTE;
439 
440 	return (0);
441 }
442 
443 static void
444 filt_fifordetach(struct knote *kn)
445 {
446 	struct socket *so = (struct socket *)kn->kn_hook;
447 
448 	SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext);
449 	if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note))
450 		so->so_rcv.sb_flags &= ~SB_KNOTE;
451 }
452 
453 static int
454 filt_fiforead(struct knote *kn, long hint)
455 {
456 	struct socket *so = (struct socket *)kn->kn_hook;
457 
458 	kn->kn_data = so->so_rcv.sb_cc;
459 	if (so->so_state & SS_CANTRCVMORE) {
460 		kn->kn_flags |= EV_EOF;
461 		return (1);
462 	}
463 	kn->kn_flags &= ~EV_EOF;
464 	return (kn->kn_data > 0);
465 }
466 
467 static void
468 filt_fifowdetach(struct knote *kn)
469 {
470 	struct socket *so = (struct socket *)kn->kn_hook;
471 
472 	SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext);
473 	if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note))
474 		so->so_snd.sb_flags &= ~SB_KNOTE;
475 }
476 
477 static int
478 filt_fifowrite(struct knote *kn, long hint)
479 {
480 	struct socket *so = (struct socket *)kn->kn_hook;
481 
482 	kn->kn_data = sbspace(&so->so_snd);
483 	if (so->so_state & SS_CANTSENDMORE) {
484 		kn->kn_flags |= EV_EOF;
485 		return (1);
486 	}
487 	kn->kn_flags &= ~EV_EOF;
488 	return (kn->kn_data >= so->so_snd.sb_lowat);
489 }
490 
491 /* ARGSUSED */
492 static int
493 fifo_poll(ap)
494 	struct vop_poll_args /* {
495 		struct vnode *a_vp;
496 		int  a_events;
497 		struct ucred *a_cred;
498 		struct thread *a_td;
499 	} */ *ap;
500 {
501 	struct file filetmp;
502 	int events, revents = 0;
503 
504 	events = ap->a_events &
505 	    (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
506 	if (events) {
507 		/*
508 		 * If POLLIN or POLLRDNORM is requested and POLLINIGNEOF is
509 		 * not, then convert the first two to the last one.  This
510 		 * tells the socket poll function to ignore EOF so that we
511 		 * block if there is no writer (and no data).  Callers can
512 		 * set POLLINIGNEOF to get non-blocking behavior.
513 		 */
514 		if (events & (POLLIN | POLLRDNORM) &&
515 		    !(events & POLLINIGNEOF)) {
516 			events &= ~(POLLIN | POLLRDNORM);
517 			events |= POLLINIGNEOF;
518 		}
519 
520 		filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
521 		filetmp.f_cred = ap->a_cred;
522 		if (filetmp.f_data)
523 			revents |= soo_poll(&filetmp, events,
524 			    ap->a_td->td_ucred, ap->a_td);
525 
526 		/* Reverse the above conversion. */
527 		if ((revents & POLLINIGNEOF) &&
528 		    !(ap->a_events & POLLINIGNEOF)) {
529 			revents |= (ap->a_events & (POLLIN | POLLRDNORM));
530 			revents &= ~POLLINIGNEOF;
531 		}
532 	}
533 	events = ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND);
534 	if (events) {
535 		filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
536 		filetmp.f_cred = ap->a_cred;
537 		if (filetmp.f_data) {
538 			revents |= soo_poll(&filetmp, events,
539 			    ap->a_td->td_ucred, ap->a_td);
540 		}
541 	}
542 	return (revents);
543 }
544 
545 /*
546  * Device close routine
547  */
548 /* ARGSUSED */
549 static int
550 fifo_close(ap)
551 	struct vop_close_args /* {
552 		struct vnode *a_vp;
553 		int  a_fflag;
554 		struct ucred *a_cred;
555 		struct thread *a_td;
556 	} */ *ap;
557 {
558 	struct vnode *vp = ap->a_vp;
559 	struct thread *td = ap->a_td;
560 	struct fifoinfo *fip = vp->v_fifoinfo;
561 
562 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
563 
564 	if (ap->a_fflag & FREAD) {
565 		fip->fi_readers--;
566 		if (fip->fi_readers == 0)
567 			socantsendmore(fip->fi_writesock);
568 	}
569 	if (ap->a_fflag & FWRITE) {
570 		fip->fi_writers--;
571 		if (fip->fi_writers == 0)
572 			socantrcvmore(fip->fi_readsock);
573 	}
574 	VOP_UNLOCK(vp, 0, td);
575 	return (0);
576 }
577 
578 static int
579 fifo_inactive(ap)
580 	struct vop_inactive_args /* {
581 		struct vnode *a_vp;
582 		struct thread *a_td;
583 	} */ *ap;
584 {
585 	struct vnode *vp = ap->a_vp;
586 	struct fifoinfo *fip = vp->v_fifoinfo;
587 
588 	VI_LOCK(vp);
589 	if (fip != NULL && vp->v_usecount == 0) {
590 		vp->v_fifoinfo = NULL;
591 		VI_UNLOCK(vp);
592 		(void)soclose(fip->fi_readsock);
593 		(void)soclose(fip->fi_writesock);
594 		FREE(fip, M_VNODE);
595 	}
596 	VOP_UNLOCK(vp, 0, ap->a_td);
597 	return (0);
598 }
599 
600 
601 /*
602  * Print out internal contents of a fifo vnode.
603  */
604 int
605 fifo_printinfo(vp)
606 	struct vnode *vp;
607 {
608 	register struct fifoinfo *fip = vp->v_fifoinfo;
609 
610 	printf(", fifo with %ld readers and %ld writers",
611 		fip->fi_readers, fip->fi_writers);
612 	return (0);
613 }
614 
615 /*
616  * Print out the contents of a fifo vnode.
617  */
618 static int
619 fifo_print(ap)
620 	struct vop_print_args /* {
621 		struct vnode *a_vp;
622 	} */ *ap;
623 {
624 	fifo_printinfo(ap->a_vp);
625 	printf("\n");
626 	return (0);
627 }
628 
629 /*
630  * Return POSIX pathconf information applicable to fifo's.
631  */
632 static int
633 fifo_pathconf(ap)
634 	struct vop_pathconf_args /* {
635 		struct vnode *a_vp;
636 		int a_name;
637 		int *a_retval;
638 	} */ *ap;
639 {
640 
641 	switch (ap->a_name) {
642 	case _PC_LINK_MAX:
643 		*ap->a_retval = LINK_MAX;
644 		return (0);
645 	case _PC_PIPE_BUF:
646 		*ap->a_retval = PIPE_BUF;
647 		return (0);
648 	case _PC_CHOWN_RESTRICTED:
649 		*ap->a_retval = 1;
650 		return (0);
651 	default:
652 		return (EINVAL);
653 	}
654 	/* NOTREACHED */
655 }
656 
657 /*
658  * Fifo advisory byte-level locks.
659  */
660 /* ARGSUSED */
661 static int
662 fifo_advlock(ap)
663 	struct vop_advlock_args /* {
664 		struct vnode *a_vp;
665 		caddr_t  a_id;
666 		int  a_op;
667 		struct flock *a_fl;
668 		int  a_flags;
669 	} */ *ap;
670 {
671 
672 	return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL);
673 }
674